edit phoneNUmber add field email

This commit is contained in:
AdisakKanthawilang 2024-10-18 12:09:46 +07:00
parent bd3cb33a5e
commit dca044eeae
2 changed files with 100 additions and 0 deletions

View file

@ -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();
}
}

View file

@ -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,