no message

This commit is contained in:
kittapath 2024-11-22 12:18:12 +07:00
parent 102f1f6646
commit 44b8b516eb
6 changed files with 241 additions and 21 deletions

View file

@ -70,8 +70,6 @@ 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")
@ -1734,6 +1732,33 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.citizenId) {
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
const cal =
citizenIdDigits[0] * 13 +
citizenIdDigits[1] * 12 +
citizenIdDigits[2] * 11 +
citizenIdDigits[3] * 10 +
citizenIdDigits[4] * 9 +
citizenIdDigits[5] * 8 +
citizenIdDigits[6] * 7 +
citizenIdDigits[7] * 6 +
citizenIdDigits[8] * 5 +
citizenIdDigits[9] * 4 +
citizenIdDigits[10] * 3 +
citizenIdDigits[11] * 2;
const calStp2 = cal % 11;
let chkDigit = 11 - calStp2;
if (chkDigit === 10) {
chkDigit = 1;
} else if (chkDigit === 11) {
chkDigit = chkDigit % 10;
}
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
@ -1781,6 +1806,8 @@ export class ProfileController extends Controller {
// }
const profile = Object.assign(new Profile(), body);
profile.prefixMain = profile.prefix;
profile.prefix = profile.rank ?? profile.prefixMain;
profile.isProbation = false;
profile.isLeave = false;
profile.createdUserId = request.user.sub;
@ -1823,8 +1850,37 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (body.citizenId) {
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
const cal =
citizenIdDigits[0] * 13 +
citizenIdDigits[1] * 12 +
citizenIdDigits[2] * 11 +
citizenIdDigits[3] * 10 +
citizenIdDigits[4] * 9 +
citizenIdDigits[5] * 8 +
citizenIdDigits[6] * 7 +
citizenIdDigits[7] * 6 +
citizenIdDigits[8] * 5 +
citizenIdDigits[9] * 4 +
citizenIdDigits[10] * 3 +
citizenIdDigits[11] * 2;
const calStp2 = cal % 11;
let chkDigit = 11 - calStp2;
if (chkDigit === 10) {
chkDigit = 1;
} else if (chkDigit === 11) {
chkDigit = chkDigit % 10;
}
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
const profile: Profile = Object.assign(new Profile(), body);
const _null: any = null;
profile.prefixMain = profile.prefix;
profile.prefix = profile.rank ?? profile.prefixMain;
profile.dateRetire = body.birthDate == null ? _null : calculateRetireDate(body.birthDate);
profile.dateRetireLaw = body.birthDate == null ? _null : calculateRetireLaw(body.birthDate);
profile.createdUserId = request.user.sub;
@ -1864,7 +1920,36 @@ export class ProfileController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
if (body.citizenId) {
const citizenIdDigits = body.citizenId.toString().split("").map(Number);
const cal =
citizenIdDigits[0] * 13 +
citizenIdDigits[1] * 12 +
citizenIdDigits[2] * 11 +
citizenIdDigits[3] * 10 +
citizenIdDigits[4] * 9 +
citizenIdDigits[5] * 8 +
citizenIdDigits[6] * 7 +
citizenIdDigits[7] * 6 +
citizenIdDigits[8] * 5 +
citizenIdDigits[9] * 4 +
citizenIdDigits[10] * 3 +
citizenIdDigits[11] * 2;
const calStp2 = cal % 11;
let chkDigit = 11 - calStp2;
if (chkDigit === 10) {
chkDigit = 1;
} else if (chkDigit === 11) {
chkDigit = chkDigit % 10;
}
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
const profile: Profile = Object.assign(new Profile(), body);
profile.prefixMain = profile.prefix;
profile.prefix = profile.rank ?? profile.prefixMain;
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;
@ -1880,15 +1965,19 @@ export class ProfileController extends Controller {
@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'});
// console.log("[token]",token);
const link = process.env.URL + "/verifyemail?upn=" + token;
// console.log("[link]",link);
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" },
);
// console.log("[token]",token);
const link = process.env.URL + "/verifyemail?upn=" + token;
// console.log("[link]",link);
await new CallAPI()
.PostData(req, "/placement/noti/send-mail", {
@ -3172,6 +3261,8 @@ export class ProfileController extends Controller {
});
Object.assign(record, body);
record.prefixMain = record.prefix;
record.prefix = record.rank ?? record.prefixMain;
record.createdUserId = request.user.sub;
record.createdFullName = request.user.name;
record.createdAt = new Date();
@ -3418,13 +3509,10 @@ export class ProfileController extends Controller {
} else if (chkDigit === 11) {
chkDigit = chkDigit % 10;
}
// else if(chkDigit === 11){
// chkDigit = cal % 10;
// }
// if (citizenIdDigits[12] !== chkDigit) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
// }
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
const record = await this.profileRepo.findOneBy({ id });
const before = structuredClone(record);
@ -3432,6 +3520,8 @@ export class ProfileController extends Controller {
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
Object.assign(record, body);
record.prefixMain = record.prefix;
record.prefix = record.rank ?? record.prefixMain;
record.createdUserId = request.user.sub;
record.createdFullName = request.user.name;
record.createdAt = new Date();
@ -7779,6 +7869,8 @@ export class ProfileController extends Controller {
profile.registrationSubDistrictId = _null;
}
profile.prefixMain = profile.prefix;
profile.prefix = profile.rank ?? profile.prefixMain;
profile.createdUserId = request.user.sub;
profile.createdFullName = request.user.name;
profile.lastUpdateUserId = request.user.sub;