Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-06-06 11:16:08 +07:00
commit 441295aae4
7 changed files with 87 additions and 139 deletions

View file

@ -309,19 +309,27 @@ export class PositionController extends Controller {
posDictField: requestBody.posDictField, posDictField: requestBody.posDictField,
posTypeId: requestBody.posTypeId, posTypeId: requestBody.posTypeId,
posLevelId: requestBody.posLevelId, posLevelId: requestBody.posLevelId,
posExecutiveId: String(requestBody.posExecutiveId), posExecutiveId: requestBody.posExecutiveId?requestBody.posExecutiveId:"",
posDictExecutiveField: requestBody.posDictExecutiveField, posDictExecutiveField: requestBody.posDictExecutiveField?requestBody.posDictExecutiveField:"",
posDictArea: requestBody.posDictArea, posDictArea: requestBody.posDictArea?requestBody.posDictArea:"",
isSpecial: requestBody.isSpecial, isSpecial: requestBody.isSpecial,
}, },
}); });
if (rowRepeated) { if (rowRepeated) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
} }
Object.assign(posDict, requestBody);
posDict.lastUpdateUserId = request.user.sub; posDict.lastUpdateUserId = request.user.sub;
posDict.lastUpdateFullName = request.user.name; posDict.lastUpdateFullName = request.user.name;
this.posDictRepository.merge(posDict, requestBody); posDict.posDictName = requestBody.posDictName,
posDict.posDictField = requestBody.posDictField,
posDict.posTypeId = requestBody.posTypeId,
posDict.posLevelId = requestBody.posLevelId,
posDict.posExecutiveId = requestBody.posExecutiveId?requestBody.posExecutiveId:null,
posDict.posDictExecutiveField = requestBody.posDictExecutiveField?requestBody.posDictExecutiveField:"",
posDict.posDictArea = requestBody.posDictArea?requestBody.posDictArea:"",
posDict.isSpecial = requestBody.isSpecial,
// this.posDictRepository.merge(posDict, requestBody);
await this.posDictRepository.save(posDict); await this.posDictRepository.save(posDict);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -386,14 +386,12 @@ export class ProfileController extends Controller {
Start: Start:
item.startDate == null item.startDate == null
? "" ? ""
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()), : Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)),
End: End:
item.endDate == null item.endDate == null ? "" : Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate)),
? ""
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
Date: Date:
item.startDate && item.endDate item.startDate && item.endDate
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
: "", : "",
Level: "", Level: "",
Degree: item.name, Degree: item.name,
@ -427,7 +425,7 @@ export class ProfileController extends Controller {
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
Date: Date:
item.startDate && item.endDate item.startDate && item.endDate
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
: "", : "",
Level: item.educationLevel ?? "", Level: item.educationLevel ?? "",
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "",

View file

@ -406,7 +406,7 @@ export class ProfileEmployeeController extends Controller {
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()), : Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
Date: Date:
item.startDate && item.endDate item.startDate && item.endDate
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
: "", : "",
Level: "", Level: "",
Degree: item.name, Degree: item.name,
@ -433,7 +433,7 @@ export class ProfileEmployeeController extends Controller {
End: new Date(item.endDate).getFullYear().toString() ?? null, End: new Date(item.endDate).getFullYear().toString() ?? null,
Date: Date:
item.startDate && item.endDate item.startDate && item.endDate
? `${Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString())} - ${Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString())}` ? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
: "", : "",
Level: item.educationLevel ?? null, Level: item.educationLevel ?? null,
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "", Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "",
@ -494,42 +494,11 @@ export class ProfileEmployeeController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
} }
if (body.citizenId.length !== 13) { if(body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){
throw new HttpError( body.employeeClass = "PERM";
HttpStatus.NOT_FOUND,
"กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก",
);
}
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;
}
// else if(chkDigit === 11){
// chkDigit = cal % 10;
// }
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
} }
if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) {
throw new HttpError(HttpStatus.NOT_FOUND, "ประเภทลูกจ้างไม่ถูกต้อง");
} }
const profile = Object.assign(new ProfileEmployee(), body); const profile = Object.assign(new ProfileEmployee(), body);
@ -539,8 +508,9 @@ export class ProfileEmployeeController extends Controller {
profile.lastUpdateFullName = request.user.name; profile.lastUpdateFullName = request.user.name;
profile.dateRetire = calculateRetireDate(profile.birthDate); profile.dateRetire = calculateRetireDate(profile.birthDate);
profile.dateRetireLaw = calculateRetireLaw(profile.birthDate); profile.dateRetireLaw = calculateRetireLaw(profile.birthDate);
profile.citizenId = Extension.CheckCitizen(profile.citizenId);
profile.employeeClass = profile.employeeClass.toLocaleUpperCase()
await this.profileRepo.save(profile); await this.profileRepo.save(profile);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -577,46 +547,8 @@ export class ProfileEmployeeController extends Controller {
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) { if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
} }
if (body.citizenId && body.citizenId.length !== 13) {
throw new HttpError(
HttpStatus.NOT_FOUND,
"กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก",
);
}
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;
}
// else if(chkDigit === 11){
// chkDigit = cal % 10;
// }
if (citizenIdDigits[12] !== chkDigit) {
throw new HttpError(HttpStatus.NOT_FOUND, "ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง");
}
}
const record = await this.profileRepo.findOneBy({ id }); const record = await this.profileRepo.findOneBy({ id });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
await this.profileHistoryRepo.save( await this.profileHistoryRepo.save(
@ -627,14 +559,21 @@ export class ProfileEmployeeController extends Controller {
}), }),
); );
if(body.employeeClass == null || body.employeeClass == undefined || body.employeeClass == ""){
body.employeeClass = "PERM";
}
if (!["PERM", "TEMP"].includes(body.employeeClass.toLocaleUpperCase())) {
throw new HttpError(HttpStatus.NOT_FOUND, "ประเภทลูกจ้างไม่ถูกต้อง");
}
Object.assign(record, body); Object.assign(record, body);
record.lastUpdateUserId = request.user.sub; record.lastUpdateUserId = request.user.sub;
record.lastUpdateFullName = request.user.name; record.lastUpdateFullName = request.user.name;
record.dateRetire = calculateRetireDate(record.birthDate); record.dateRetire = calculateRetireDate(record.birthDate);
record.dateRetireLaw = calculateRetireLaw(record.birthDate); record.dateRetireLaw = calculateRetireLaw(record.birthDate);
record.citizenId = Extension.CheckCitizen(record.citizenId);
record.employeeClass = record.employeeClass.toLocaleUpperCase();
await this.profileRepo.save(record); await this.profileRepo.save(record);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -846,6 +785,11 @@ export class ProfileEmployeeController extends Controller {
position: _data.position, position: _data.position,
posNo: shortName, posNo: shortName,
employeeClass: _data.employeeClass == null ? null : _data.employeeClass, employeeClass: _data.employeeClass == null ? null : _data.employeeClass,
dateAppoint: _data.dateAppoint,
dateStart: _data.dateStart,
createdAt: _data.createdAt,
dateRetireLaw: _data.dateRetireLaw,
draftOrgEmployeeStatus: null
}; };
}), }),
); );

