chore: update user profile
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user