sort and verify email

This commit is contained in:
AdisakKanthawilang 2024-11-21 11:38:24 +07:00
parent 6abb33ccff
commit 657d885e32
2 changed files with 39 additions and 33 deletions

View file

@ -1482,7 +1482,8 @@ export class PositionController extends Controller {
},
relations: ["posLevel", "posType", "posExecutive"],
order: {
createdAt: "ASC",
posType:{posTypeRank: "ASC"},
posLevel:{posLevelRank: "ASC"}
},
});
@ -1908,7 +1909,8 @@ export class PositionController extends Controller {
},
relations: ["posLevel", "posType", "posExecutive"],
order: {
createdAt: "ASC",
posType:{posTypeRank: "ASC"},
posLevel:{posLevelRank: "ASC"}
},
});

View file

@ -70,6 +70,8 @@ import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHisto
import { viewDirector } from "../entities/view/viewDirector";
import { viewDirectorActing } from "../entities/view/viewDirectorActing";
import CallAPI from "../interfaces/call-api";
import { log } from "console";
import { Subject } from "typeorm/persistence/Subject.js";
@Route("api/v1/org/profile")
@Tags("Profile")
@Security("bearerAuth")
@ -1873,13 +1875,6 @@ export class ProfileController extends Controller {
return new HttpSuccess(profile.id);
}
/**
* API Email
*
* @summary Email
*
*/
@Post("send-verify-email")
async sendVerifyEmail(
@Request() req:RequestWithUser,
@Body()
@ -1889,29 +1884,22 @@ export class ProfileController extends Controller {
subject: string;
}
) {
const profile = await this.profileRepo.findOne({
where:{
id: body.profileId,
email: body.email
}
});
const jwt = require('jsonwebtoken');
const token = jwt.sign({email_id: body.email}, "Stack", {expiresIn: '24h'});
console.log("[token]",token);
const link = process.env.API_URL + "/" + token;
const token = jwt.sign({email_id: body.email, profileId: body.profileId}, process.env.AUTH_ACCOUNT_SECRET, {expiresIn: '5m'});
// console.log("[token]",token);
const link = process.env.URL + "/verifyemail/" + token;
// console.log("[link]",link);
const detail = null;
await new CallAPI()
.PostData(req, "/placement/notisend-mail", {
.PostData(req, "/placement/noti/send-mail", {
subject: body.subject,
body: detail,
body: link,
Email: body.email,
})
.catch((error) => {
console.error("Error calling API:", error);
});
});
return new HttpSuccess();
}
/**
@ -1920,19 +1908,29 @@ export class ProfileController extends Controller {
* @summary Email
*
*/
@Post("gen-link-verify-email")
@Post("verify-email")
async genLinkVerifyEmail(
@Request() req:RequestWithUser,
@Body() body:{
email: string;
token: string;
},
) {
// const profile = await this.profileRepo.findOne({
// where:{
// id: body.profileId,
// email: body.email
// }
// });
const jwt = require('jsonwebtoken');
const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey";
const decodedToken = jwt.verify(body.token, secretKey);
// console.log("[email]",decodedToken);
// console.log("[1]",decodedToken.email_id);
const profile = await this.profileRepo.findOne({
where:{
id: decodedToken.profileId,
email: decodedToken.email_id,
}
});
if(!profile){ throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");}
Object.assign(profile, body);
profile.statusEmail = "VERIFIED";
await this.profileRepo.save(profile)
}
@ -7982,6 +7980,12 @@ export class ProfileController extends Controller {
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();
}