chore: update user profile

This commit is contained in:
Matin
2025-02-20 09:50:01 +03:30
parent c306dca107
commit 99fa47356a
5 changed files with 59 additions and 9 deletions
+10 -2
View File
@@ -80,7 +80,7 @@ export class UsersService {
/************************************************************ */
async getMe(userId: string) {
const user = await this.userRepository.findOne({ where: { id: userId }, relations: { roles: true } });
const user = await this.userRepository.findOne({ where: { id: userId }, relations: { roles: true, city: { province: true } } });
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
return { user };
}
@@ -104,9 +104,17 @@ export class UsersService {
/************************************************************ */
async updateProfile(userId: string, updateProfileDto: UpdateProfileDto) {
let city;
const user = await this.userRepository.findOneBy({ id: userId });
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
if (updateProfileDto.cityId) {
const { city: existCity } = await this.addressService.getCity(+updateProfileDto.cityId);
if (!existCity) throw new BadRequestException(UserMessage.CITY_NOT_FOUND);
city = existCity;
}
//
if (updateProfileDto.userName) {
updateProfileDto.userName = slugify(updateProfileDto.userName, { lower: true, trim: true });
@@ -114,7 +122,7 @@ export class UsersService {
if (existUserName) throw new BadRequestException(UserMessage.USERNAME_EXIST);
}
await this.userRepository.save({ ...user, ...updateProfileDto });
await this.userRepository.save({ ...user, ...updateProfileDto, city });
//
return {
message: CommonMessage.UPDATE_SUCCESS,