เพิ่มฟิลด์ สถานะอีเมล (ลูกจ้าง)

This commit is contained in:
Bright 2025-04-23 17:15:34 +07:00
parent 8d8b034d7b
commit 56f4d3b85b
3 changed files with 264 additions and 0 deletions

View file

@ -5458,4 +5458,132 @@ export class ProfileEmployeeController extends Controller {
}
return new HttpSuccess(_profile);
}
async sendVerifyEmail(
@Request() req: RequestWithUser,
@Body()
body: {
profileId: string;
email: string;
subject: string;
},
) {
const jwt = require("jsonwebtoken");
const token = jwt.sign(
{ email_id: body.email, profileId: body.profileId },
process.env.AUTH_ACCOUNT_SECRET,
{ expiresIn: "15m" },
);
const link = process.env.VITE_URL_USER + "/verifyemail?upn=" + token;
await new CallAPI()
.PostData(req, "/placement/noti/send-mail", {
subject: body.subject,
body: link,
Email: body.email,
})
.catch((error) => {
console.error("Error calling API:", error);
});
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 ProfileEmployeeHistory();
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 ProfileEmployeeHistory();
Object.assign(profile, body);
Object.assign(history, { ...profile, id: undefined });
profile.statusEmail = "NOT_VERIFIED";
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 }),
]);
const verifyemailBody = {
profileId: profile.id,
email: body.email,
subject: "ยืนยันอีเมล",
};
this.sendVerifyEmail(request, verifyemailBody);
return new HttpSuccess();
}
}