Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Edit User Profile API #44

Merged
merged 5 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/api-gateway/src/dtos/update-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IsNotEmpty, IsString } from 'class-validator';

import { ApiProperty } from '@nestjs/swagger';
import { trim } from '@credebl/common/cast.helper';
import { Transform } from 'class-transformer';

export class UpdateProfileDto {

Expand All @@ -15,6 +17,7 @@ export class UpdateProfileDto {
lastName: string;

@ApiProperty()
@Transform(({ value }) => trim(value))
@IsNotEmpty({message:'Please provide valid profileLogoUrl'})
@IsString({message:'ProfileLogoUrl should be string'})
profileLogoUrl?: string;
Expand Down
15 changes: 7 additions & 8 deletions apps/api-gateway/src/user/dto/update-user-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsNumber, IsOptional, IsString} from 'class-validator';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsNumber, IsOptional, IsString} from 'class-validator';


export class UpdateUserProfileDto {
Expand All @@ -8,6 +8,11 @@ export class UpdateUserProfileDto {
@IsNumber()
id: number;

@ApiPropertyOptional()
@IsOptional()
@IsString({message:'ProfileLogoUrl should be string'})
profileImg?: string;

@ApiProperty({ example: 'Alen' })
@IsString({ message: 'firstName should be string' })
@IsOptional()
Expand All @@ -17,10 +22,4 @@ export class UpdateUserProfileDto {
@IsString({ message: 'lastName should be string' })
@IsOptional()
lastName?: string;

@ApiProperty({ example: '[email protected]' })
@IsEmail()
@IsNotEmpty({ message: 'Please provide valid email' })
@IsString({ message: 'email should be string' })
email: string;
}
5 changes: 2 additions & 3 deletions apps/api-gateway/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,11 @@ async get(@User() user: IUserRequestInterface, @Query() getAllUsersDto: GetAllUs
@UseGuards(AuthGuard('jwt'))
async updateUserProfile(@Body() updateUserProfileDto: UpdateUserProfileDto, @Res() res: Response): Promise<Response> {

const UpdatedUserProfile = await this.userService.updateUserProfile(updateUserProfileDto);
await this.userService.updateUserProfile(updateUserProfileDto);

const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.update,
data: UpdatedUserProfile.response
message: ResponseMessages.user.success.update
};
return res.status(HttpStatus.OK).json(finalResponse);

Expand Down
3 changes: 1 addition & 2 deletions apps/user/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ export interface UserWhereUniqueInput{
export interface UserWhereInput{
email?: string
}

export interface UpdateUserProfile {
id: number,
profileImg?: string;
firstName: string,
lastName: string,
email: string
}
6 changes: 4 additions & 2 deletions apps/user/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export class UserRepository {
id: Number(updateUserProfile.id)
},
data: {
profileImg: updateUserProfile.profileImg,
firstName: updateUserProfile.firstName,
lastName: updateUserProfile.lastName,
email: updateUserProfile.email
lastName: updateUserProfile.lastName
}
});
return userdetails;
Expand Down Expand Up @@ -199,6 +199,8 @@ export class UserRepository {
email: true,
firstName: true,
lastName: true,
profileImg: true,
publicProfile:true,
isEmailVerified: true,
clientId: true,
clientSecret: true,
Expand Down
3 changes: 2 additions & 1 deletion apps/user/src/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface';

import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto';
import { Controller } from '@nestjs/common';
import { LoginUserDto } from '../dtos/login-user.dto';
import { MessagePattern } from '@nestjs/microservices';
import { UserService } from './user.service';
import { VerifyEmailTokenDto } from '../dtos/verify-email.dto';
import { UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface';


@Controller()
export class UserController {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "user" ALTER COLUMN "profileImg" SET DATA TYPE TEXT;
2 changes: 1 addition & 1 deletion libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ model user {
keycloakUserId String? @db.VarChar(500)
clientId String? @db.VarChar(500)
clientSecret String? @db.VarChar(500)
profileImg String? @db.VarChar(1000)
profileImg String?
fidoUserId String? @db.VarChar(1000)
isFidoVerified Boolean @default(false)
userOrgRoles user_org_roles[]
Expand Down
Loading