update first and last name endpoint

This commit is contained in:
faris Aljohari
2024-07-15 15:57:22 +03:00
parent f8cd47e940
commit 5e25eeb883
3 changed files with 77 additions and 5 deletions
+40
View File
@@ -1,4 +1,5 @@
import {
UpdateNameDto,
UpdateProfilePictureDataDto,
UpdateRegionDataDto,
UpdateTimezoneDataDto,
@@ -167,6 +168,45 @@ export class UserService {
throw new BadRequestException('Timezone update failed');
}
return {
uuid: updatedUser.uuid,
firstName: updatedUser.firstName,
lastName: updatedUser.lastName,
profilePicture: updatedUser.profilePicture,
region: updatedUser.region,
timeZoneUuid: updatedUser.timeZone,
};
} catch (err) {
throw new HttpException(
err.message || 'User not found',
HttpStatus.NOT_FOUND,
);
}
}
async updateNameByUserUuid(userUuid: string, updateNameDto: UpdateNameDto) {
try {
const user = await this.getUserDetailsByUserUuid(userUuid);
if (!user) {
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
}
if (!updateNameDto.firstName || !updateNameDto.lastName) {
throw new BadRequestException('First Name and Last Name is required');
}
await this.userRepository.update(
{ uuid: userUuid },
{
firstName: updateNameDto.firstName,
lastName: updateNameDto.lastName,
},
);
const updatedUser = await this.getUserDetailsByUserUuid(userUuid);
if (!updatedUser.firstName || !updatedUser.lastName) {
throw new BadRequestException('First Name and Last Name update failed');
}
return {
uuid: updatedUser.uuid,
firstName: updatedUser.firstName,