diff --git a/src/controllers/AuthRoleController.ts b/src/controllers/AuthRoleController.ts index 3084cf32..b6b747b1 100644 --- a/src/controllers/AuthRoleController.ts +++ b/src/controllers/AuthRoleController.ts @@ -101,6 +101,19 @@ export class AuthRoleController extends Controller { posMaster.lastUpdateFullName = req.user.name; posMaster.authRoleId = body.authRoleId; await this.posMasterRepository.save(posMaster); + + // เช็คว่าถ้ามีค่า current_holderId ให้ลบ key สิทธิ์ใน redis + if (posMaster.current_holderId) { + const redisClient = await this.redis.createClient({ + host: REDIS_HOST, + port: REDIS_PORT, + }); + redisClient.del("role_" + posMaster.current_holderId, (err: Error, response: Response) => { + if (err) throw err; + console.log(response); + }); + } + return new HttpSuccess(); } diff --git a/src/controllers/ChangePositionController.ts b/src/controllers/ChangePositionController.ts index 294ff7f6..49b925a1 100644 --- a/src/controllers/ChangePositionController.ts +++ b/src/controllers/ChangePositionController.ts @@ -4,14 +4,12 @@ import { Post, Put, Delete, - Patch, Route, Security, Tags, Body, Path, Request, - Example, SuccessResponse, Response, Query, @@ -20,18 +18,18 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; -import { Equal, ILike, In, IsNull, Like, Not, Brackets, MoreThan } from "typeorm"; +import { In, Not, Brackets } from "typeorm"; import { RequestWithUser } from "../middlewares/user"; -import { - ChangePosition, - CreateChangePosition, - UpdateChangePosition +import { + ChangePosition, + CreateChangePosition, + UpdateChangePosition, } from "../entities/ChangePosition"; -import { - ProfileChangePosition, - CreateProfileChangePosition, +import { + ProfileChangePosition, + CreateProfileChangePosition, UpdateProfileChangePosition, - SelectProfileChangePosition + SelectProfileChangePosition, } from "../entities/ProfileChangePosition"; import { OrgRoot } from "../entities/OrgRoot"; import { OrgChild1 } from "../entities/OrgChild1"; @@ -48,8 +46,8 @@ import CallAPI from "../interfaces/call-api"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ChangePositionController extends Controller { - private changePositionRepository = AppDataSource.getRepository(ChangePosition); - private profileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition); + private changePositionRepository = AppDataSource.getRepository(ChangePosition); + private profileChangePositionRepository = AppDataSource.getRepository(ProfileChangePosition); private orgRootRepository = AppDataSource.getRepository(OrgRoot); private child1Repository = AppDataSource.getRepository(OrgChild1); private child2Repository = AppDataSource.getRepository(OrgChild2); @@ -70,7 +68,7 @@ export class ChangePositionController extends Controller { const _changePosition = await this.changePositionRepository.findOne({ where: { name: body.name }, }); - if(_changePosition){ + if (_changePosition) { throw new HttpError( HttpStatusCode.INTERNAL_SERVER_ERROR, "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", @@ -79,9 +77,9 @@ export class ChangePositionController extends Controller { const changePosition = new ChangePosition(); Object.assign(changePosition, body); - changePosition.date = new Date, - changePosition.status = "WAITTING", - changePosition.createdUserId = request.user.sub; + (changePosition.date = new Date()), + (changePosition.status = "WAITTING"), + (changePosition.createdUserId = request.user.sub); changePosition.createdFullName = request.user.name; changePosition.lastUpdateUserId = request.user.sub; changePosition.lastUpdateFullName = request.user.name; @@ -126,17 +124,17 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: UpdateChangePosition, ) { - const changePosition = await this.changePositionRepository.findOneBy({ id }); - if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + if (!changePosition) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); const checkDuplicate = await this.changePositionRepository.find({ - where: { + where: { id: Not(id), - name: body.name + name: body.name, }, }); - if(checkDuplicate.length > 0){ + if (checkDuplicate.length > 0) { throw new HttpError( HttpStatusCode.INTERNAL_SERVER_ERROR, "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", @@ -165,10 +163,10 @@ export class ChangePositionController extends Controller { .createQueryBuilder("changePosition") .leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition") .where( - searchKeyword - ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" + searchKeyword + ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" : "1=1", - { keyword: `%${searchKeyword}%` } + { keyword: `%${searchKeyword}%` }, ) .orderBy("changePosition.date", "ASC") .skip((page - 1) * pageSize) @@ -181,7 +179,7 @@ export class ChangePositionController extends Controller { /** * API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว * - * @summary รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว (ADMIN) + * @summary รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง สถานะเลือกตำแหน่งแล้ว (ADMIN) * */ @Get("pending") @@ -190,9 +188,9 @@ export class ChangePositionController extends Controller { relations: ["profileChangePosition"], where: { profileChangePosition: { - status: "PENDING" - } - } + status: "PENDING", + }, + }, }); return new HttpSuccess(profiles); } @@ -201,16 +199,15 @@ export class ChangePositionController extends Controller { * API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายละเอียดรอบย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} id Id รอบย้ายสับเปลี่ยนตำแหน่ง */ @Get("{id}") - async GetChangePositionById( @Path() id: string ) { - - const data = await this.changePositionRepository.findOne({ + async GetChangePositionById(@Path() id: string) { + const data = await this.changePositionRepository.findOne({ relations: ["profileChangePosition"], - where: { id: id }} - ); + where: { id: id }, + }); if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); return new HttpSuccess(data); } @@ -229,18 +226,19 @@ export class ChangePositionController extends Controller { @Request() request: RequestWithUser, ) { const changePosition = await this.changePositionRepository.findOneBy({ id: changePositionId }); - if (!changePosition) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); + if (!changePosition) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); const profileChangePositions: ProfileChangePosition[] = []; const profiles = new ProfileChangePosition(); for (const data of body.profiles) { - Object.assign(profiles, data); + Object.assign(profiles, data); let positionOld = data.positionOld ? `${data.positionOld}` : ""; - let rootOld = data.rootOld ? data.positionOld ? `/${data.rootOld}` : `${data.rootOld}` : ""; + let rootOld = data.rootOld ? (data.positionOld ? `/${data.rootOld}` : `${data.rootOld}`) : ""; profiles.changePositionId = changePositionId; - profiles.organizationPositionOld = `${positionOld}${rootOld}`, - profiles.status = "WAITTING", - profiles.createdUserId = request.user.sub; + (profiles.organizationPositionOld = `${positionOld}${rootOld}`), + (profiles.status = "WAITTING"), + (profiles.createdUserId = request.user.sub); profiles.createdFullName = request.user.name; profiles.lastUpdateUserId = request.user.sub; profiles.lastUpdateFullName = request.user.name; @@ -270,16 +268,15 @@ export class ChangePositionController extends Controller { * API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายการรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} changePositionId Id รอบย้ายสับเปลี่ยนตำแหน่ง */ @Get("profile-all/{changePositionId}") - async GetProfileChangePositionLists( + async GetProfileChangePositionLists( @Path() changePositionId: string, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query() searchKeyword: string = "", - ) { const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition) .createQueryBuilder("profileChangePosition") @@ -287,7 +284,7 @@ export class ChangePositionController extends Controller { .andWhere( new Brackets((qb) => { qb.where( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.prefix LIKE :keyword" : "1=1", { @@ -295,7 +292,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.firstName LIKE :keyword" : "1=1", { @@ -303,7 +300,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.lastName LIKE :keyword" : "1=1", { @@ -311,7 +308,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.citizenId LIKE :keyword" : "1=1", { @@ -319,7 +316,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.birthDate LIKE :keyword" : "1=1", { @@ -327,7 +324,7 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.lastUpdatedAt LIKE :keyword" : "1=1", { @@ -335,13 +332,13 @@ export class ChangePositionController extends Controller { }, ) .orWhere( - searchKeyword != undefined && searchKeyword != null && searchKeyword != "" + searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? "profileChangePosition.status LIKE :keyword" : "1=1", { keyword: `%${searchKeyword}%`, }, - ) + ); }), ) .orderBy("profileChangePosition.createdAt", "ASC") @@ -356,17 +353,19 @@ export class ChangePositionController extends Controller { * API รายละเอียดรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง * * @summary API รายละเอียดรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง (ADMIN) - * + * * @param {string} id Id รายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง */ @Get("profile/{id}") - async GetProfileChangePositionById( - @Path() id: string - ) { + async GetProfileChangePositionById(@Path() id: string) { const profileChangePos = await this.profileChangePositionRepository.findOne({ - where: { id: id } + where: { id: id }, }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่ง", + ); return new HttpSuccess(profileChangePos); } @@ -383,9 +382,12 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: UpdateProfileChangePosition, ) { - const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้", + ); profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateFullName = request.user.name; @@ -395,7 +397,7 @@ export class ChangePositionController extends Controller { profileChangePos.positionLevelOld = body.positionLevelOld; profileChangePos.organizationPositionOld = body.organizationPositionOld; profileChangePos.amountOld = body.amountOld; - profileChangePos.reason = body.reason? String(body.reason) : ""; + profileChangePos.reason = body.reason ? String(body.reason) : ""; profileChangePos.dateCurrent = body.dateCurrent; await this.profileChangePositionRepository.save(profileChangePos); return new HttpSuccess(); @@ -414,9 +416,12 @@ export class ChangePositionController extends Controller { @Path() id: string, @Body() body: SelectProfileChangePosition, ) { - const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); - if (!profileChangePos) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้"); + if (!profileChangePos) + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่พบข้อมูลรายชื่อผู้ที่ย้ายสับเปลี่ยนตำแหน่งนี้", + ); switch (body.node) { case 0: { @@ -507,18 +512,18 @@ export class ChangePositionController extends Controller { profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateFullName = request.user.name; - profileChangePos.node = body.node; - profileChangePos.nodeId = body.nodeId; - profileChangePos.orgRevisionId = body.orgRevisionId; - profileChangePos.posmasterId = body.posmasterId; - profileChangePos.posMasterNo = body.posMasterNo; - profileChangePos.positionId = body.positionId; - profileChangePos.position = body.position; - profileChangePos.positionField = body.positionField; - profileChangePos.posTypeId = String(body.posTypeId); - profileChangePos.posTypeName = body.posTypeName; - profileChangePos.posLevelId = String(body.posLevelId); - profileChangePos.posLevelName = body.posLevelName; + profileChangePos.node = body.node; + profileChangePos.nodeId = body.nodeId; + profileChangePos.orgRevisionId = body.orgRevisionId; + profileChangePos.posmasterId = body.posmasterId; + profileChangePos.posMasterNo = body.posMasterNo; + profileChangePos.positionId = body.positionId; + profileChangePos.position = body.position; + profileChangePos.positionField = body.positionField; + profileChangePos.posTypeId = String(body.posTypeId); + profileChangePos.posTypeName = body.posTypeName; + profileChangePos.posLevelId = String(body.posLevelId); + profileChangePos.posLevelName = body.posLevelName; profileChangePos.status = "PENDING"; await this.profileChangePositionRepository.save(profileChangePos); return new HttpSuccess(); @@ -534,24 +539,24 @@ export class ChangePositionController extends Controller { async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { const profilechangePositions = await this.changePositionRepository.find({ relations: ["profileChangePosition"], - where: { id: In(requestBody.id) } - }); + where: { id: In(requestBody.id) }, + }); - for (const item of profilechangePositions) { - item.status = "REPORT"; - item.lastUpdateUserId = request.user.sub; - item.lastUpdateFullName = request.user.name; - if (item.profileChangePosition) { - for (const profile of item.profileChangePosition) { - profile.status = "REPORT"; - profile.lastUpdateUserId = request.user.sub; - profile.lastUpdateFullName = request.user.name; - await this.profileChangePositionRepository.save(profile); - } + for (const item of profilechangePositions) { + item.status = "REPORT"; + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + if (item.profileChangePosition) { + for (const profile of item.profileChangePosition) { + profile.status = "REPORT"; + profile.lastUpdateUserId = request.user.sub; + profile.lastUpdateFullName = request.user.name; + await this.profileChangePositionRepository.save(profile); } - await this.changePositionRepository.save(item); } - return new HttpSuccess(); + await this.changePositionRepository.save(item); + } + return new HttpSuccess(); } /** @@ -573,11 +578,11 @@ export class ChangePositionController extends Controller { await Promise.all( body.result.map(async (v) => { const profile = await this.profileChangePositionRepository.findOne({ - where: { id: v.id } + where: { id: v.id }, }); if (profile != null) { await new CallAPI() - .PostData(request, "org/profile/salary", { + .PostData(request, "/org/profile/salary", { profileId: profile.id, date: new Date(), }) diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 7534803d..e7ff17f0 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -2188,6 +2188,7 @@ export class EmployeePositionController extends Controller { ) { const posMaster = await this.employeePosMasterRepository.findOne({ where: { id: body.posmasterId }, + relations: ["orgRoot"], }); if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); @@ -2244,9 +2245,14 @@ export class EmployeePositionController extends Controller { }); if (positionNew != null) { positionNew.positionIsSelected = true; - profile.posLevel = positionNew.posLevel; - profile.posType = positionNew.posType; + profile.posLevelId = positionNew.posLevelId; + profile.posTypeId = positionNew.posTypeId; profile.position = positionNew.positionName; + profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null; + profile.positionEmployeePositionId = positionNew.positionName; + // profile.positionEmployeeLineId = "PERM"; + // profile.positionEmployeeGroupId = "PERM"; + await this.profileRepository.save(profile); await this.employeePositionRepository.save(positionNew); } diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index ff378dc5..986e0c2d 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -14,7 +14,7 @@ import { UploadedFile, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Brackets, Double } from "typeorm"; +import { Brackets, Double, In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -315,7 +315,7 @@ export class ImportDataController extends Controller { rowCount++; const profileSalary = new ProfileSalary(); profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; @@ -336,19 +336,20 @@ export class ImportDataController extends Controller { profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalarys.push(profileSalary); + // profileSalarys.push(profileSalary); // await this.salaryRepository.save(profileSalary); - if (profileSalarys.length === BATCH_SIZE) { - await this.salaryRepository.save(profileSalarys); - profileSalarys = await []; - } + // if (profileSalarys.length === BATCH_SIZE) { + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.salaryRepository.save(profileSalary); + // profileSalarys = await []; + // } }), ); // await this.salaryRepository.save(profileSalarys); // profileSalarys = await []; }), ); - await this.salaryRepository.save(profileSalarys); + // await this.salaryRepository.save(profileSalarys); // } console.log(rowCount); return new HttpSuccess(); @@ -406,7 +407,7 @@ export class ImportDataController extends Controller { const profileSalary = new ProfileSalary(); profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; @@ -427,13 +428,13 @@ export class ImportDataController extends Controller { profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalarys.push(profileSalary); + // profileSalarys.push(profileSalary); // await this.salaryRepository.save(profileSalary); - if (profileSalarys.length === BATCH_SIZE) { - await this.salaryRepository.save(profileSalarys); - profileSalarys = await []; - } + // if (profileSalarys.length === BATCH_SIZE) { console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.salaryRepository.save(profileSalary); + // profileSalarys = await []; + // } }), ); // await this.salaryRepository.save(profileSalarys); @@ -441,7 +442,7 @@ export class ImportDataController extends Controller { }), ); // } - await this.salaryRepository.save(profileSalarys); + // await this.salaryRepository.save(profileSalarys); console.log(rowCount); return new HttpSuccess(); } @@ -523,7 +524,16 @@ export class ImportDataController extends Controller { profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; @@ -550,7 +560,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(rowCount); + // console.log(rowCount); // await Promise.all([ // this.profileFamilyFatherRepository.save(fathers), @@ -638,7 +648,16 @@ export class ImportDataController extends Controller { profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; @@ -665,7 +684,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(rowCount); + // console.log(rowCount); // await Promise.all([ // this.profileFamilyFatherRepository.save(fathers), @@ -749,14 +768,14 @@ export class ImportDataController extends Controller { }); let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + // startDate = startDate ? new Date(startDate, 0, 1) : null_; let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + // endDate = endDate ? new Date(endDate, 0, 1) : null_; education.profileId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; @@ -768,6 +787,7 @@ export class ImportDataController extends Controller { education.lastUpdateUserId = request.user.sub; education.lastUpdateFullName = request.user.name; // await educations.push(await education); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.educationRepository.save(await education); }), ); @@ -776,7 +796,7 @@ export class ImportDataController extends Controller { }), ); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); } @@ -822,14 +842,14 @@ export class ImportDataController extends Controller { }); let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + // startDate = startDate ? new Date(startDate, 0, 1) : null_; let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + // endDate = endDate ? new Date(endDate, 0, 1) : null_; education.profileEmployeeId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; @@ -840,14 +860,16 @@ export class ImportDataController extends Controller { education.createdFullName = request.user.name; education.lastUpdateUserId = request.user.sub; education.lastUpdateFullName = request.user.name; - educations.push(education); + // educations.push(education); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.educationRepository.save(education); }), ); - await this.educationRepository.save(educations); + // await this.educationRepository.save(educations); }), ); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.educationRepository.save(educations); return new HttpSuccess(); } @@ -1086,15 +1108,18 @@ export class ImportDataController extends Controller { _item.registrationZipCode = existingProfile.ZIPCODE; _item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.createdUserId = request.user.sub; + _item.createdFullName = request.user.name; _item.lastUpdateUserId = request.user.sub; _item.lastUpdateFullName = request.user.name; // profileDatas.push(_item); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.profileRepo.save(_item); }), ); // await this.profileRepo.save(profileDatas); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); return new HttpSuccess(); } @@ -1152,7 +1177,7 @@ export class ImportDataController extends Controller { _item.registrationProvinceId = provinceId ? provinceId.id : null_; } } - if (existingProfile.AMPHUR_CODE) { + if (existingProfile.AMPHUR_CODE && provinceRegis_) { districtRegis_ = await this.amphurRepo.findOne({ where: { AMPHUR_CODE: existingProfile.AMPHUR_CODE, @@ -1168,7 +1193,7 @@ export class ImportDataController extends Controller { _item.registrationDistrictId = districtId ? districtId.id : null_; } } - if (existingProfile.DISTRICT_CODE) { + if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { subDistrictRegis_ = await this.subDistrictRepo.findOne({ where: { DISTRICT_CODE: existingProfile.DISTRICT_CODE, @@ -1199,7 +1224,7 @@ export class ImportDataController extends Controller { _item.currentProvinceId = provinceId ? provinceId.id : null_; } } - if (existingProfile.CONTACT_AMPHUR_CODE) { + if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) { districtCurr_ = await this.amphurRepo.findOne({ where: { AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, @@ -1215,7 +1240,7 @@ export class ImportDataController extends Controller { _item.currentDistrictId = districtId ? districtId.id : null_; } } - if (existingProfile.CONTACT_DISTRICT_CODE) { + if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) { subDistrictCurr_ = await this.subDistrictRepo.findOne({ where: { DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, @@ -1236,15 +1261,79 @@ export class ImportDataController extends Controller { _item.registrationZipCode = existingProfile.ZIPCODE; _item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.createdUserId = request.user.sub; + _item.createdFullName = request.user.name; _item.lastUpdateUserId = request.user.sub; _item.lastUpdateFullName = request.user.name; // profileDatas.push(_item); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); await this.profileEmpRepo.save(_item); }), ); // await this.profileEmpRepo.save(profileDatas); // } - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + return new HttpSuccess(); + } + /** + * @summary ทะเบียนประวัติ ข้าราชการ + */ + @Post("cleardataupload") + async ClearDataUpload(@Request() request: { user: Record }) { + const profileOff = await this.profileRepo.find({ + select: ["citizenId"], + }); + const profileEmp = await this.profileEmpRepo.find({ + select: ["citizenId"], + }); + const _profileOff = profileOff.map((x) => x.citizenId); + const _profileEmp = profileEmp.map((x) => x.citizenId); + const allId = _profileOff.concat(_profileEmp); + + for (var i = 1; i <= 1000; i++) { + const HR_POSITION_OFFICER = await this.HR_POSITION_OFFICERRepo.find({ + where: { CIT: Not(In(allId)) }, + take: 1000, + skip: 0, + }); + this.HR_POSITION_OFFICERRepo.remove(HR_POSITION_OFFICER); + // const HR_PERSONAL_OFFICER_FAMILY = await this.HR_PERSONAL_OFFICER_FAMILYRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_OFFICER_FAMILYRepo.remove(HR_PERSONAL_OFFICER_FAMILY); + // const HR_EDUCATION = await this.HR_EDUCATIONRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_EDUCATIONRepo.remove(HR_EDUCATION); + // const HR_PERSONAL_OFFICER_ADDRESS = await this.HR_PERSONAL_OFFICER_ADDRESSRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_OFFICER_ADDRESSRepo.remove(HR_PERSONAL_OFFICER_ADDRESS); + // const HR_EDUCATION_EMP = await this.HR_EDUCATION_EMPRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_EDUCATION_EMPRepo.remove(HR_EDUCATION_EMP); + // const HR_PERSONAL_EMP_ADDRESS = await this.HR_PERSONAL_EMP_ADDRESSRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_EMP_ADDRESSRepo.remove(HR_PERSONAL_EMP_ADDRESS); + // const HR_PERSONAL_EMP_FAMILY = await this.HR_PERSONAL_EMP_FAMILYRepo.find({ + // where: { CIT: Not(In(allId)) }, + // take: 1000, + // skip: 0, + // }); + // this.HR_PERSONAL_EMP_FAMILYRepo.remove(HR_PERSONAL_EMP_FAMILY); + } return new HttpSuccess(); } } diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 450cefeb..ef8e35a0 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -3,23 +3,19 @@ import { Get, Post, Put, - Delete, - Patch, Route, Security, Tags, Body, Path, Request, - Example, SuccessResponse, Response, - Query, } from "tsoa"; import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; -import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1"; +import { OrgChild1 } from "../entities/OrgChild1"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { In, IsNull, Not } from "typeorm"; @@ -29,7 +25,6 @@ import { OrgChild3 } from "../entities/OrgChild3"; import { OrgChild4 } from "../entities/OrgChild4"; import { PosMaster } from "../entities/PosMaster"; import { Position } from "../entities/Position"; -import { log } from "console"; import CallAPI from "../interfaces/call-api"; import { ProfileSalary } from "../entities/ProfileSalary"; import { Profile } from "../entities/Profile"; @@ -1680,7 +1675,7 @@ export class OrganizationController extends Controller { : item != null && item?.orgRoot != null ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}` : null; - await new CallAPI().PostData(request, "org/profile/salary", { + await new CallAPI().PostData(request, "/org/profile/salary", { profileId: item.next_holderId, date: new Date(), amount: profileSalary?.amount ?? null, @@ -1750,6 +1745,281 @@ export class OrganizationController extends Controller { return new HttpSuccess(); } + /** + * API Organizational Chart + * + * @summary Organizational Chart + * + * @param {string} revisionId Id revison + */ + @Get("org-chart/{revisionId}") + async orgchart(@Path() revisionId: string) { + const data = await this.orgRevisionRepository.findOne({ + where: { id: revisionId }, + }); + if (!data) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); + } + let posMasterRoot: any; + let posMasterChild1: any; + let posMasterChild2: any; + let posMasterChild3: any; + let posMasterChild4: any; + if (data.orgRevisionIsCurrent == true && data.orgRevisionIsDraft == false) { + posMasterRoot = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild1Id: IsNull(), + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot"], + }); + posMasterChild1 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild2Id: IsNull(), + orgChild1Id: Not(IsNull()), + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgChild1"], + }); + posMasterChild2 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild3Id: IsNull(), + orgChild2Id: Not(IsNull()), + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgChild2"], + }); + posMasterChild3 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild4Id: IsNull(), + orgChild3Id: Not(IsNull()), + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgChild3"], + }); + posMasterChild4 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild4Id: Not(IsNull()), + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgChild4"], + }); + + let formattedData = posMasterRoot + .filter((x: any) => x.current_holderId != null) + .map((x0: PosMaster) => ({ + personID: x0.current_holder.id, + name: x0.current_holder.firstName, + avatar: x0.current_holder.avatar, + positionName: x0.current_holder.position, + positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, + positionNumInt: x0.posMasterNo, + departmentName: x0.orgRoot.orgRootName, + organizationId: x0.orgRoot.id, + children: posMasterChild1 + .filter((x: any) => x.current_holderId != null && x.orgRootId == x0.orgRootId) + .map((x1: PosMaster) => ({ + personID: x1.current_holder.id, + name: x1.current_holder.firstName, + avatar: x1.current_holder.avatar, + positionName: x1.current_holder.position, + positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, + positionNumInt: x1.posMasterNo, + departmentName: x1.orgChild1.orgChild1Name, + organizationId: x1.orgChild1.id, + children: posMasterChild2 + .filter((x: any) => x.current_holderId != null && x.child1Id == x1.orgChild1Id) + .map((x2: PosMaster) => ({ + personID: x2.current_holder.id, + name: x2.current_holder.firstName, + avatar: x2.current_holder.avatar, + positionName: x2.current_holder.position, + positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, + positionNumInt: x2.posMasterNo, + departmentName: x2.orgChild2.orgChild2Name, + organizationId: x2.orgChild2.id, + children: posMasterChild3 + .filter((x: any) => x.current_holderId != null && x.child2Id == x2.orgChild2Id) + .map((x3: PosMaster) => ({ + personID: x3.current_holder.id, + name: x3.current_holder.firstName, + avatar: x3.current_holder.avatar, + positionName: x3.current_holder.position, + positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo, + positionNumInt: x3.posMasterNo, + departmentName: x3.orgChild3.orgChild3Name, + organizationId: x3.orgChild3.id, + children: posMasterChild4 + .filter( + (x: any) => x.current_holderId != null && x.child3Id == x3.orgChild3Id, + ) + .map((x4: PosMaster) => ({ + personID: x4.current_holder.id, + name: x4.current_holder.firstName, + avatar: x4.current_holder.avatar, + positionName: x4.current_holder.position, + positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, + positionNumInt: x4.posMasterNo, + departmentName: x4.orgChild4.orgChild4Name, + organizationId: x4.orgChild4.id, + })), + })), + })), + })), + })); + + const formattedData_ = { + personID: "", + name: "", + avatar: "", + positionName: "", + positionNum: "", + positionNumInt: null, + departmentName: data.orgRevisionName, + organizationId: data.id, + children: formattedData, + }; + return new HttpSuccess([formattedData_]); + } else if (data.orgRevisionIsCurrent == false && data.orgRevisionIsDraft == true) { + posMasterRoot = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild1Id: IsNull(), + next_holderId: Not(IsNull()), + }, + relations: ["next_holder", "orgRoot"], + }); + posMasterChild1 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild2Id: IsNull(), + orgChild1Id: Not(IsNull()), + next_holderId: Not(IsNull()), + }, + relations: ["next_holder", "orgChild1"], + }); + posMasterChild2 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild3Id: IsNull(), + orgChild2Id: Not(IsNull()), + next_holderId: Not(IsNull()), + }, + relations: ["next_holder", "orgChild2"], + }); + posMasterChild3 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild4Id: IsNull(), + orgChild3Id: Not(IsNull()), + next_holderId: Not(IsNull()), + }, + relations: ["next_holder", "orgChild3"], + }); + posMasterChild4 = await this.posMasterRepository.find({ + where: { + orgRevisionId: data.id, + orgChild4Id: Not(IsNull()), + next_holderId: Not(IsNull()), + }, + relations: ["next_holder", "orgChild4"], + }); + + let formattedData = posMasterRoot + .filter((x: any) => x.next_holderId != null) + .map((x0: PosMaster) => ({ + personID: x0.next_holder.id, + name: x0.next_holder.firstName, + avatar: x0.next_holder.avatar, + positionName: x0.next_holder.position, + positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo, + positionNumInt: x0.posMasterNo, + departmentName: x0.orgRoot.orgRootName, + organizationId: x0.orgRoot.id, + children: posMasterChild1 + .filter((x: any) => x.next_holderId != null && x.orgRootId == x0.orgRootId) + .map((x1: PosMaster) => ({ + personID: x1.next_holder.id, + name: x1.next_holder.firstName, + avatar: x1.next_holder.avatar, + positionName: x1.next_holder.position, + positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo, + positionNumInt: x1.posMasterNo, + departmentName: x1.orgChild1.orgChild1Name, + organizationId: x1.orgChild1.id, + children: posMasterChild2 + .filter((x: any) => x.next_holderId != null && x.child1Id == x1.orgChild1Id) + .map((x2: PosMaster) => ({ + personID: x2.next_holder.id, + name: x2.next_holder.firstName, + avatar: x2.next_holder.avatar, + positionName: x2.next_holder.position, + positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo, + positionNumInt: x2.posMasterNo, + departmentName: x2.orgChild2.orgChild2Name, + organizationId: x2.orgChild2.id, + children: posMasterChild3 + .filter((x: any) => x.next_holderId != null && x.child2Id == x2.orgChild2Id) + .map((x3: PosMaster) => ({ + personID: x3.next_holder.id, + name: x3.next_holder.firstName, + avatar: x3.next_holder.avatar, + positionName: x3.next_holder.position, + positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo, + positionNumInt: x3.posMasterNo, + departmentName: x3.orgChild3.orgChild3Name, + organizationId: x3.orgChild3.id, + children: posMasterChild4 + .filter((x: any) => x.next_holderId != null && x.child3Id == x3.orgChild3Id) + .map((x4: PosMaster) => ({ + personID: x4.next_holder.id, + name: x4.next_holder.firstName, + avatar: x4.next_holder.avatar, + positionName: x4.next_holder.position, + positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo, + positionNumInt: x4.posMasterNo, + departmentName: x4.orgChild4.orgChild4Name, + organizationId: x4.orgChild4.id, + })), + })), + })), + })), + })); + + const formattedData_ = { + personID: "", + name: "", + avatar: "", + positionName: "", + positionNum: "", + positionNumInt: null, + departmentName: data.orgRevisionName, + organizationId: data.id, + children: formattedData, + }; + return new HttpSuccess([formattedData_]); + } else { + return new HttpSuccess([ + { + personID: "", + name: "", + avatar: "", + positionName: "", + positionNum: "", + positionNumInt: null, + departmentName: data.orgRevisionName, + organizationId: data.id, + children: [], + }, + ]); + } + } + /** * API Organizational StructChart * @@ -3441,15 +3711,15 @@ export class OrganizationController extends Controller { }); if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); const posMaster = await this.posMasterRepository.find({ - where: { orgRootId: root.id, orgChild1Id: IsNull() }, + where: { orgRootId: root.id, orgChild1Id: IsNull(), current_holder: Not(IsNull()) }, relations: ["current_holder"], }); if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); const maps = posMaster.map((posMaster) => ({ - id: posMaster.current_holder.id, - name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`, - positionName: posMaster.current_holder.position, + id: posMaster?.current_holder?.id, + name: `${posMaster?.current_holder?.prefix}${posMaster?.current_holder?.firstName} ${posMaster?.current_holder?.lastName}`, + positionName: posMaster?.current_holder?.position, })); return new HttpSuccess(maps); diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 64dfe557..8016639d 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -35,54 +35,60 @@ export class PermissionController extends Controller { const getAsync = promisify(redisClient.get).bind(redisClient); let reply = await getAsync("role_" + request.user.sub); - // if (reply != null) { - // reply = JSON.parse(reply); - // } else { - const profile = await this.profileRepo.findOne({ - select: ["id"], - where: { keycloak: request.user.sub }, - }); - if (!profile) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + if (reply != null) { + reply = JSON.parse(reply); + } else { + const profile = await this.profileRepo.findOne({ + select: ["id"], + where: { keycloak: request.user.sub }, + }); + if (!profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); + } + + const posMaster = await this.posMasterRepository.findOne({ + // select: ["authRoleId"], + where: { + current_holderId: profile.id, + orgRevision: { + orgRevisionIsDraft: false, + orgRevisionIsCurrent: true, + }, + }, + }); + if (!posMaster) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); + } + + const getDetail = await this.authRoleRepo.findOne({ + select: ["id", "roleName", "roleDescription"], + where: { id: posMaster.authRoleId }, + }); + if (!getDetail) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const roleAttrData = await this.authRoleAttrRepo.find({ + select: [ + "authSysId", + "parentNode", + "attrOwnership", + "attrIsCreate", + "attrIsList", + "attrIsGet", + "attrIsUpdate", + "attrIsDelete", + "attrPrivilege", + ], + where: { authRoleId: getDetail.id }, + }); + + reply = { + ...getDetail, + roles: roleAttrData, + }; + redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply)); } - - const posMaster = await this.posMasterRepository.findOne({ - select: ["authRoleId"], - where: { current_holderId: profile.id }, - }); - if (!posMaster) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์"); - } - - const getDetail = await this.authRoleRepo.findOne({ - select: ["id", "roleName", "roleDescription"], - where: { id: posMaster.authRoleId }, - }); - if (!getDetail) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const roleAttrData = await this.authRoleAttrRepo.find({ - select: [ - "authSysId", - "parentNode", - "attrOwnership", - "attrIsCreate", - "attrIsList", - "attrIsGet", - "attrIsUpdate", - "attrIsDelete", - "attrPrivilege", - ], - where: { authRoleId: getDetail.id }, - }); - - reply = { - ...getDetail, - roles: roleAttrData, - }; - // redisClient.setex("role_" + request.user.sub, 86400, JSON.stringify(reply)); - // } return new HttpSuccess(reply); } @@ -98,7 +104,6 @@ export class PermissionController extends Controller { if (reply != null) { reply = JSON.parse(reply); } else { - console.log(request.user.sub); const profile = await this.profileRepo.findOne({ select: ["id"], where: { keycloak: request.user.sub }, @@ -137,23 +142,36 @@ export class PermissionController extends Controller { const getList = await this.authSysRepo.find({ select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"], - where: { - id: In(sysId), - }, + where: [ + { + id: In(sysId), + }, + { + parentId: In(sysId), + }, + ], }); - const reply = getList + reply = await getList .filter((x) => x.parentId == null) + .sort((a, b) => a.order - b.order) .map((item) => { return { ...item, children: getList .filter((x) => x.parentId == item.id) - .sort((a, b) => a.order - b.order), + .sort((a, b) => a.order - b.order) + .map((item2) => { + return { + ...item2, + children: getList + .filter((x) => x.parentId == item2.id) + .sort((a, b) => a.order - b.order), + }; + }), }; - }) - .sort((a, b) => a.order - b.order); - // console.log(JSON.stringify(reply)); + }); + redisClient.setex("menu_" + request.user.sub, 86400, JSON.stringify(reply)); } diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index af8eafd3..b46b60d4 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -3417,8 +3417,8 @@ export class PositionController extends Controller { }); if (positionNew != null) { positionNew.positionIsSelected = true; - profile.posLevel = positionNew.posLevel; - profile.posType = positionNew.posType; + profile.posLevelId = positionNew.posLevelId; + profile.posTypeId = positionNew.posTypeId; profile.position = positionNew.positionName; await this.profileRepository.save(profile); await this.positionRepository.save(positionNew); diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index 8bae21a6..5414f07f 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -24,7 +24,7 @@ import { RequestWithUser } from "../middlewares/user"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/ability") @Tags("ProfileAbility") @Security("bearerAuth") @@ -133,6 +133,7 @@ export class ProfileAbilityController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileAbility, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -163,6 +164,7 @@ export class ProfileAbilityController extends Controller { @Request() req: RequestWithUser, @Path() abilityId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -184,7 +186,8 @@ export class ProfileAbilityController extends Controller { } @Delete("{abilityId}") - public async deleteProfileAbility(@Path() abilityId: string) { + public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser,) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.profileAbilityHistoryRepo.delete({ profileAbilityId: abilityId, }); diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index 10e67463..d18927c5 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -26,7 +26,7 @@ import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/ability") @Tags("ProfileAbilityEmployee") @Security("bearerAuth") @@ -136,6 +136,7 @@ export class ProfileAbilityEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileAbilityEmployee, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -166,6 +167,7 @@ export class ProfileAbilityEmployeeController extends Controller { @Request() req: RequestWithUser, @Path() abilityId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -187,7 +189,8 @@ export class ProfileAbilityEmployeeController extends Controller { } @Delete("{abilityId}") - public async deleteProfileAbility(@Path() abilityId: string) { + public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.profileAbilityHistoryRepo.delete({ profileAbilityId: abilityId, }); diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index 156a6160..be87a538 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -26,7 +26,7 @@ import { AppDataSource } from "../database/data-source"; import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/address") @Tags("ProfileAddress") @Security("bearerAuth") @@ -182,6 +182,7 @@ export class ProfileAddressController extends Controller { @Request() req: RequestWithUser, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.profileRepo.findOneBy({ id: profileId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileAddressEmployeeController.ts b/src/controllers/ProfileAddressEmployeeController.ts index 3ec8a3d9..04ede998 100644 --- a/src/controllers/ProfileAddressEmployeeController.ts +++ b/src/controllers/ProfileAddressEmployeeController.ts @@ -27,7 +27,7 @@ import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/address") @Tags("ProfileAddressEmployee") @Security("bearerAuth") @@ -183,6 +183,7 @@ export class ProfileAddressEmployeeController extends Controller { @Request() req: RequestWithUser, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.profileEmployeeRepo.findOneBy({ id: profileId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index dfbecd3c..6accbfe4 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -19,7 +19,6 @@ import { import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; - import { AppDataSource } from "../database/data-source"; import { CreateProfileAssessment, @@ -29,7 +28,7 @@ import { import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory"; import { Profile } from "../entities/Profile"; import { RequestWithUser } from "../middlewares/user"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/assessments") @Tags("ProfileAssessments") @Security("bearerAuth") @@ -147,6 +146,7 @@ export class ProfileAssessmentsController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileAssessment, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -176,6 +176,7 @@ export class ProfileAssessmentsController extends Controller { @Request() req: RequestWithUser, @Path() assessmentId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -196,7 +197,8 @@ export class ProfileAssessmentsController extends Controller { } @Delete("{assessmentId}") - public async deleteProfileAssessment(@Path() assessmentId: string) { + public async deleteProfileAssessment(@Path() assessmentId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.profileAssessmentsHistoryRepository.delete({ profileAssessmentId: assessmentId, }); diff --git a/src/controllers/ProfileAssessmentsEmployeeController.ts b/src/controllers/ProfileAssessmentsEmployeeController.ts index 7813e928..3329c6c4 100644 --- a/src/controllers/ProfileAssessmentsEmployeeController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeController.ts @@ -19,7 +19,6 @@ import { import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import HttpSuccess from "../interfaces/http-success"; - import { AppDataSource } from "../database/data-source"; import { CreateProfileEmployeeAssessment, @@ -29,7 +28,7 @@ import { import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { RequestWithUser } from "../middlewares/user"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/assessments") @Tags("ProfileEmployeeAssessments") @Security("bearerAuth") @@ -149,6 +148,7 @@ export class ProfileAssessmentsEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeAssessment, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -178,6 +178,7 @@ export class ProfileAssessmentsEmployeeController extends Controller { @Request() req: RequestWithUser, @Path() assessmentId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -198,7 +199,8 @@ export class ProfileAssessmentsEmployeeController extends Controller { } @Delete("{assessmentId}") - public async deleteProfileAssessment(@Path() assessmentId: string) { + public async deleteProfileAssessment(@Path() assessmentId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.profileAssessmentsHistoryRepository.delete({ profileAssessmentId: assessmentId, }); diff --git a/src/controllers/ProfileAvatarController.ts b/src/controllers/ProfileAvatarController.ts index 0c194ed8..9b176354 100644 --- a/src/controllers/ProfileAvatarController.ts +++ b/src/controllers/ProfileAvatarController.ts @@ -6,7 +6,7 @@ import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/avatar") @Tags("ProfileAvatar") @Security("bearerAuth") @@ -63,6 +63,7 @@ export class ProfileAvatarController extends Controller { @Post() public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); const profile = await this.profileRepository.findOne({ where: { id: body.profileId }, }); @@ -113,7 +114,8 @@ export class ProfileAvatarController extends Controller { } @Delete("{avatarId}") - public async deleteAvatar(@Path() avatarId: string) { + public async deleteAvatar(@Path() avatarId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); const result = await this.avatarRepository.delete({ id: avatarId }); if (result.affected == undefined || result.affected <= 0) { diff --git a/src/controllers/ProfileAvatarEmployeeController.ts b/src/controllers/ProfileAvatarEmployeeController.ts index 362902bc..a13a212a 100644 --- a/src/controllers/ProfileAvatarEmployeeController.ts +++ b/src/controllers/ProfileAvatarEmployeeController.ts @@ -6,7 +6,7 @@ import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/avatar") @Tags("ProfileAvatar") @Security("bearerAuth") @@ -54,6 +54,7 @@ export class ProfileAvatarEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeAvatar, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); const profile = await this.profileRepository.findOne({ where: { id: body.profileEmployeeId }, }); @@ -104,7 +105,8 @@ export class ProfileAvatarEmployeeController extends Controller { } @Delete("{avatarId}") - public async deleteAvatarEmployee(@Path() avatarId: string) { + public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); const result = await this.avatarRepository.delete({ id: avatarId }); if (result.affected == undefined || result.affected <= 0) { diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index b8abf0bb..aece1c2a 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/certificate") @Tags("ProfileCertificate") @Security("bearerAuth") @@ -122,6 +122,7 @@ export class ProfileCertificateController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileCertificate, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -154,6 +155,7 @@ export class ProfileCertificateController extends Controller { @Body() body: UpdateProfileCertificate, @Path() certificateId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.certificateRepo.findOneBy({ id: certificateId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -175,7 +177,8 @@ export class ProfileCertificateController extends Controller { } @Delete("{certificateId}") - public async deleteCertificate(@Path() certificateId: string) { + public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.certificateHistoryRepo.delete({ profileCertificateId: certificateId, }); diff --git a/src/controllers/ProfileCertificateEmployeeController.ts b/src/controllers/ProfileCertificateEmployeeController.ts index 5fbcfc55..2a4fb61a 100644 --- a/src/controllers/ProfileCertificateEmployeeController.ts +++ b/src/controllers/ProfileCertificateEmployeeController.ts @@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/certificate") @Tags("ProfileEmployeeCertificate") @Security("bearerAuth") @@ -121,6 +121,7 @@ export class ProfileCertificateEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeCertificate, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -153,6 +154,7 @@ export class ProfileCertificateEmployeeController extends Controller { @Body() body: UpdateProfileCertificate, @Path() certificateId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.certificateRepo.findOneBy({ id: certificateId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -174,7 +176,8 @@ export class ProfileCertificateEmployeeController extends Controller { } @Delete("{certificateId}") - public async deleteCertificate(@Path() certificateId: string) { + public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.certificateHistoryRepo.delete({ profileCertificateId: certificateId, }); diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index f4238fe1..372588fb 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -26,7 +26,7 @@ import { } from "../entities/ProfileChangeName"; import CallAPI from "../interfaces/call-api"; import { updateName } from "../keycloak"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/changeName") @Tags("ProfileChangeName") @Security("bearerAuth") @@ -119,6 +119,7 @@ export class ProfileChangeNameController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileChangeName, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -164,6 +165,7 @@ export class ProfileChangeNameController extends Controller { @Body() body: UpdateProfileChangeName, @Path() changeNameId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -212,7 +214,8 @@ export class ProfileChangeNameController extends Controller { } @Delete("{changeNameId}") - public async deleteTraning(@Path() changeNameId: string) { + public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser,) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.changeNameHistoryRepository.delete({ profileChangeNameId: changeNameId, }); diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 5d653f59..5106cab5 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -26,7 +26,7 @@ import { UpdateProfileChangeName, } from "../entities/ProfileChangeName"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/changeName") @Tags("ProfileChangeNameEmployee") @Security("bearerAuth") @@ -119,6 +119,7 @@ export class ProfileChangeNameEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileChangeNameEmployee, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -156,6 +157,7 @@ export class ProfileChangeNameEmployeeController extends Controller { @Body() body: UpdateProfileChangeName, @Path() changeNameId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -196,7 +198,8 @@ export class ProfileChangeNameEmployeeController extends Controller { } @Delete("{changeNameId}") - public async deleteTraning(@Path() changeNameId: string) { + public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.changeNameHistoryRepository.delete({ profileChangeNameId: changeNameId, }); diff --git a/src/controllers/ProfileChildrenController.ts b/src/controllers/ProfileChildrenController.ts index f2b4f202..70021fca 100644 --- a/src/controllers/ProfileChildrenController.ts +++ b/src/controllers/ProfileChildrenController.ts @@ -25,6 +25,7 @@ import { UpdateProfileChildren, } from "../entities/ProfileChildren"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/family/children") @Tags("ProfileChildren") @Security("bearerAuth") @@ -64,6 +65,7 @@ export class ProfileChildrenController extends Controller { @Post() public async newChildren(@Request() req: RequestWithUser, @Body() body: CreateProfileChildren) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); const profile = await this.profileRepository.findOneBy({ id: body.profileId }); if (!profile) { @@ -106,6 +108,7 @@ export class ProfileChildrenController extends Controller { @Body() body: UpdateProfileChildren, @Path() childrenId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.childrenRepository.findOneBy({ id: childrenId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -132,7 +135,8 @@ export class ProfileChildrenController extends Controller { } @Delete("{childrenId}") - public async deleteTraning(@Path() childrenId: string) { + public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser,) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.childrenHistoryRepository.delete({ profileChildrenId: childrenId, }); diff --git a/src/controllers/ProfileChildrenEmployeeController.ts b/src/controllers/ProfileChildrenEmployeeController.ts index a515c896..24b08d68 100644 --- a/src/controllers/ProfileChildrenEmployeeController.ts +++ b/src/controllers/ProfileChildrenEmployeeController.ts @@ -27,6 +27,7 @@ import { } from "../entities/ProfileChildren"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/family/children") @Tags("ProfileChildren") @Security("bearerAuth") @@ -69,6 +70,7 @@ export class ProfileChildrenEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileChildrenEmployee, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); if (!profile) { @@ -113,6 +115,7 @@ export class ProfileChildrenEmployeeController extends Controller { @Body() body: UpdateProfileChildren, @Path() childrenId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.childrenRepository.findOneBy({ id: childrenId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -141,7 +144,8 @@ export class ProfileChildrenEmployeeController extends Controller { } @Delete("{childrenId}") - public async deleteTraning(@Path() childrenId: string) { + public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.childrenHistoryRepository.delete({ profileChildrenId: childrenId, }); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index bec9eb16..6f05547e 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -59,7 +59,7 @@ import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory"; import { ProfileLeave } from "../entities/ProfileLeave"; import { updateName } from "../keycloak"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -2250,6 +2250,7 @@ export class ProfileController extends Controller { @Path() id: string, @Body() body: UpdateProfile, ) { + await new permission().PermissionUpdate(request,"SYS_REGISTRY"); const exists = !!body.citizenId && (await this.profileRepo.findOne({ diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 8a7780d7..ced55b63 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -24,7 +24,7 @@ import { ProfileDiscipline, UpdateProfileDiscipline, } from "../entities/ProfileDiscipline"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/discipline") @Tags("ProfileDiscipline") @Security("bearerAuth") @@ -124,6 +124,7 @@ export class ProfileDisciplineController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileDiscipline, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -156,6 +157,7 @@ export class ProfileDisciplineController extends Controller { @Body() body: UpdateProfileDiscipline, @Path() disciplineId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -177,7 +179,8 @@ export class ProfileDisciplineController extends Controller { } @Delete("{disciplineId}") - public async deleteDiscipline(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 4819c9f3..daff6982 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -24,7 +24,7 @@ import { UpdateProfileDiscipline, } from "../entities/ProfileDiscipline"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/discipline") @Tags("ProfileDisciplineEmployee") @Security("bearerAuth") @@ -115,6 +115,7 @@ export class ProfileDisciplineEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDiscipline, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -147,6 +148,7 @@ export class ProfileDisciplineEmployeeController extends Controller { @Body() body: UpdateProfileDiscipline, @Path() disciplineId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -168,7 +170,8 @@ export class ProfileDisciplineEmployeeController extends Controller { } @Delete("{disciplineId}") - public async deleteDiscipline(@Path() disciplineId: string) { + public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.disciplineHistoryRepository.delete({ profileDisciplineId: disciplineId, }); diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index dc70e062..31c17037 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -20,7 +20,7 @@ import { ProfileDutyHistory } from "../entities/ProfileDutyHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/duty") @Tags("ProfileDuty") @Security("bearerAuth") @@ -128,6 +128,7 @@ export class ProfileDutyController extends Controller { @Post() public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileDuty) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -160,6 +161,7 @@ export class ProfileDutyController extends Controller { @Body() body: UpdateProfileDuty, @Path() dutyId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.dutyRepository.findOneBy({ id: dutyId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -178,7 +180,8 @@ export class ProfileDutyController extends Controller { } @Delete("{dutyId}") - public async deleteDuty(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 8d039092..8e6b6a6b 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -20,7 +20,7 @@ import { ProfileDutyHistory } from "../entities/ProfileDutyHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/duty") @Tags("ProfileEmployeeDuty") @Security("bearerAuth") @@ -89,6 +89,7 @@ export class ProfileDutyEmployeeController extends Controller { @Post() public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -121,6 +122,7 @@ export class ProfileDutyEmployeeController extends Controller { @Body() body: UpdateProfileDuty, @Path() dutyId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.dutyRepository.findOneBy({ id: dutyId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -139,7 +141,8 @@ export class ProfileDutyEmployeeController extends Controller { } @Delete("{dutyId}") - public async deleteDuty(@Path() dutyId: string) { + public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.dutyHistoryRepository.delete({ profileDutyId: dutyId, }); diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index 4a0f1332..5ae7821a 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -30,7 +30,7 @@ import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { AppDataSource } from "../database/data-source"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/educations") @Tags("ProfileEducations") @Security("bearerAuth") @@ -181,6 +181,7 @@ export class ProfileEducationsController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEducation, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -211,6 +212,7 @@ export class ProfileEducationsController extends Controller { @Request() req: RequestWithUser, @Path() educationId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.profileEducationRepo.findOneBy({ id: educationId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -232,7 +234,8 @@ export class ProfileEducationsController extends Controller { } @Delete("{educationId}") - public async deleteProfileEducation(@Path() educationId: string) { + public async deleteProfileEducation(@Path() educationId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.profileEducationHistoryRepo.delete({ profileEducationId: educationId, }); diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index eececfbf..f2e42933 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -16,11 +16,9 @@ import { Patch, Example, } from "tsoa"; - import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; - import { ProfileEducation, CreateProfileEducation, @@ -32,7 +30,7 @@ import { Profile } from "../entities/Profile"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { AppDataSource } from "../database/data-source"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/educations") @Tags("ProfileEducationsEmployee") @Security("bearerAuth") @@ -185,6 +183,7 @@ export class ProfileEducationsEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEducationEmployee, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -215,6 +214,7 @@ export class ProfileEducationsEmployeeController extends Controller { @Request() req: RequestWithUser, @Path() educationId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.profileEducationRepo.findOneBy({ id: educationId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -236,7 +236,8 @@ export class ProfileEducationsEmployeeController extends Controller { } @Delete("{educationId}") - public async deleteProfileEducation(@Path() educationId: string) { + public async deleteProfileEducation(@Path() educationId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.profileEducationHistoryRepo.delete({ profileEducationId: educationId, }); diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index e5fae7ab..87214166 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -37,7 +37,6 @@ import { import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosType } from "../entities/EmployeePosType"; import { RequestWithUser } from "../middlewares/user"; -import { Position } from "../entities/Position"; import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; @@ -63,11 +62,10 @@ import { } from "../entities/ProfileEmployeeEmployment"; import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; import CallAPI from "../interfaces/call-api"; -import e from "cors"; import { EmployeePosition } from "../entities/EmployeePosition"; import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileLeave } from "../entities/ProfileLeave"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @Security("bearerAuth") @@ -578,6 +576,7 @@ export class ProfileEmployeeController extends Controller { */ @Post() async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { + await new permission().PermissionCreate(request,"SYS_REGISTRY_EMP"); if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) { throw new HttpError( HttpStatus.INTERNAL_SERVER_ERROR, @@ -630,6 +629,7 @@ export class ProfileEmployeeController extends Controller { @Path() id: string, @Body() body: UpdateProfileEmployee, ) { + await new permission().PermissionUpdate(request,"SYS_REGISTRY_EMP"); const exists = !!body.citizenId && (await this.profileRepo.findOne({ @@ -692,7 +692,8 @@ export class ProfileEmployeeController extends Controller { * @param {string} id Id ทะเบียนประวัติ */ @Delete("{id}") - async deleteProfile(@Path() id: string) { + async deleteProfile(@Path() id: string, @Request() request: RequestWithUser,) { + await new permission().PermissionDelete(request,"SYS_REGISTRY_EMP"); const result = await this.profileRepo.findOne({ where: { id: id } }); if (!result) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -989,6 +990,61 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess(formattedData); } + /** + * API ออกคำสั่งลูกจ้าง + * + * @summary ORG_038 - ออกคำสั่งลูกจ้าง (ADMIN) # + * + */ + @Get("report-temp") + async getReportTemp(@Request() request: RequestWithUser) { + const profiles = await this.profileRepo.find({ + where: { statusTemp: "REPORT", employeeClass: "TEMP" }, + }); + + if (!profiles) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const findRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: true }, + }); + if (!findRevision) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + } + + const formattedData = profiles.map((profile) => { + const shortName = + profile.child4Temp != null + ? `${profile.child4ShortNameTemp}${profile.posMasterNoTemp}` + : profile.child3Temp != null + ? `${profile.child3ShortNameTemp}${profile.posMasterNoTemp}` + : profile.child2Temp != null + ? `${profile.child2ShortNameTemp}${profile.posMasterNoTemp}` + : profile.child1Temp != null + ? `${profile.child1ShortNameTemp}${profile.posMasterNoTemp}` + : profile.rootIdTemp != null + ? `${profile.rootShortNameTemp}${profile.posMasterNoTemp}` + : null; + + return { + id: profile.id, + citizenId: profile.citizenId, + prefix: profile.prefix, + firstName: profile.firstName, + lastName: profile.lastName, + organization: profile.rootTemp, + positionName: profile.positionTemp, + positionType: profile.posTypeNameTemp, + positionLevel: profile.posLevelNameTemp, + positionNumber: shortName, + birthDate: profile.birthDate, + }; + }); + + return new HttpSuccess(formattedData); + } + /** * API รายละเอียดรายการทะเบียนประวัติ * @@ -2760,7 +2816,7 @@ export class ProfileEmployeeController extends Controller { profile.leaveReason = requestBody.leaveReason; profile.dateLeave = requestBody.dateLeave; if (requestBody.isLeave == true) { - await removeProfileInOrganize(profile.id,"EMPLOYEE"); + await removeProfileInOrganize(profile.id, "EMPLOYEE"); } await this.profileRepo.save(profile); @@ -3076,7 +3132,7 @@ export class ProfileEmployeeController extends Controller { }); if (profile != null) { await new CallAPI() - .PostData(request, "org/profile-employee/salary", { + .PostData(request, "/org/profile-employee/salary", { profileEmployeeId: profile.id, date: new Date(), amount: v.amount, @@ -3092,10 +3148,12 @@ export class ProfileEmployeeController extends Controller { .then(async (x) => { profile.statusTemp = "DONE"; profile.employeeClass = "PERM"; + const _null: any = null; + profile.employeeWage = v.amount == null ? _null : v.amount.toString(); await this.profileRepo.save(profile); }); await new CallAPI() - .PostData(request, "org/employee/pos/report/current", { + .PostData(request, "/org/employee/pos/report/current", { posmasterId: profile.posmasterIdTemp, positionId: profile.positionIdTemp, profileId: profile.id, diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index 8d3cda07..a5243916 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -25,6 +25,7 @@ import { } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/family/couple") @Tags("ProfileFamilyCouple") @Security("bearerAuth") @@ -219,6 +220,7 @@ export class ProfileFamilyCoupleController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileFamilyCouple, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); const familyCouple = Object.assign(new ProfileFamilyCouple(), body); if (!familyCouple) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -265,6 +267,7 @@ export class ProfileFamilyCoupleController extends Controller { @Body() body: UpdateProfileFamilyCouple, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId }); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileFamilyCoupleEmployeeController.ts b/src/controllers/ProfileFamilyCoupleEmployeeController.ts index 61c46dc6..66e3645d 100644 --- a/src/controllers/ProfileFamilyCoupleEmployeeController.ts +++ b/src/controllers/ProfileFamilyCoupleEmployeeController.ts @@ -21,6 +21,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileFamilyCouple, CreateProfileEmployeeFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/family/couple") @Tags("ProfileEmployeeFamilyCouple") @Security("bearerAuth") @@ -215,6 +216,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeFamilyCouple, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); const familyCouple = Object.assign(new ProfileFamilyCouple(), body); if (!familyCouple) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -261,6 +263,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { @Body() body: UpdateProfileFamilyCouple, @Path() profileEmployeeId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileEmployeeId: profileEmployeeId, }); diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index 56171677..a0860261 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -25,6 +25,7 @@ import { } from "../entities/ProfileFamilyFather"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/family/father") @Tags("ProfileFamilyFather") @Security("bearerAuth") @@ -205,6 +206,7 @@ export class ProfileFamilyFatherController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileFamilyFather, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); const familyFather = Object.assign(new ProfileFamilyFather(), body); if (!familyFather) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -245,6 +247,7 @@ export class ProfileFamilyFatherController extends Controller { @Body() body: UpdateProfileFamilyFather, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId }); if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileFamilyFatherEmployeeController.ts b/src/controllers/ProfileFamilyFatherEmployeeController.ts index 9135c51d..05f35848 100644 --- a/src/controllers/ProfileFamilyFatherEmployeeController.ts +++ b/src/controllers/ProfileFamilyFatherEmployeeController.ts @@ -25,6 +25,7 @@ import { } from "../entities/ProfileFamilyFather"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/family/father") @Tags("ProfileEmployeeFamilyFather") @Security("bearerAuth") @@ -205,6 +206,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeFamilyFather, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); const familyFather = Object.assign(new ProfileFamilyFather(), body); if (!familyFather) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -245,6 +247,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller { @Body() body: UpdateProfileFamilyFather, @Path() profileEmployeeId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const familyFather = await this.ProfileFamilyFather.findOneBy({ profileEmployeeId: profileEmployeeId, }); diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index 55acab88..798c60ef 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -25,6 +25,7 @@ import { } from "../entities/ProfileFamilyMother"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/family/mother") @Tags("ProfileFamilyMother") @Security("bearerAuth") @@ -205,6 +206,7 @@ export class ProfileFamilyMotherController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileFamilyMother, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); const familyMother = Object.assign(new ProfileFamilyMother(), body); if (!familyMother) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -245,6 +247,7 @@ export class ProfileFamilyMotherController extends Controller { @Body() body: UpdateProfileFamilyMother, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId }); if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); diff --git a/src/controllers/ProfileFamilyMotherEmployeeController.ts b/src/controllers/ProfileFamilyMotherEmployeeController.ts index 4b6325fb..ab922bd8 100644 --- a/src/controllers/ProfileFamilyMotherEmployeeController.ts +++ b/src/controllers/ProfileFamilyMotherEmployeeController.ts @@ -21,6 +21,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileFamilyMother, CreateProfileEmployeeFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import Extension from "../interfaces/extension"; +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/family/mother") @Tags("ProfileEmployeeFamilyMother") @Security("bearerAuth") @@ -201,6 +202,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeFamilyMother, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); const familyMother = Object.assign(new ProfileFamilyMother(), body); if (!familyMother) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -241,6 +243,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller { @Body() body: UpdateProfileFamilyMother, @Path() profileEmployeeId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const familyMother = await this.ProfileFamilyMother.findOneBy({ profileEmployeeId: profileEmployeeId, }); diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index fff540e3..cef1adbf 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -9,7 +9,7 @@ import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileG import { Position } from "../entities/Position"; import { PosMaster } from "../entities/PosMaster"; import { calculateAge, calculateRetireDate } from "../interfaces/utils"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/government") @Tags("ProfileGovernment") @Security("bearerAuth") @@ -293,6 +293,7 @@ export class ProfileGovernmentHistoryController extends Controller { @Body() body: UpdateProfileGovernment, @Path() profileId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.profileRepo.findOne({ where: { id: profileId }, }); diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 73c40045..7bb64f1c 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -26,7 +26,7 @@ import { import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { calculateAge, calculateRetireDate } from "../interfaces/utils"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/government") @Tags("ProfileEmployeeGovernment") @Security("bearerAuth") @@ -288,6 +288,7 @@ export class ProfileGovernmentEmployeeController extends Controller { @Body() body: UpdateProfileGovernment, @Path() profileEmployeeId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.profileEmployeeRepo.findOne({ where: { id: profileEmployeeId }, }); diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index 84b9b226..57a84874 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileHonorHistory } from "../entities/ProfileHonorHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/honor") @Tags("ProfileHonor") @Security("bearerAuth") @@ -138,6 +138,7 @@ export class ProfileHonorController extends Controller { @Post() public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -170,6 +171,7 @@ export class ProfileHonorController extends Controller { @Body() body: UpdateProfileHonor, @Path() honorId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.honorRepo.findOneBy({ id: honorId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -188,7 +190,8 @@ export class ProfileHonorController extends Controller { } @Delete("{honorId}") - public async deleteTraning(@Path() honorId: string) { + public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.honorHistoryRepo.delete({ profileHonorId: honorId, }); diff --git a/src/controllers/ProfileHonorEmployeeController.ts b/src/controllers/ProfileHonorEmployeeController.ts index a6b232ad..f5f211d4 100644 --- a/src/controllers/ProfileHonorEmployeeController.ts +++ b/src/controllers/ProfileHonorEmployeeController.ts @@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileHonorHistory } from "../entities/ProfileHonorHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/honor") @Tags("ProfileEmployeeHonor") @Security("bearerAuth") @@ -138,6 +138,7 @@ export class ProfileHonorEmployeeController extends Controller { @Post() public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -170,6 +171,7 @@ export class ProfileHonorEmployeeController extends Controller { @Body() body: UpdateProfileHonor, @Path() honorId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.honorRepo.findOneBy({ id: honorId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -188,7 +190,8 @@ export class ProfileHonorEmployeeController extends Controller { } @Delete("{honorId}") - public async deleteTraning(@Path() honorId: string) { + public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.honorHistoryRepo.delete({ profileHonorId: honorId, }); diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 7b71e203..82b5ce07 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -25,7 +25,7 @@ import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { Insignia } from "../entities/Insignia"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/insignia") @Tags("ProfileInsignia") @Security("bearerAuth") @@ -166,6 +166,7 @@ export class ProfileInsigniaController extends Controller { @Post() public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -205,6 +206,7 @@ export class ProfileInsigniaController extends Controller { @Body() body: UpdateProfileInsignia, @Path() insigniaId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -230,7 +232,8 @@ export class ProfileInsigniaController extends Controller { } @Delete("{insigniaId}") - public async deleteInsignia(@Path() insigniaId: string) { + public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.insigniaHistoryRepo.delete({ profileInsigniaId: insigniaId, }); diff --git a/src/controllers/ProfileInsigniaEmployeeController.ts b/src/controllers/ProfileInsigniaEmployeeController.ts index 6de21b7e..d59f1529 100644 --- a/src/controllers/ProfileInsigniaEmployeeController.ts +++ b/src/controllers/ProfileInsigniaEmployeeController.ts @@ -25,7 +25,7 @@ import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Insignia } from "../entities/Insignia"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/insignia") @Tags("ProfileEmployeeInsignia") @Security("bearerAuth") @@ -166,6 +166,7 @@ export class ProfileInsigniaEmployeeController extends Controller { @Post() public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeInsignia) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -205,6 +206,7 @@ export class ProfileInsigniaEmployeeController extends Controller { @Body() body: UpdateProfileInsignia, @Path() insigniaId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -230,7 +232,8 @@ export class ProfileInsigniaEmployeeController extends Controller { } @Delete("{insigniaId}") - public async deleteInsignia(@Path() insigniaId: string) { + public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.insigniaHistoryRepo.delete({ profileInsigniaId: insigniaId, }); diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 8ff61a61..0f9eea8b 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -22,12 +22,11 @@ import { import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; - import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { LeaveType } from "../entities/LeaveType"; import { Brackets } from "typeorm"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/leave") @Tags("ProfileLeave") @Security("bearerAuth") @@ -248,6 +247,7 @@ export class ProfileLeaveController extends Controller { @Post() public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -286,6 +286,7 @@ export class ProfileLeaveController extends Controller { @Body() body: UpdateProfileLeave, @Path() leaveId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.leaveRepo.findOneBy({ id: leaveId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -311,7 +312,8 @@ export class ProfileLeaveController extends Controller { } @Delete("{leaveId}") - public async deleteLeave(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileLeaveEmployeeController.ts b/src/controllers/ProfileLeaveEmployeeController.ts index 8f1716c9..5c3a314b 100644 --- a/src/controllers/ProfileLeaveEmployeeController.ts +++ b/src/controllers/ProfileLeaveEmployeeController.ts @@ -22,11 +22,10 @@ import { import HttpSuccess from "../interfaces/http-success"; import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; - import { RequestWithUser } from "../middlewares/user"; import { LeaveType } from "../entities/LeaveType"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/leave") @Tags("ProfileLeave") @Security("bearerAuth") @@ -69,6 +68,7 @@ export class ProfileLeaveEmployeeController extends Controller { @Post() public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -107,6 +107,7 @@ export class ProfileLeaveEmployeeController extends Controller { @Body() body: UpdateProfileLeave, @Path() leaveId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.leaveRepo.findOneBy({ id: leaveId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -132,7 +133,8 @@ export class ProfileLeaveEmployeeController extends Controller { } @Delete("{leaveId}") - public async deleteLeave(@Path() leaveId: string) { + public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.leaveHistoryRepo.delete({ profileLeaveId: leaveId, }); diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index c74b24d7..3475c911 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -20,7 +20,7 @@ import { ProfileNopaidHistory } from "../entities/ProfileNopaidHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/nopaid") @Tags("ProfileNopaid") @Security("bearerAuth") @@ -96,6 +96,7 @@ export class ProfileNopaidController extends Controller { @Post() public async newNopaid(@Request() req: RequestWithUser, @Body() body: CreateProfileNopaid) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -128,6 +129,7 @@ export class ProfileNopaidController extends Controller { @Body() body: UpdateProfileNopaid, @Path() nopaidId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -149,7 +151,8 @@ export class ProfileNopaidController extends Controller { } @Delete("{nopaidId}") - public async deleteNopaid(@Path() nopaidId: string) { + public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.nopaidHistoryRepository.delete({ profileNopaidId: nopaidId, }); diff --git a/src/controllers/ProfileNopaidEmployeeController.ts b/src/controllers/ProfileNopaidEmployeeController.ts index 8bda984d..26cc91fc 100644 --- a/src/controllers/ProfileNopaidEmployeeController.ts +++ b/src/controllers/ProfileNopaidEmployeeController.ts @@ -24,7 +24,7 @@ import { ProfileNopaid, UpdateProfileNopaid, } from "../entities/ProfileNopaid"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/nopaid") @Tags("ProfileNopaid") @Security("bearerAuth") @@ -67,6 +67,7 @@ export class ProfileNopaidEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeNopaid, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -99,6 +100,7 @@ export class ProfileNopaidEmployeeController extends Controller { @Body() body: UpdateProfileNopaid, @Path() nopaidId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -120,7 +122,8 @@ export class ProfileNopaidEmployeeController extends Controller { } @Delete("{nopaidId}") - public async deleteNopaid(@Path() nopaidId: string) { + public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.nopaidHistoryRepository.delete({ profileNopaidId: nopaidId, }); diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index 11a986ec..2575e926 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -20,7 +20,7 @@ import { ProfileOtherHistory } from "../entities/ProfileOtherHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/other") @Tags("ProfileOther") @Security("bearerAuth") @@ -93,6 +93,7 @@ export class ProfileOtherController extends Controller { @Post() public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileOther) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -125,6 +126,7 @@ export class ProfileOtherController extends Controller { @Body() body: UpdateProfileOther, @Path() otherId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.otherRepository.findOneBy({ id: otherId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -146,7 +148,8 @@ export class ProfileOtherController extends Controller { } @Delete("{otherId}") - public async deleteOther(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/controllers/ProfileOtherEmployeeController.ts b/src/controllers/ProfileOtherEmployeeController.ts index b04addf6..11eee382 100644 --- a/src/controllers/ProfileOtherEmployeeController.ts +++ b/src/controllers/ProfileOtherEmployeeController.ts @@ -24,7 +24,7 @@ import { ProfileOther, UpdateProfileOther, } from "../entities/ProfileOther"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/other") @Tags("ProfileOther") @Security("bearerAuth") @@ -64,6 +64,7 @@ export class ProfileOtherEmployeeController extends Controller { @Post() public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -96,6 +97,7 @@ export class ProfileOtherEmployeeController extends Controller { @Body() body: UpdateProfileOther, @Path() otherId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.otherRepository.findOneBy({ id: otherId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -117,7 +119,8 @@ export class ProfileOtherEmployeeController extends Controller { } @Delete("{otherId}") - public async deleteOther(@Path() otherId: string) { + public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.otherHistoryRepository.delete({ profileOtherId: otherId, }); diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index eb9c66a7..3a17eb17 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -21,7 +21,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; import { LessThan, MoreThan } from "typeorm"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -140,6 +140,7 @@ export class ProfileSalaryController extends Controller { @Post() public async newSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalary) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -178,6 +179,7 @@ export class ProfileSalaryController extends Controller { @Body() body: UpdateProfileSalary, @Path() salaryId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.salaryRepo.findOneBy({ id: salaryId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -196,7 +198,8 @@ export class ProfileSalaryController extends Controller { } @Delete("{salaryId}") - public async deleteSalary(@Path() salaryId: string) { + public async deleteSalary(@Path() salaryId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.salaryHistoryRepo.delete({ profileSalaryId: salaryId, }); diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 8f6c7237..58c0fe54 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -25,7 +25,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { LessThan, MoreThan } from "typeorm"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/salary") @Tags("ProfileSalary") @Security("bearerAuth") @@ -69,6 +69,7 @@ export class ProfileSalaryEmployeeController extends Controller { @Request() req: RequestWithUser, @Body() body: CreateProfileSalaryEmployee, ) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -107,6 +108,7 @@ export class ProfileSalaryEmployeeController extends Controller { @Body() body: UpdateProfileSalaryEmployee, @Path() salaryId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.salaryRepo.findOneBy({ id: salaryId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -125,7 +127,8 @@ export class ProfileSalaryEmployeeController extends Controller { } @Delete("{salaryId}") - public async deleteSalaryEmployee(@Path() salaryId: string) { + public async deleteSalaryEmployee(@Path() salaryId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.salaryHistoryRepo.delete({ profileSalaryId: salaryId, }); diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index 20de8cf8..eb34c688 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile/training") @Tags("ProfileTraining") @Security("bearerAuth") @@ -139,6 +139,7 @@ export class ProfileTrainingController extends Controller { @Post() public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) { + await new permission().PermissionCreate(req,"SYS_REGISTRY"); if (!body.profileId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); } @@ -171,6 +172,7 @@ export class ProfileTrainingController extends Controller { @Body() body: UpdateProfileTraining, @Path() trainingId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY"); const record = await this.trainingRepo.findOneBy({ id: trainingId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -189,7 +191,8 @@ export class ProfileTrainingController extends Controller { } @Delete("{trainingId}") - public async deleteTraining(@Path() trainingId: string) { + public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY"); await this.trainingHistoryRepo.delete({ profileTrainingId: trainingId, }); diff --git a/src/controllers/ProfileTrainingEmployeeController.ts b/src/controllers/ProfileTrainingEmployeeController.ts index e70cc2be..2df7aaf1 100644 --- a/src/controllers/ProfileTrainingEmployeeController.ts +++ b/src/controllers/ProfileTrainingEmployeeController.ts @@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error"; import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; - +import permission from "../interfaces/permission"; @Route("api/v1/org/profile-employee/training") @Tags("ProfileEmployeeTraining") @Security("bearerAuth") @@ -139,6 +139,7 @@ export class ProfileTrainingEmployeeController extends Controller { @Post() public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeTraining) { + await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP"); if (!body.profileEmployeeId) { throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); } @@ -171,6 +172,7 @@ export class ProfileTrainingEmployeeController extends Controller { @Body() body: UpdateProfileTraining, @Path() trainingId: string, ) { + await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP"); const record = await this.trainingRepo.findOneBy({ id: trainingId }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); @@ -189,7 +191,8 @@ export class ProfileTrainingEmployeeController extends Controller { } @Delete("{trainingId}") - public async deleteTraining(@Path() trainingId: string) { + public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) { + await new permission().PermissionDelete(req,"SYS_REGISTRY_EMP"); await this.trainingHistoryRepo.delete({ profileTrainingId: trainingId, }); diff --git a/src/entities/HR_EDUCATION.ts b/src/entities/HR_EDUCATION.ts index 64fe5602..0bf28924 100644 --- a/src/entities/HR_EDUCATION.ts +++ b/src/entities/HR_EDUCATION.ts @@ -32,12 +32,12 @@ export class HR_EDUCATION { }) EDUCATION_YEAR: string; - @Column({ - nullable: true, - type: "text", - default: null, - }) - EDUCATION_NAME: string; + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // EDUCATION_NAME: string; @Column({ nullable: true, diff --git a/src/entities/HR_EDUCATION_EMP.ts b/src/entities/HR_EDUCATION_EMP.ts index 7dc106d4..ea6f6e42 100644 --- a/src/entities/HR_EDUCATION_EMP.ts +++ b/src/entities/HR_EDUCATION_EMP.ts @@ -32,12 +32,12 @@ export class HR_EDUCATION_EMP { }) EDUCATION_YEAR: string; - @Column({ - nullable: true, - type: "text", - default: null, - }) - EDUCATION_NAME: string; + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // EDUCATION_NAME: string; @Column({ nullable: true, diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 5b44a91d..e6c256de 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -27,6 +27,25 @@ class Extension { } return null; } + public static ConvertToDateTimeV2(value: any) { + if (value != "" && value != null) { + if (value.toString().length > 4) { + const chars = value.split("/"); + let year = Number(chars[2]) + 1900; + let month = Extension.MonthToNumber(chars[1]); + return new Date(year, month, chars[0]); + } else { + if (value.toString().length == 4) { + if (value < 1800) { + return null; + } else if (value > 2500) { + return new Date(value - 543, 0, 1); + } + } + } + } + return null; + } public static CheckRelationship(value: any) { if (value != "" && value != null) { @@ -76,6 +95,36 @@ class Extension { return ""; } } + public static MonthToNumber(value: string) { + switch (value.trim().toUpperCase()) { + case "JAN": + return 0; + case "FEB": + return 1; + case "MAR": + return 2; + case "APR": + return 3; + case "MAY": + return 4; + case "JUN": + return 5; + case "JUL": + return 6; + case "AUG": + return 7; + case "SEP": + return 8; + case "OCT": + return 9; + case "NOV": + return 10; + case "DEC": + return 11; + default: + return 0; + } + } public static ToThaiShortMonth(value: number) { switch (value) { diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts new file mode 100644 index 00000000..74bb1de4 --- /dev/null +++ b/src/interfaces/permission.ts @@ -0,0 +1,58 @@ +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; +import { RequestWithUser } from "../middlewares/user"; +import CallAPI from "./call-api"; +import HttpError from "./http-error"; +import HttpStatus from "./http-status"; + +class CheckAuth { + public async Permission(req: RequestWithUser, system: string, action: string) { + await new CallAPI() + .GetData(req, "/org/permission") + .then((x) => { + let permission = false; + let role = x.roles.find((x: any) => x.authSysId == system); + if (!role) throw "ไม่มีสิทธิ์เข้าระบบ"; + if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate; + if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete; + if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet; + if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList; + if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate; + if (role.attrOwnership == "OWNER") permission = true; + if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้"; + return role.attrPrivilege; + }) + .catch((x) => { + throw new HttpError(HttpStatus.FORBIDDEN, x); + }); + } + public async PermissionCreate(req: RequestWithUser, system: string) { + this.Permission(req, system, "CREATE"); + } + public async PermissionDelete(req: RequestWithUser, system: string) { + this.Permission(req, system, "DELETE"); + } + public async PermissionGet(req: RequestWithUser, system: string) { + this.Permission(req, system, "GET"); + } + public async PermissionList(req: RequestWithUser, system: string) { + this.Permission(req, system, "LIST"); + } + public async PermissionUpdate(req: RequestWithUser, system: string) { + this.Permission(req, system, "UPDATE"); + } +} + +export default CheckAuth;