View file

@ -209,7 +209,7 @@ export class KeycloakController extends Controller {
@Get("user") @Get("user")
async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") { async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") {
const total = await getUserCount(); const total = await getUserCount(first, max, search);
const result = await getUserList(first, max, search); const result = await getUserList(first, max, search);
if (Array.isArray(result)) { if (Array.isArray(result)) {

View file

@ -40,7 +40,7 @@ export class PosDict extends EntityBase {
comment: "ตำแหน่งทางการบริหาร", comment: "ตำแหน่งทางการบริหาร",
default: null, default: null,
}) })
posExecutiveId: string; posExecutiveId?: string|null;
@Column({ @Column({
nullable: true, nullable: true,
@ -94,10 +94,10 @@ export class CreatePosDict {
posExecutiveId?: string | null; posExecutiveId?: string | null;
@Column() @Column()
posDictExecutiveField: string | null; posDictExecutiveField?: string | null;
@Column() @Column()
posDictArea: string | null; posDictArea?: string | null;
@Column() @Column()
isSpecial: boolean; isSpecial: boolean;
@ -146,13 +146,13 @@ export class UpdatePosDict {
posLevelId: string; posLevelId: string;
@Column() @Column()
posExecutiveId?: string | undefined; posExecutiveId?: string | null;
@Column() @Column()
posDictExecutiveField: string; posDictExecutiveField?: string | null;
@Column() @Column()
posDictArea: string; posDictArea?: string | null;
@Column() @Column()
isSpecial: boolean; isSpecial: boolean;

View file

@ -472,51 +472,45 @@ export class ProfileEmployeeHistory extends ProfileEmployee {
} }
export class CreateProfileEmployee { export class CreateProfileEmployee {
rank: string;
prefix: string; prefix: string;
rank?: string | null;
firstName: string; firstName: string;
lastName: string; lastName: string;
// position: string;
// isProbation: boolean | null;
// dateRetire: Date | null;
birthDate: Date | null;
salaryLevel: number | null;
// ethnicity: string | null;
// telephoneNumber: string | null;
citizenId: string; citizenId: string;
// religion: string | null; birthDate?: Date | null;
posLevelId: string | null; position?: string | null;
posTypeId: string | null; posLevelId?: string | null;
// nationality: string | null; posTypeId?: string | null;
// gender: string | null; gender?: string | null;
// relationship: string | null; relationship?: string | null;
// bloodGroup: string | null; nationality?: string | null;
// email: string | null; ethnicity?: string | null;
// phone: string | null; religion?: string | null;
bloodGroup?: string | null;
phone?: string | null;
salaryLevel?: number | null;
employeeClass?: string | null;
} }
export type UpdateProfileEmployee = { export type UpdateProfileEmployee = {
prefix: string;
rank?: string | null; rank?: string | null;
prefix?: string | null; firstName: string;
firstName?: string | null; lastName: string;
lastName?: string | null; citizenId: string;
// position?: string | null;
// isProbation?: boolean | null;
// dateRetire?: Date | null;
birthDate?: Date | null; birthDate?: Date | null;
salaryLevel?: number | null; position?: string | null;
ethnicity?: string | null;
telephoneNumber?: string | null;
citizenId?: string;
religion: string | null;
posLevelId?: string | null; posLevelId?: string | null;
posTypeId?: string | null; posTypeId?: string | null;
nationality?: string | null;
gender?: string | null; gender?: string | null;
relationship?: string | null; relationship?: string | null;
nationality?: string | null;
ethnicity?: string | null;
religion?: string | null;
bloodGroup?: string | null; bloodGroup?: string | null;
email: string | null; phone?: string | null;
phone: string | null; salaryLevel?: number | null;
employeeClass?: string | null;
}; };
export type UpdateProfileAddressEmployee = { export type UpdateProfileAddressEmployee = {

View file

@ -150,12 +150,12 @@ export async function getUserList(first = "", max = "", search = "") {
})); }));
} }
export async function getUserCount() { export async function getUserCount(first = "", max = "", search = "") {
const res = await fetch( const res = await fetch(
`${KC_URL}/admin/realms/${KC_REALM}/users/count`, `${KC_URL}/admin/realms/${KC_REALM}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}`,
{ {
headers: { headers: {
"authorization": `Bearer ${await getToken()}`, authorization: `Bearer ${await getToken()}`,
"content-type": `application/json`, "content-type": `application/json`,
}, },
}, },
@ -283,13 +283,17 @@ export async function getRoles(name?: string) {
const data = (await res.json()) as any; const data = (await res.json()) as any;
if (Array.isArray(data)) { if (Array.isArray(data)) {
return data.map((v: Record<string, string>) => ({ id: v.id, name: v.name })); return data.map((v: Record<string, string>) => ({
id: v.id,
name: v.name,
description: v.description,
}));
} }
return { // return {
id: data.id, // id: data.id,
name: data.name, // name: data.name,
}; // };
} }
/** /**