Skip to content

Commit

Permalink
Merge pull request #228 from Roger13579/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Roger13579 authored Jun 16, 2024
2 parents d4d6d99 + 988771c commit 8819a2d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
61 changes: 36 additions & 25 deletions src/dto/user/userDetailDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,50 @@ import { IUser } from '../../models/user';
import { Gender, IUpdateUserDetailReq } from '../../types/user.type';

export class UserDetailDto {
private readonly id: string;
private readonly name: string;
private readonly birthDate: Date;
private readonly gender: Gender;
private readonly phone: string;
private readonly address: string;
private readonly _id: string;
private readonly _name: string;
private readonly _birthDate: Date;
private readonly _gender: Gender;
private readonly _phone: string;
private readonly _address: string;
private readonly _avatarPath: string;

get getId(): string {
return this.id;
get avatarPath(): string {
return this._avatarPath;
}
get getName(): string {
return this.name;

get id(): string {
return this._id;
}
get getBirthDate(): Date {
return this.birthDate;

get name(): string {
return this._name;
}
get getGender(): string {
return this.gender;

get birthDate(): Date {
return this._birthDate;
}
get getPhone(): string {
return this.phone;

get gender(): Gender {
return this._gender;
}
get getAddress(): string {
return this.address;

get phone(): string {
return this._phone;
}

get address(): string {
return this._address;
}

constructor(req: IUpdateUserDetailReq) {
this.id = (req.user as IUser).id.toString();
const { name, birthDate, gender, phone, address } = req.body;
this.name = name;
this.birthDate = birthDate;
this.gender = gender;
this.phone = phone;
this.address = address;
this._id = (req.user as IUser).id.toString();
const { name, birthDate, gender, phone, address, avatarPath } = req.body;
this._name = name;
this._birthDate = birthDate;
this._gender = gender;
this._phone = phone;
this._address = address;
this._avatarPath = avatarPath;
}
}
13 changes: 7 additions & 6 deletions src/repository/userRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ export class UserRepository {

public async updateUserDetail(userDetailDto: UserDetailDto) {
return UserModel.findByIdAndUpdate(
{ _id: new Types.ObjectId(userDetailDto.getId) },
{ _id: new Types.ObjectId(userDetailDto.id) },
{
name: userDetailDto.getName,
birthDate: userDetailDto.getBirthDate,
gender: userDetailDto.getGender,
phone: userDetailDto.getPhone,
address: userDetailDto.getAddress,
name: userDetailDto.name,
birthDate: userDetailDto.birthDate,
gender: userDetailDto.gender,
phone: userDetailDto.phone,
address: userDetailDto.address,
avatarPath: userDetailDto.avatarPath,
},
updateOptions,
);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/userRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class UserRoute extends BaseRoute {
"gender": "none",
"phone": "0912345678",
"address": "aaaabbb",
"imgUrl": ""
"avatarPath": "avatarPath"
}
}
*/
Expand Down
1 change: 1 addition & 0 deletions src/types/user.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ export interface IUpdateUserDetailReq extends IUserReq {
gender: Gender;
phone: string;
address: string;
avatarPath: string;
};
}

0 comments on commit 8819a2d

Please sign in to comment.