diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 2b4120ce..f5bc83bc 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -6362,4 +6362,97 @@ export class ProfileController extends Controller { ); return new HttpSuccess(); } + + /** + * API แก้ไขเบอร์โทรศัพท์ + * + * @summary แก้ไขเบอร์โทรศัพท์ (USER) + * + */ + @Put("updatePhoneNumber/user") + async updatePhoneNumber(@Request() request: RequestWithUser, + @Body() + body: { + phone: string; + }, + ) { + const profile = await this.profileRepo.findOne({ + relations: { + posLevel: true, + posType: true, + }, + where: { keycloak: request.user.sub }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const history = new ProfileHistory(); + + Object.assign(profile, body); + Object.assign(history, { ...profile, id: undefined }); + + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.lastUpdatedAt = new Date(); + history.lastUpdateUserId = request.user.sub; + history.lastUpdateFullName = request.user.name; + history.createdUserId = request.user.sub; + history.createdFullName = request.user.name; + history.createdAt = new Date(); + history.lastUpdatedAt = new Date(); + + await Promise.all([ + this.profileRepo.save(profile, { data: request }), + this.profileHistoryRepo.save(history, { data: request }), + ]); + return new HttpSuccess(); + } + + /** + * API แก้ไขอีเมล + * + * @summary แก้ไขอีเมล (USER) + * + */ + @Put("updateEmail/user") + async updateEmail(@Request() request: RequestWithUser, + @Body() + body: { + email: string; + }, + ) { + const profile = await this.profileRepo.findOne({ + relations: { + posLevel: true, + posType: true, + }, + where: { keycloak: request.user.sub }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const history = new ProfileHistory(); + + Object.assign(profile, body); + Object.assign(history, { ...profile, id: undefined }); + + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + profile.lastUpdatedAt = new Date(); + history.lastUpdateUserId = request.user.sub; + history.lastUpdateFullName = request.user.name; + history.createdUserId = request.user.sub; + history.createdFullName = request.user.name; + history.createdAt = new Date(); + history.lastUpdatedAt = new Date(); + + await Promise.all([ + this.profileRepo.save(profile, { data: request }), + this.profileHistoryRepo.save(history, { data: request }), + ]); + return new HttpSuccess(); + } + + + } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 6b1cdec3..1bf72839 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -120,6 +120,13 @@ export class Profile extends EntityBase { }) email: string; + @Column({ + nullable: true, + comment: "สถานะอีเมล",//VERIFIED = ยืนยัน, NOT_VERIFIED = ไม่ได้ยืนยัน + default: null, + }) + statusEmail: string; + @Column({ nullable: true, length: 20,