Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-08-09 10:18:12 +07:00
commit a91410dcdc
55 changed files with 971 additions and 292 deletions

View file

@ -101,6 +101,19 @@ export class AuthRoleController extends Controller {
posMaster.lastUpdateFullName = req.user.name; posMaster.lastUpdateFullName = req.user.name;
posMaster.authRoleId = body.authRoleId; posMaster.authRoleId = body.authRoleId;
await this.posMasterRepository.save(posMaster); 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(); return new HttpSuccess();
} }

View file

@ -4,14 +4,12 @@ import {
Post, Post,
Put, Put,
Delete, Delete,
Patch,
Route, Route,
Security, Security,
Tags, Tags,
Body, Body,
Path, Path,
Request, Request,
Example,
SuccessResponse, SuccessResponse,
Response, Response,
Query, Query,
@ -20,18 +18,18 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; 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 { RequestWithUser } from "../middlewares/user";
import { import {
ChangePosition, ChangePosition,
CreateChangePosition, CreateChangePosition,
UpdateChangePosition UpdateChangePosition,
} from "../entities/ChangePosition"; } from "../entities/ChangePosition";
import { import {
ProfileChangePosition, ProfileChangePosition,
CreateProfileChangePosition, CreateProfileChangePosition,
UpdateProfileChangePosition, UpdateProfileChangePosition,
SelectProfileChangePosition SelectProfileChangePosition,
} from "../entities/ProfileChangePosition"; } from "../entities/ProfileChangePosition";
import { OrgRoot } from "../entities/OrgRoot"; import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild1 } from "../entities/OrgChild1"; import { OrgChild1 } from "../entities/OrgChild1";
@ -70,7 +68,7 @@ export class ChangePositionController extends Controller {
const _changePosition = await this.changePositionRepository.findOne({ const _changePosition = await this.changePositionRepository.findOne({
where: { name: body.name }, where: { name: body.name },
}); });
if(_changePosition){ if (_changePosition) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
@ -79,9 +77,9 @@ export class ChangePositionController extends Controller {
const changePosition = new ChangePosition(); const changePosition = new ChangePosition();
Object.assign(changePosition, body); Object.assign(changePosition, body);
changePosition.date = new Date, (changePosition.date = new Date()),
changePosition.status = "WAITTING", (changePosition.status = "WAITTING"),
changePosition.createdUserId = request.user.sub; (changePosition.createdUserId = request.user.sub);
changePosition.createdFullName = request.user.name; changePosition.createdFullName = request.user.name;
changePosition.lastUpdateUserId = request.user.sub; changePosition.lastUpdateUserId = request.user.sub;
changePosition.lastUpdateFullName = request.user.name; changePosition.lastUpdateFullName = request.user.name;
@ -126,17 +124,17 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateChangePosition, @Body() body: UpdateChangePosition,
) { ) {
const changePosition = await this.changePositionRepository.findOneBy({ id }); 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({ const checkDuplicate = await this.changePositionRepository.find({
where: { where: {
id: Not(id), id: Not(id),
name: body.name name: body.name,
}, },
}); });
if(checkDuplicate.length > 0){ if (checkDuplicate.length > 0) {
throw new HttpError( throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว", "ชื่อรอบการย้ายสับเปลี่ยนตำแหน่งนี้มีอยู่ในระบบแล้ว",
@ -168,7 +166,7 @@ export class ChangePositionController extends Controller {
searchKeyword searchKeyword
? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword" ? "changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword"
: "1=1", : "1=1",
{ keyword: `%${searchKeyword}%` } { keyword: `%${searchKeyword}%` },
) )
.orderBy("changePosition.date", "ASC") .orderBy("changePosition.date", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
@ -190,9 +188,9 @@ export class ChangePositionController extends Controller {
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { where: {
profileChangePosition: { profileChangePosition: {
status: "PENDING" status: "PENDING",
} },
} },
}); });
return new HttpSuccess(profiles); return new HttpSuccess(profiles);
} }
@ -205,12 +203,11 @@ export class ChangePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{id}")
async GetChangePositionById( @Path() id: string ) { async GetChangePositionById(@Path() id: string) {
const data = await this.changePositionRepository.findOne({ const data = await this.changePositionRepository.findOne({
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { id: id }} where: { id: id },
); });
if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง"); if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
return new HttpSuccess(data); return new HttpSuccess(data);
} }
@ -229,18 +226,19 @@ export class ChangePositionController extends Controller {
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
const changePosition = await this.changePositionRepository.findOneBy({ id: changePositionId }); 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 profileChangePositions: ProfileChangePosition[] = [];
const profiles = new ProfileChangePosition(); const profiles = new ProfileChangePosition();
for (const data of body.profiles) { for (const data of body.profiles) {
Object.assign(profiles, data); Object.assign(profiles, data);
let positionOld = data.positionOld ? `${data.positionOld}` : ""; 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.changePositionId = changePositionId;
profiles.organizationPositionOld = `${positionOld}${rootOld}`, (profiles.organizationPositionOld = `${positionOld}${rootOld}`),
profiles.status = "WAITTING", (profiles.status = "WAITTING"),
profiles.createdUserId = request.user.sub; (profiles.createdUserId = request.user.sub);
profiles.createdFullName = request.user.name; profiles.createdFullName = request.user.name;
profiles.lastUpdateUserId = request.user.sub; profiles.lastUpdateUserId = request.user.sub;
profiles.lastUpdateFullName = request.user.name; profiles.lastUpdateFullName = request.user.name;
@ -279,7 +277,6 @@ export class ChangePositionController extends Controller {
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query() searchKeyword: string = "", @Query() searchKeyword: string = "",
) { ) {
const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition) const [profileChangePosition, total] = await AppDataSource.getRepository(ProfileChangePosition)
.createQueryBuilder("profileChangePosition") .createQueryBuilder("profileChangePosition")
@ -341,7 +338,7 @@ export class ChangePositionController extends Controller {
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, },
) );
}), }),
) )
.orderBy("profileChangePosition.createdAt", "ASC") .orderBy("profileChangePosition.createdAt", "ASC")
@ -360,13 +357,15 @@ export class ChangePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("profile/{id}") @Get("profile/{id}")
async GetProfileChangePositionById( async GetProfileChangePositionById(@Path() id: string) {
@Path() id: string
) {
const profileChangePos = await this.profileChangePositionRepository.findOne({ 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); return new HttpSuccess(profileChangePos);
} }
@ -383,9 +382,12 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateProfileChangePosition, @Body() body: UpdateProfileChangePosition,
) { ) {
const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); 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.lastUpdateUserId = request.user.sub;
profileChangePos.lastUpdateFullName = request.user.name; profileChangePos.lastUpdateFullName = request.user.name;
@ -395,7 +397,7 @@ export class ChangePositionController extends Controller {
profileChangePos.positionLevelOld = body.positionLevelOld; profileChangePos.positionLevelOld = body.positionLevelOld;
profileChangePos.organizationPositionOld = body.organizationPositionOld; profileChangePos.organizationPositionOld = body.organizationPositionOld;
profileChangePos.amountOld = body.amountOld; profileChangePos.amountOld = body.amountOld;
profileChangePos.reason = body.reason? String(body.reason) : ""; profileChangePos.reason = body.reason ? String(body.reason) : "";
profileChangePos.dateCurrent = body.dateCurrent; profileChangePos.dateCurrent = body.dateCurrent;
await this.profileChangePositionRepository.save(profileChangePos); await this.profileChangePositionRepository.save(profileChangePos);
return new HttpSuccess(); return new HttpSuccess();
@ -414,9 +416,12 @@ export class ChangePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: SelectProfileChangePosition, @Body() body: SelectProfileChangePosition,
) { ) {
const profileChangePos = await this.profileChangePositionRepository.findOneBy({ id }); 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) { switch (body.node) {
case 0: { case 0: {
@ -507,18 +512,18 @@ export class ChangePositionController extends Controller {
profileChangePos.lastUpdateUserId = request.user.sub; profileChangePos.lastUpdateUserId = request.user.sub;
profileChangePos.lastUpdateFullName = request.user.name; profileChangePos.lastUpdateFullName = request.user.name;
profileChangePos.node = body.node; profileChangePos.node = body.node;
profileChangePos.nodeId = body.nodeId; profileChangePos.nodeId = body.nodeId;
profileChangePos.orgRevisionId = body.orgRevisionId; profileChangePos.orgRevisionId = body.orgRevisionId;
profileChangePos.posmasterId = body.posmasterId; profileChangePos.posmasterId = body.posmasterId;
profileChangePos.posMasterNo = body.posMasterNo; profileChangePos.posMasterNo = body.posMasterNo;
profileChangePos.positionId = body.positionId; profileChangePos.positionId = body.positionId;
profileChangePos.position = body.position; profileChangePos.position = body.position;
profileChangePos.positionField = body.positionField; profileChangePos.positionField = body.positionField;
profileChangePos.posTypeId = String(body.posTypeId); profileChangePos.posTypeId = String(body.posTypeId);
profileChangePos.posTypeName = body.posTypeName; profileChangePos.posTypeName = body.posTypeName;
profileChangePos.posLevelId = String(body.posLevelId); profileChangePos.posLevelId = String(body.posLevelId);
profileChangePos.posLevelName = body.posLevelName; profileChangePos.posLevelName = body.posLevelName;
profileChangePos.status = "PENDING"; profileChangePos.status = "PENDING";
await this.profileChangePositionRepository.save(profileChangePos); await this.profileChangePositionRepository.save(profileChangePos);
return new HttpSuccess(); return new HttpSuccess();
@ -534,24 +539,24 @@ export class ChangePositionController extends Controller {
async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) { async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) {
const profilechangePositions = await this.changePositionRepository.find({ const profilechangePositions = await this.changePositionRepository.find({
relations: ["profileChangePosition"], relations: ["profileChangePosition"],
where: { id: In(requestBody.id) } where: { id: In(requestBody.id) },
}); });
for (const item of profilechangePositions) { for (const item of profilechangePositions) {
item.status = "REPORT"; item.status = "REPORT";
item.lastUpdateUserId = request.user.sub; item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name; item.lastUpdateFullName = request.user.name;
if (item.profileChangePosition) { if (item.profileChangePosition) {
for (const profile of item.profileChangePosition) { for (const profile of item.profileChangePosition) {
profile.status = "REPORT"; profile.status = "REPORT";
profile.lastUpdateUserId = request.user.sub; profile.lastUpdateUserId = request.user.sub;
profile.lastUpdateFullName = request.user.name; profile.lastUpdateFullName = request.user.name;
await this.profileChangePositionRepository.save(profile); 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( await Promise.all(
body.result.map(async (v) => { body.result.map(async (v) => {
const profile = await this.profileChangePositionRepository.findOne({ const profile = await this.profileChangePositionRepository.findOne({
where: { id: v.id } where: { id: v.id },
}); });
if (profile != null) { if (profile != null) {
await new CallAPI() await new CallAPI()
.PostData(request, "org/profile/salary", { .PostData(request, "/org/profile/salary", {
profileId: profile.id, profileId: profile.id,
date: new Date(), date: new Date(),
}) })

View file

@ -2188,6 +2188,7 @@ export class EmployeePositionController extends Controller {
) { ) {
const posMaster = await this.employeePosMasterRepository.findOne({ const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: body.posmasterId }, where: { id: body.posmasterId },
relations: ["orgRoot"],
}); });
if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); if (posMaster == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
@ -2244,9 +2245,14 @@ export class EmployeePositionController extends Controller {
}); });
if (positionNew != null) { if (positionNew != null) {
positionNew.positionIsSelected = true; positionNew.positionIsSelected = true;
profile.posLevel = positionNew.posLevel; profile.posLevelId = positionNew.posLevelId;
profile.posType = positionNew.posType; profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName; 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.profileRepository.save(profile);
await this.employeePositionRepository.save(positionNew); await this.employeePositionRepository.save(positionNew);
} }

View file

@ -14,7 +14,7 @@ import {
UploadedFile, UploadedFile,
} from "tsoa"; } from "tsoa";
import { AppDataSource } from "../database/data-source"; 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 HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
@ -315,7 +315,7 @@ export class ImportDataController extends Controller {
rowCount++; rowCount++;
const profileSalary = new ProfileSalary(); const profileSalary = new ProfileSalary();
profileSalary.date = 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 = const SALARY: any =
item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY);
profileSalary.amount = SALARY; profileSalary.amount = SALARY;
@ -336,19 +336,20 @@ export class ImportDataController extends Controller {
profileSalary.createdFullName = request.user.name; profileSalary.createdFullName = request.user.name;
profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateUserId = request.user.sub;
profileSalary.lastUpdateFullName = request.user.name; profileSalary.lastUpdateFullName = request.user.name;
profileSalarys.push(profileSalary); // profileSalarys.push(profileSalary);
// await this.salaryRepository.save(profileSalary); // await this.salaryRepository.save(profileSalary);
if (profileSalarys.length === BATCH_SIZE) { // if (profileSalarys.length === BATCH_SIZE) {
await this.salaryRepository.save(profileSalarys); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
profileSalarys = await []; await this.salaryRepository.save(profileSalary);
} // profileSalarys = await [];
// }
}), }),
); );
// await this.salaryRepository.save(profileSalarys); // await this.salaryRepository.save(profileSalarys);
// profileSalarys = await []; // profileSalarys = await [];
}), }),
); );
await this.salaryRepository.save(profileSalarys); // await this.salaryRepository.save(profileSalarys);
// } // }
console.log(rowCount); console.log(rowCount);
return new HttpSuccess(); return new HttpSuccess();
@ -406,7 +407,7 @@ export class ImportDataController extends Controller {
const profileSalary = new ProfileSalary(); const profileSalary = new ProfileSalary();
profileSalary.date = 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 = const SALARY: any =
item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY);
profileSalary.amount = SALARY; profileSalary.amount = SALARY;
@ -427,13 +428,13 @@ export class ImportDataController extends Controller {
profileSalary.createdFullName = request.user.name; profileSalary.createdFullName = request.user.name;
profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateUserId = request.user.sub;
profileSalary.lastUpdateFullName = request.user.name; profileSalary.lastUpdateFullName = request.user.name;
profileSalarys.push(profileSalary); // profileSalarys.push(profileSalary);
// await this.salaryRepository.save(profileSalary); // await this.salaryRepository.save(profileSalary);
if (profileSalarys.length === BATCH_SIZE) { // if (profileSalarys.length === BATCH_SIZE) {
await this.salaryRepository.save(profileSalarys);
profileSalarys = await [];
}
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.salaryRepository.save(profileSalary);
// profileSalarys = await [];
// }
}), }),
); );
// await this.salaryRepository.save(profileSalarys); // 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); console.log(rowCount);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -523,7 +524,16 @@ export class ImportDataController extends Controller {
profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME;
profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME;
profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; 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.coupleLive = existingProfile.LIFE_SPOUSE;
profileCouple.createdUserId = request.user.sub; profileCouple.createdUserId = request.user.sub;
profileCouple.createdFullName = request.user.name; profileCouple.createdFullName = request.user.name;
@ -550,7 +560,7 @@ export class ImportDataController extends Controller {
}), }),
); );
// } // }
console.log(rowCount); // console.log(rowCount);
// await Promise.all([ // await Promise.all([
// this.profileFamilyFatherRepository.save(fathers), // this.profileFamilyFatherRepository.save(fathers),
@ -638,7 +648,16 @@ export class ImportDataController extends Controller {
profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME;
profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME;
profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; 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.coupleLive = existingProfile.LIFE_SPOUSE;
profileCouple.createdUserId = request.user.sub; profileCouple.createdUserId = request.user.sub;
profileCouple.createdFullName = request.user.name; profileCouple.createdFullName = request.user.name;
@ -665,7 +684,7 @@ export class ImportDataController extends Controller {
}), }),
); );
// } // }
console.log(rowCount); // console.log(rowCount);
// await Promise.all([ // await Promise.all([
// this.profileFamilyFatherRepository.save(fathers), // this.profileFamilyFatherRepository.save(fathers),
@ -749,14 +768,14 @@ export class ImportDataController extends Controller {
}); });
let startDate = item.START_EDUCATION_YEAR let startDate = item.START_EDUCATION_YEAR
? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR)
: null_; : null_;
startDate = startDate ? new Date(startDate, 0, 1) : null_; // startDate = startDate ? new Date(startDate, 0, 1) : null_;
let endDate = item.EDUCATION_YEAR let endDate = item.EDUCATION_YEAR
? Extension.ConvertToDateTime(item.EDUCATION_YEAR) ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR)
: null_; : null_;
endDate = endDate ? new Date(endDate, 0, 1) : null_; // endDate = endDate ? new Date(endDate, 0, 1) : null_;
education.profileId = _item.id; education.profileId = _item.id;
education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
@ -768,6 +787,7 @@ export class ImportDataController extends Controller {
education.lastUpdateUserId = request.user.sub; education.lastUpdateUserId = request.user.sub;
education.lastUpdateFullName = request.user.name; education.lastUpdateFullName = request.user.name;
// await educations.push(await education); // await educations.push(await education);
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.educationRepository.save(await education); 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); // await this.educationRepository.save(educations);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -822,14 +842,14 @@ export class ImportDataController extends Controller {
}); });
let startDate = item.START_EDUCATION_YEAR let startDate = item.START_EDUCATION_YEAR
? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR)
: null_; : null_;
startDate = startDate ? new Date(startDate, 0, 1) : null_; // startDate = startDate ? new Date(startDate, 0, 1) : null_;
let endDate = item.EDUCATION_YEAR let endDate = item.EDUCATION_YEAR
? Extension.ConvertToDateTime(item.EDUCATION_YEAR) ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR)
: null_; : null_;
endDate = endDate ? new Date(endDate, 0, 1) : null_; // endDate = endDate ? new Date(endDate, 0, 1) : null_;
education.profileEmployeeId = _item.id; education.profileEmployeeId = _item.id;
education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
@ -840,14 +860,16 @@ export class ImportDataController extends Controller {
education.createdFullName = request.user.name; education.createdFullName = request.user.name;
education.lastUpdateUserId = request.user.sub; education.lastUpdateUserId = request.user.sub;
education.lastUpdateFullName = request.user.name; 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); // await this.educationRepository.save(educations);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -1086,15 +1108,18 @@ export class ImportDataController extends Controller {
_item.registrationZipCode = existingProfile.ZIPCODE; _item.registrationZipCode = existingProfile.ZIPCODE;
_item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentAddress = existingProfile.CONTACT_H_NUMBER;
_item.currentZipCode = existingProfile.CONTACT_ZIPCODE; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE;
_item.createdUserId = request.user.sub;
_item.createdFullName = request.user.name;
_item.lastUpdateUserId = request.user.sub; _item.lastUpdateUserId = request.user.sub;
_item.lastUpdateFullName = request.user.name; _item.lastUpdateFullName = request.user.name;
// profileDatas.push(_item); // profileDatas.push(_item);
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.profileRepo.save(_item); await this.profileRepo.save(_item);
}), }),
); );
// await this.profileRepo.save(profileDatas); // await this.profileRepo.save(profileDatas);
// } // }
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -1152,7 +1177,7 @@ export class ImportDataController extends Controller {
_item.registrationProvinceId = provinceId ? provinceId.id : null_; _item.registrationProvinceId = provinceId ? provinceId.id : null_;
} }
} }
if (existingProfile.AMPHUR_CODE) { if (existingProfile.AMPHUR_CODE && provinceRegis_) {
districtRegis_ = await this.amphurRepo.findOne({ districtRegis_ = await this.amphurRepo.findOne({
where: { where: {
AMPHUR_CODE: existingProfile.AMPHUR_CODE, AMPHUR_CODE: existingProfile.AMPHUR_CODE,
@ -1168,7 +1193,7 @@ export class ImportDataController extends Controller {
_item.registrationDistrictId = districtId ? districtId.id : null_; _item.registrationDistrictId = districtId ? districtId.id : null_;
} }
} }
if (existingProfile.DISTRICT_CODE) { if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) {
subDistrictRegis_ = await this.subDistrictRepo.findOne({ subDistrictRegis_ = await this.subDistrictRepo.findOne({
where: { where: {
DISTRICT_CODE: existingProfile.DISTRICT_CODE, DISTRICT_CODE: existingProfile.DISTRICT_CODE,
@ -1199,7 +1224,7 @@ export class ImportDataController extends Controller {
_item.currentProvinceId = provinceId ? provinceId.id : null_; _item.currentProvinceId = provinceId ? provinceId.id : null_;
} }
} }
if (existingProfile.CONTACT_AMPHUR_CODE) { if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) {
districtCurr_ = await this.amphurRepo.findOne({ districtCurr_ = await this.amphurRepo.findOne({
where: { where: {
AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE,
@ -1215,7 +1240,7 @@ export class ImportDataController extends Controller {
_item.currentDistrictId = districtId ? districtId.id : null_; _item.currentDistrictId = districtId ? districtId.id : null_;
} }
} }
if (existingProfile.CONTACT_DISTRICT_CODE) { if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) {
subDistrictCurr_ = await this.subDistrictRepo.findOne({ subDistrictCurr_ = await this.subDistrictRepo.findOne({
where: { where: {
DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE,
@ -1236,15 +1261,79 @@ export class ImportDataController extends Controller {
_item.registrationZipCode = existingProfile.ZIPCODE; _item.registrationZipCode = existingProfile.ZIPCODE;
_item.currentAddress = existingProfile.CONTACT_H_NUMBER; _item.currentAddress = existingProfile.CONTACT_H_NUMBER;
_item.currentZipCode = existingProfile.CONTACT_ZIPCODE; _item.currentZipCode = existingProfile.CONTACT_ZIPCODE;
_item.createdUserId = request.user.sub;
_item.createdFullName = request.user.name;
_item.lastUpdateUserId = request.user.sub; _item.lastUpdateUserId = request.user.sub;
_item.lastUpdateFullName = request.user.name; _item.lastUpdateFullName = request.user.name;
// profileDatas.push(_item); // profileDatas.push(_item);
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
await this.profileEmpRepo.save(_item); await this.profileEmpRepo.save(_item);
}), }),
); );
// await this.profileEmpRepo.save(profileDatas); // await this.profileEmpRepo.save(profileDatas);
// } // }
console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount);
return new HttpSuccess();
}
/**
* @summary
*/
@Post("cleardataupload")
async ClearDataUpload(@Request() request: { user: Record<string, any> }) {
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(); return new HttpSuccess();
} }
} }

View file

@ -3,23 +3,19 @@ import {
Get, Get,
Post, Post,
Put, Put,
Delete,
Patch,
Route, Route,
Security, Security,
Tags, Tags,
Body, Body,
Path, Path,
Request, Request,
Example,
SuccessResponse, SuccessResponse,
Response, Response,
Query,
} from "tsoa"; } from "tsoa";
import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision"; import { CreateOrgRevision, OrgRevision } from "../entities/OrgRevision";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1"; import { OrgChild1 } from "../entities/OrgChild1";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import { In, IsNull, Not } from "typeorm"; import { In, IsNull, Not } from "typeorm";
@ -29,7 +25,6 @@ import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4"; import { OrgChild4 } from "../entities/OrgChild4";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { log } from "console";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import { ProfileSalary } from "../entities/ProfileSalary"; import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
@ -1680,7 +1675,7 @@ export class OrganizationController extends Controller {
: item != null && item?.orgRoot != null : item != null && item?.orgRoot != null
? `${item.orgRoot.orgRootShortName}${item.posMasterNo}` ? `${item.orgRoot.orgRootShortName}${item.posMasterNo}`
: null; : null;
await new CallAPI().PostData(request, "org/profile/salary", { await new CallAPI().PostData(request, "/org/profile/salary", {
profileId: item.next_holderId, profileId: item.next_holderId,
date: new Date(), date: new Date(),
amount: profileSalary?.amount ?? null, amount: profileSalary?.amount ?? null,
@ -1750,6 +1745,281 @@ export class OrganizationController extends Controller {
return new HttpSuccess(); 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 * API Organizational StructChart
* *
@ -3441,15 +3711,15 @@ export class OrganizationController extends Controller {
}); });
if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
const posMaster = await this.posMasterRepository.find({ 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"], relations: ["current_holder"],
}); });
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง"); if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
const maps = posMaster.map((posMaster) => ({ const maps = posMaster.map((posMaster) => ({
id: posMaster.current_holder.id, id: posMaster?.current_holder?.id,
name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`, name: `${posMaster?.current_holder?.prefix}${posMaster?.current_holder?.firstName} ${posMaster?.current_holder?.lastName}`,
positionName: posMaster.current_holder.position, positionName: posMaster?.current_holder?.position,
})); }));
return new HttpSuccess(maps); return new HttpSuccess(maps);

View file

@ -35,54 +35,60 @@ export class PermissionController extends Controller {
const getAsync = promisify(redisClient.get).bind(redisClient); const getAsync = promisify(redisClient.get).bind(redisClient);
let reply = await getAsync("role_" + request.user.sub); let reply = await getAsync("role_" + request.user.sub);
// if (reply != null) { if (reply != null) {
// reply = JSON.parse(reply); reply = JSON.parse(reply);
// } else { } else {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
select: ["id"], select: ["id"],
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); 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); return new HttpSuccess(reply);
} }
@ -98,7 +104,6 @@ export class PermissionController extends Controller {
if (reply != null) { if (reply != null) {
reply = JSON.parse(reply); reply = JSON.parse(reply);
} else { } else {
console.log(request.user.sub);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
select: ["id"], select: ["id"],
where: { keycloak: request.user.sub }, where: { keycloak: request.user.sub },
@ -137,23 +142,36 @@ export class PermissionController extends Controller {
const getList = await this.authSysRepo.find({ const getList = await this.authSysRepo.find({
select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"], select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"],
where: { where: [
id: In(sysId), {
}, id: In(sysId),
},
{
parentId: In(sysId),
},
],
}); });
const reply = getList reply = await getList
.filter((x) => x.parentId == null) .filter((x) => x.parentId == null)
.sort((a, b) => a.order - b.order)
.map((item) => { .map((item) => {
return { return {
...item, ...item,
children: getList children: getList
.filter((x) => x.parentId == item.id) .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)); redisClient.setex("menu_" + request.user.sub, 86400, JSON.stringify(reply));
} }

View file

@ -3417,8 +3417,8 @@ export class PositionController extends Controller {
}); });
if (positionNew != null) { if (positionNew != null) {
positionNew.positionIsSelected = true; positionNew.positionIsSelected = true;
profile.posLevel = positionNew.posLevel; profile.posLevelId = positionNew.posLevelId;
profile.posType = positionNew.posType; profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName; profile.position = positionNew.positionName;
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew); await this.positionRepository.save(positionNew);

View file

@ -24,7 +24,7 @@ import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/ability") @Route("api/v1/org/profile/ability")
@Tags("ProfileAbility") @Tags("ProfileAbility")
@Security("bearerAuth") @Security("bearerAuth")
@ -133,6 +133,7 @@ export class ProfileAbilityController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileAbility, @Body() body: CreateProfileAbility,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -163,6 +164,7 @@ export class ProfileAbilityController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() abilityId: string, @Path() abilityId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -184,7 +186,8 @@ export class ProfileAbilityController extends Controller {
} }
@Delete("{abilityId}") @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({ await this.profileAbilityHistoryRepo.delete({
profileAbilityId: abilityId, profileAbilityId: abilityId,
}); });

View file

@ -26,7 +26,7 @@ import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/ability") @Route("api/v1/org/profile-employee/ability")
@Tags("ProfileAbilityEmployee") @Tags("ProfileAbilityEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -136,6 +136,7 @@ export class ProfileAbilityEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileAbilityEmployee, @Body() body: CreateProfileAbilityEmployee,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -166,6 +167,7 @@ export class ProfileAbilityEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() abilityId: string, @Path() abilityId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -187,7 +189,8 @@ export class ProfileAbilityEmployeeController extends Controller {
} }
@Delete("{abilityId}") @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({ await this.profileAbilityHistoryRepo.delete({
profileAbilityId: abilityId, profileAbilityId: abilityId,
}); });

View file

@ -26,7 +26,7 @@ import { AppDataSource } from "../database/data-source";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/address") @Route("api/v1/org/profile/address")
@Tags("ProfileAddress") @Tags("ProfileAddress")
@Security("bearerAuth") @Security("bearerAuth")
@ -182,6 +182,7 @@ export class ProfileAddressController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.profileRepo.findOneBy({ id: profileId }); const record = await this.profileRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -27,7 +27,7 @@ import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/address") @Route("api/v1/org/profile-employee/address")
@Tags("ProfileAddressEmployee") @Tags("ProfileAddressEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -183,6 +183,7 @@ export class ProfileAddressEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId }); const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -19,7 +19,6 @@ import {
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { import {
CreateProfileAssessment, CreateProfileAssessment,
@ -29,7 +28,7 @@ import {
import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory"; import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/assessments") @Route("api/v1/org/profile/assessments")
@Tags("ProfileAssessments") @Tags("ProfileAssessments")
@Security("bearerAuth") @Security("bearerAuth")
@ -147,6 +146,7 @@ export class ProfileAssessmentsController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileAssessment, @Body() body: CreateProfileAssessment,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -176,6 +176,7 @@ export class ProfileAssessmentsController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() assessmentId: string, @Path() assessmentId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -196,7 +197,8 @@ export class ProfileAssessmentsController extends Controller {
} }
@Delete("{assessmentId}") @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({ await this.profileAssessmentsHistoryRepository.delete({
profileAssessmentId: assessmentId, profileAssessmentId: assessmentId,
}); });

View file

@ -19,7 +19,6 @@ import {
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { import {
CreateProfileEmployeeAssessment, CreateProfileEmployeeAssessment,
@ -29,7 +28,7 @@ import {
import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory"; import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/assessments") @Route("api/v1/org/profile-employee/assessments")
@Tags("ProfileEmployeeAssessments") @Tags("ProfileEmployeeAssessments")
@Security("bearerAuth") @Security("bearerAuth")
@ -149,6 +148,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAssessment, @Body() body: CreateProfileEmployeeAssessment,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -178,6 +178,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() assessmentId: string, @Path() assessmentId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -198,7 +199,8 @@ export class ProfileAssessmentsEmployeeController extends Controller {
} }
@Delete("{assessmentId}") @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({ await this.profileAssessmentsHistoryRepository.delete({
profileAssessmentId: assessmentId, profileAssessmentId: assessmentId,
}); });

View file

@ -6,7 +6,7 @@ import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; import { CreateProfileAvatar, ProfileAvatar } from "../entities/ProfileAvatar";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/avatar") @Route("api/v1/org/profile/avatar")
@Tags("ProfileAvatar") @Tags("ProfileAvatar")
@Security("bearerAuth") @Security("bearerAuth")
@ -63,6 +63,7 @@ export class ProfileAvatarController extends Controller {
@Post() @Post()
public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) { public async newAvatar(@Request() req: RequestWithUser, @Body() body: CreateProfileAvatar) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
where: { id: body.profileId }, where: { id: body.profileId },
}); });
@ -113,7 +114,8 @@ export class ProfileAvatarController extends Controller {
} }
@Delete("{avatarId}") @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 }); const result = await this.avatarRepository.delete({ id: avatarId });
if (result.affected == undefined || result.affected <= 0) { if (result.affected == undefined || result.affected <= 0) {

View file

@ -6,7 +6,7 @@ import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileAvatar"; import { CreateProfileEmployeeAvatar, ProfileAvatar } from "../entities/ProfileAvatar";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/avatar") @Route("api/v1/org/profile-employee/avatar")
@Tags("ProfileAvatar") @Tags("ProfileAvatar")
@Security("bearerAuth") @Security("bearerAuth")
@ -54,6 +54,7 @@ export class ProfileAvatarEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAvatar, @Body() body: CreateProfileEmployeeAvatar,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
where: { id: body.profileEmployeeId }, where: { id: body.profileEmployeeId },
}); });
@ -104,7 +105,8 @@ export class ProfileAvatarEmployeeController extends Controller {
} }
@Delete("{avatarId}") @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 }); const result = await this.avatarRepository.delete({ id: avatarId });
if (result.affected == undefined || result.affected <= 0) { if (result.affected == undefined || result.affected <= 0) {

View file

@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/certificate") @Route("api/v1/org/profile/certificate")
@Tags("ProfileCertificate") @Tags("ProfileCertificate")
@Security("bearerAuth") @Security("bearerAuth")
@ -122,6 +122,7 @@ export class ProfileCertificateController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileCertificate, @Body() body: CreateProfileCertificate,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -154,6 +155,7 @@ export class ProfileCertificateController extends Controller {
@Body() body: UpdateProfileCertificate, @Body() body: UpdateProfileCertificate,
@Path() certificateId: string, @Path() certificateId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.certificateRepo.findOneBy({ id: certificateId }); const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -175,7 +177,8 @@ export class ProfileCertificateController extends Controller {
} }
@Delete("{certificateId}") @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({ await this.certificateHistoryRepo.delete({
profileCertificateId: certificateId, profileCertificateId: certificateId,
}); });

View file

@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/certificate") @Route("api/v1/org/profile-employee/certificate")
@Tags("ProfileEmployeeCertificate") @Tags("ProfileEmployeeCertificate")
@Security("bearerAuth") @Security("bearerAuth")
@ -121,6 +121,7 @@ export class ProfileCertificateEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeCertificate, @Body() body: CreateProfileEmployeeCertificate,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -153,6 +154,7 @@ export class ProfileCertificateEmployeeController extends Controller {
@Body() body: UpdateProfileCertificate, @Body() body: UpdateProfileCertificate,
@Path() certificateId: string, @Path() certificateId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.certificateRepo.findOneBy({ id: certificateId }); const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -174,7 +176,8 @@ export class ProfileCertificateEmployeeController extends Controller {
} }
@Delete("{certificateId}") @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({ await this.certificateHistoryRepo.delete({
profileCertificateId: certificateId, profileCertificateId: certificateId,
}); });

View file

@ -26,7 +26,7 @@ import {
} from "../entities/ProfileChangeName"; } from "../entities/ProfileChangeName";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import { updateName } from "../keycloak"; import { updateName } from "../keycloak";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/changeName") @Route("api/v1/org/profile/changeName")
@Tags("ProfileChangeName") @Tags("ProfileChangeName")
@Security("bearerAuth") @Security("bearerAuth")
@ -119,6 +119,7 @@ export class ProfileChangeNameController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileChangeName, @Body() body: CreateProfileChangeName,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -164,6 +165,7 @@ export class ProfileChangeNameController extends Controller {
@Body() body: UpdateProfileChangeName, @Body() body: UpdateProfileChangeName,
@Path() changeNameId: string, @Path() changeNameId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -212,7 +214,8 @@ export class ProfileChangeNameController extends Controller {
} }
@Delete("{changeNameId}") @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({ await this.changeNameHistoryRepository.delete({
profileChangeNameId: changeNameId, profileChangeNameId: changeNameId,
}); });

View file

@ -26,7 +26,7 @@ import {
UpdateProfileChangeName, UpdateProfileChangeName,
} from "../entities/ProfileChangeName"; } from "../entities/ProfileChangeName";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/changeName") @Route("api/v1/org/profile-employee/changeName")
@Tags("ProfileChangeNameEmployee") @Tags("ProfileChangeNameEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -119,6 +119,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileChangeNameEmployee, @Body() body: CreateProfileChangeNameEmployee,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -156,6 +157,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Body() body: UpdateProfileChangeName, @Body() body: UpdateProfileChangeName,
@Path() changeNameId: string, @Path() changeNameId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -196,7 +198,8 @@ export class ProfileChangeNameEmployeeController extends Controller {
} }
@Delete("{changeNameId}") @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({ await this.changeNameHistoryRepository.delete({
profileChangeNameId: changeNameId, profileChangeNameId: changeNameId,
}); });

View file

@ -25,6 +25,7 @@ import {
UpdateProfileChildren, UpdateProfileChildren,
} from "../entities/ProfileChildren"; } from "../entities/ProfileChildren";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/family/children") @Route("api/v1/org/profile/family/children")
@Tags("ProfileChildren") @Tags("ProfileChildren")
@Security("bearerAuth") @Security("bearerAuth")
@ -64,6 +65,7 @@ export class ProfileChildrenController extends Controller {
@Post() @Post()
public async newChildren(@Request() req: RequestWithUser, @Body() body: CreateProfileChildren) { 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 }); const profile = await this.profileRepository.findOneBy({ id: body.profileId });
if (!profile) { if (!profile) {
@ -106,6 +108,7 @@ export class ProfileChildrenController extends Controller {
@Body() body: UpdateProfileChildren, @Body() body: UpdateProfileChildren,
@Path() childrenId: string, @Path() childrenId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.childrenRepository.findOneBy({ id: childrenId }); const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -132,7 +135,8 @@ export class ProfileChildrenController extends Controller {
} }
@Delete("{childrenId}") @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({ await this.childrenHistoryRepository.delete({
profileChildrenId: childrenId, profileChildrenId: childrenId,
}); });

View file

@ -27,6 +27,7 @@ import {
} from "../entities/ProfileChildren"; } from "../entities/ProfileChildren";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/family/children") @Route("api/v1/org/profile-employee/family/children")
@Tags("ProfileChildren") @Tags("ProfileChildren")
@Security("bearerAuth") @Security("bearerAuth")
@ -69,6 +70,7 @@ export class ProfileChildrenEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileChildrenEmployee, @Body() body: CreateProfileChildrenEmployee,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
@ -113,6 +115,7 @@ export class ProfileChildrenEmployeeController extends Controller {
@Body() body: UpdateProfileChildren, @Body() body: UpdateProfileChildren,
@Path() childrenId: string, @Path() childrenId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.childrenRepository.findOneBy({ id: childrenId }); const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -141,7 +144,8 @@ export class ProfileChildrenEmployeeController extends Controller {
} }
@Delete("{childrenId}") @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({ await this.childrenHistoryRepository.delete({
profileChildrenId: childrenId, profileChildrenId: childrenId,
}); });

View file

@ -59,7 +59,7 @@ import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory"; import { ProfileDisciplineHistory } from "../entities/ProfileDisciplineHistory";
import { ProfileLeave } from "../entities/ProfileLeave"; import { ProfileLeave } from "../entities/ProfileLeave";
import { updateName } from "../keycloak"; import { updateName } from "../keycloak";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@Security("bearerAuth") @Security("bearerAuth")
@ -2250,6 +2250,7 @@ export class ProfileController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateProfile, @Body() body: UpdateProfile,
) { ) {
await new permission().PermissionUpdate(request,"SYS_REGISTRY");
const exists = const exists =
!!body.citizenId && !!body.citizenId &&
(await this.profileRepo.findOne({ (await this.profileRepo.findOne({

View file

@ -24,7 +24,7 @@ import {
ProfileDiscipline, ProfileDiscipline,
UpdateProfileDiscipline, UpdateProfileDiscipline,
} from "../entities/ProfileDiscipline"; } from "../entities/ProfileDiscipline";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/discipline") @Route("api/v1/org/profile/discipline")
@Tags("ProfileDiscipline") @Tags("ProfileDiscipline")
@Security("bearerAuth") @Security("bearerAuth")
@ -124,6 +124,7 @@ export class ProfileDisciplineController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileDiscipline, @Body() body: CreateProfileDiscipline,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -156,6 +157,7 @@ export class ProfileDisciplineController extends Controller {
@Body() body: UpdateProfileDiscipline, @Body() body: UpdateProfileDiscipline,
@Path() disciplineId: string, @Path() disciplineId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -177,7 +179,8 @@ export class ProfileDisciplineController extends Controller {
} }
@Delete("{disciplineId}") @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({ await this.disciplineHistoryRepository.delete({
profileDisciplineId: disciplineId, profileDisciplineId: disciplineId,
}); });

View file

@ -24,7 +24,7 @@ import {
UpdateProfileDiscipline, UpdateProfileDiscipline,
} from "../entities/ProfileDiscipline"; } from "../entities/ProfileDiscipline";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/discipline") @Route("api/v1/org/profile-employee/discipline")
@Tags("ProfileDisciplineEmployee") @Tags("ProfileDisciplineEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -115,6 +115,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeDiscipline, @Body() body: CreateProfileEmployeeDiscipline,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -147,6 +148,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
@Body() body: UpdateProfileDiscipline, @Body() body: UpdateProfileDiscipline,
@Path() disciplineId: string, @Path() disciplineId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -168,7 +170,8 @@ export class ProfileDisciplineEmployeeController extends Controller {
} }
@Delete("{disciplineId}") @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({ await this.disciplineHistoryRepository.delete({
profileDisciplineId: disciplineId, profileDisciplineId: disciplineId,
}); });

View file

@ -20,7 +20,7 @@ import { ProfileDutyHistory } from "../entities/ProfileDutyHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/duty") @Route("api/v1/org/profile/duty")
@Tags("ProfileDuty") @Tags("ProfileDuty")
@Security("bearerAuth") @Security("bearerAuth")
@ -128,6 +128,7 @@ export class ProfileDutyController extends Controller {
@Post() @Post()
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileDuty) { public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileDuty) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -160,6 +161,7 @@ export class ProfileDutyController extends Controller {
@Body() body: UpdateProfileDuty, @Body() body: UpdateProfileDuty,
@Path() dutyId: string, @Path() dutyId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.dutyRepository.findOneBy({ id: dutyId }); const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -178,7 +180,8 @@ export class ProfileDutyController extends Controller {
} }
@Delete("{dutyId}") @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({ await this.dutyHistoryRepository.delete({
profileDutyId: dutyId, profileDutyId: dutyId,
}); });

View file

@ -20,7 +20,7 @@ import { ProfileDutyHistory } from "../entities/ProfileDutyHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/duty") @Route("api/v1/org/profile-employee/duty")
@Tags("ProfileEmployeeDuty") @Tags("ProfileEmployeeDuty")
@Security("bearerAuth") @Security("bearerAuth")
@ -89,6 +89,7 @@ export class ProfileDutyEmployeeController extends Controller {
@Post() @Post()
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) { public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -121,6 +122,7 @@ export class ProfileDutyEmployeeController extends Controller {
@Body() body: UpdateProfileDuty, @Body() body: UpdateProfileDuty,
@Path() dutyId: string, @Path() dutyId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.dutyRepository.findOneBy({ id: dutyId }); const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -139,7 +141,8 @@ export class ProfileDutyEmployeeController extends Controller {
} }
@Delete("{dutyId}") @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({ await this.dutyHistoryRepository.delete({
profileDutyId: dutyId, profileDutyId: dutyId,
}); });

View file

@ -30,7 +30,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/educations") @Route("api/v1/org/profile/educations")
@Tags("ProfileEducations") @Tags("ProfileEducations")
@Security("bearerAuth") @Security("bearerAuth")
@ -181,6 +181,7 @@ export class ProfileEducationsController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEducation, @Body() body: CreateProfileEducation,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -211,6 +212,7 @@ export class ProfileEducationsController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() educationId: string, @Path() educationId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.profileEducationRepo.findOneBy({ id: educationId }); const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -232,7 +234,8 @@ export class ProfileEducationsController extends Controller {
} }
@Delete("{educationId}") @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({ await this.profileEducationHistoryRepo.delete({
profileEducationId: educationId, profileEducationId: educationId,
}); });

View file

@ -16,11 +16,9 @@ import {
Patch, Patch,
Example, Example,
} from "tsoa"; } from "tsoa";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import { import {
ProfileEducation, ProfileEducation,
CreateProfileEducation, CreateProfileEducation,
@ -32,7 +30,7 @@ import { Profile } from "../entities/Profile";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/educations") @Route("api/v1/org/profile-employee/educations")
@Tags("ProfileEducationsEmployee") @Tags("ProfileEducationsEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -185,6 +183,7 @@ export class ProfileEducationsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEducationEmployee, @Body() body: CreateProfileEducationEmployee,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -215,6 +214,7 @@ export class ProfileEducationsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() educationId: string, @Path() educationId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.profileEducationRepo.findOneBy({ id: educationId }); const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -236,7 +236,8 @@ export class ProfileEducationsEmployeeController extends Controller {
} }
@Delete("{educationId}") @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({ await this.profileEducationHistoryRepo.delete({
profileEducationId: educationId, profileEducationId: educationId,
}); });

View file

@ -37,7 +37,6 @@ import {
import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosType } from "../entities/EmployeePosType";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Position } from "../entities/Position";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { SubDistrict } from "../entities/SubDistrict"; import { SubDistrict } from "../entities/SubDistrict";
@ -63,11 +62,10 @@ import {
} from "../entities/ProfileEmployeeEmployment"; } from "../entities/ProfileEmployeeEmployment";
import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory"; import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmploymentHistory";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import e from "cors";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { ProfileInsignia } from "../entities/ProfileInsignia"; import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave"; import { ProfileLeave } from "../entities/ProfileLeave";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee") @Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -578,6 +576,7 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Post() @Post()
async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request,"SYS_REGISTRY_EMP");
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) { if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
throw new HttpError( throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
@ -630,6 +629,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateProfileEmployee, @Body() body: UpdateProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request,"SYS_REGISTRY_EMP");
const exists = const exists =
!!body.citizenId && !!body.citizenId &&
(await this.profileRepo.findOne({ (await this.profileRepo.findOne({
@ -692,7 +692,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{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 } }); const result = await this.profileRepo.findOne({ where: { id: id } });
if (!result) { if (!result) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -989,6 +990,61 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess(formattedData); 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 * API
* *
@ -2760,7 +2816,7 @@ export class ProfileEmployeeController extends Controller {
profile.leaveReason = requestBody.leaveReason; profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave; profile.dateLeave = requestBody.dateLeave;
if (requestBody.isLeave == true) { if (requestBody.isLeave == true) {
await removeProfileInOrganize(profile.id,"EMPLOYEE"); await removeProfileInOrganize(profile.id, "EMPLOYEE");
} }
await this.profileRepo.save(profile); await this.profileRepo.save(profile);
@ -3076,7 +3132,7 @@ export class ProfileEmployeeController extends Controller {
}); });
if (profile != null) { if (profile != null) {
await new CallAPI() await new CallAPI()
.PostData(request, "org/profile-employee/salary", { .PostData(request, "/org/profile-employee/salary", {
profileEmployeeId: profile.id, profileEmployeeId: profile.id,
date: new Date(), date: new Date(),
amount: v.amount, amount: v.amount,
@ -3092,10 +3148,12 @@ export class ProfileEmployeeController extends Controller {
.then(async (x) => { .then(async (x) => {
profile.statusTemp = "DONE"; profile.statusTemp = "DONE";
profile.employeeClass = "PERM"; profile.employeeClass = "PERM";
const _null: any = null;
profile.employeeWage = v.amount == null ? _null : v.amount.toString();
await this.profileRepo.save(profile); await this.profileRepo.save(profile);
}); });
await new CallAPI() await new CallAPI()
.PostData(request, "org/employee/pos/report/current", { .PostData(request, "/org/employee/pos/report/current", {
posmasterId: profile.posmasterIdTemp, posmasterId: profile.posmasterIdTemp,
positionId: profile.positionIdTemp, positionId: profile.positionIdTemp,
profileId: profile.id, profileId: profile.id,

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileFamilyCouple"; } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/family/couple") @Route("api/v1/org/profile/family/couple")
@Tags("ProfileFamilyCouple") @Tags("ProfileFamilyCouple")
@Security("bearerAuth") @Security("bearerAuth")
@ -219,6 +220,7 @@ export class ProfileFamilyCoupleController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyCouple, @Body() body: CreateProfileFamilyCouple,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
const familyCouple = Object.assign(new ProfileFamilyCouple(), body); const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) { if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -265,6 +267,7 @@ export class ProfileFamilyCoupleController extends Controller {
@Body() body: UpdateProfileFamilyCouple, @Body() body: UpdateProfileFamilyCouple,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId }); const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -21,6 +21,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyCouple, CreateProfileEmployeeFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCouple, CreateProfileEmployeeFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/family/couple") @Route("api/v1/org/profile-employee/family/couple")
@Tags("ProfileEmployeeFamilyCouple") @Tags("ProfileEmployeeFamilyCouple")
@Security("bearerAuth") @Security("bearerAuth")
@ -215,6 +216,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyCouple, @Body() body: CreateProfileEmployeeFamilyCouple,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
const familyCouple = Object.assign(new ProfileFamilyCouple(), body); const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) { if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -261,6 +263,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyCouple, @Body() body: UpdateProfileFamilyCouple,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ const familyCouple = await this.ProfileFamilyCouple.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileFamilyFather"; } from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/family/father") @Route("api/v1/org/profile/family/father")
@Tags("ProfileFamilyFather") @Tags("ProfileFamilyFather")
@Security("bearerAuth") @Security("bearerAuth")
@ -205,6 +206,7 @@ export class ProfileFamilyFatherController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyFather, @Body() body: CreateProfileFamilyFather,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
const familyFather = Object.assign(new ProfileFamilyFather(), body); const familyFather = Object.assign(new ProfileFamilyFather(), body);
if (!familyFather) { if (!familyFather) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -245,6 +247,7 @@ export class ProfileFamilyFatherController extends Controller {
@Body() body: UpdateProfileFamilyFather, @Body() body: UpdateProfileFamilyFather,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId }); const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId });
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileFamilyFather"; } from "../entities/ProfileFamilyFather";
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/family/father") @Route("api/v1/org/profile-employee/family/father")
@Tags("ProfileEmployeeFamilyFather") @Tags("ProfileEmployeeFamilyFather")
@Security("bearerAuth") @Security("bearerAuth")
@ -205,6 +206,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyFather, @Body() body: CreateProfileEmployeeFamilyFather,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
const familyFather = Object.assign(new ProfileFamilyFather(), body); const familyFather = Object.assign(new ProfileFamilyFather(), body);
if (!familyFather) { if (!familyFather) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -245,6 +247,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyFather, @Body() body: UpdateProfileFamilyFather,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const familyFather = await this.ProfileFamilyFather.findOneBy({ const familyFather = await this.ProfileFamilyFather.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileFamilyMother"; } from "../entities/ProfileFamilyMother";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/family/mother") @Route("api/v1/org/profile/family/mother")
@Tags("ProfileFamilyMother") @Tags("ProfileFamilyMother")
@Security("bearerAuth") @Security("bearerAuth")
@ -205,6 +206,7 @@ export class ProfileFamilyMotherController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileFamilyMother, @Body() body: CreateProfileFamilyMother,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
const familyMother = Object.assign(new ProfileFamilyMother(), body); const familyMother = Object.assign(new ProfileFamilyMother(), body);
if (!familyMother) { if (!familyMother) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -245,6 +247,7 @@ export class ProfileFamilyMotherController extends Controller {
@Body() body: UpdateProfileFamilyMother, @Body() body: UpdateProfileFamilyMother,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId }); const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -21,6 +21,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
import { ProfileFamilyMother, CreateProfileEmployeeFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother"; import { ProfileFamilyMother, CreateProfileEmployeeFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/family/mother") @Route("api/v1/org/profile-employee/family/mother")
@Tags("ProfileEmployeeFamilyMother") @Tags("ProfileEmployeeFamilyMother")
@Security("bearerAuth") @Security("bearerAuth")
@ -201,6 +202,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyMother, @Body() body: CreateProfileEmployeeFamilyMother,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
const familyMother = Object.assign(new ProfileFamilyMother(), body); const familyMother = Object.assign(new ProfileFamilyMother(), body);
if (!familyMother) { if (!familyMother) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -241,6 +243,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyMother, @Body() body: UpdateProfileFamilyMother,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const familyMother = await this.ProfileFamilyMother.findOneBy({ const familyMother = await this.ProfileFamilyMother.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -9,7 +9,7 @@ import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileG
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { calculateAge, calculateRetireDate } from "../interfaces/utils"; import { calculateAge, calculateRetireDate } from "../interfaces/utils";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/government") @Route("api/v1/org/profile/government")
@Tags("ProfileGovernment") @Tags("ProfileGovernment")
@Security("bearerAuth") @Security("bearerAuth")
@ -293,6 +293,7 @@ export class ProfileGovernmentHistoryController extends Controller {
@Body() body: UpdateProfileGovernment, @Body() body: UpdateProfileGovernment,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.profileRepo.findOne({ const record = await this.profileRepo.findOne({
where: { id: profileId }, where: { id: profileId },
}); });

View file

@ -26,7 +26,7 @@ import {
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { calculateAge, calculateRetireDate } from "../interfaces/utils"; import { calculateAge, calculateRetireDate } from "../interfaces/utils";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/government") @Route("api/v1/org/profile-employee/government")
@Tags("ProfileEmployeeGovernment") @Tags("ProfileEmployeeGovernment")
@Security("bearerAuth") @Security("bearerAuth")
@ -288,6 +288,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
@Body() body: UpdateProfileGovernment, @Body() body: UpdateProfileGovernment,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.profileEmployeeRepo.findOne({ const record = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });

View file

@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileHonorHistory } from "../entities/ProfileHonorHistory"; import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/honor") @Route("api/v1/org/profile/honor")
@Tags("ProfileHonor") @Tags("ProfileHonor")
@Security("bearerAuth") @Security("bearerAuth")
@ -138,6 +138,7 @@ export class ProfileHonorController extends Controller {
@Post() @Post()
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) { public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -170,6 +171,7 @@ export class ProfileHonorController extends Controller {
@Body() body: UpdateProfileHonor, @Body() body: UpdateProfileHonor,
@Path() honorId: string, @Path() honorId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.honorRepo.findOneBy({ id: honorId }); const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -188,7 +190,8 @@ export class ProfileHonorController extends Controller {
} }
@Delete("{honorId}") @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({ await this.honorHistoryRepo.delete({
profileHonorId: honorId, profileHonorId: honorId,
}); });

View file

@ -20,7 +20,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileHonorHistory } from "../entities/ProfileHonorHistory"; import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/honor") @Route("api/v1/org/profile-employee/honor")
@Tags("ProfileEmployeeHonor") @Tags("ProfileEmployeeHonor")
@Security("bearerAuth") @Security("bearerAuth")
@ -138,6 +138,7 @@ export class ProfileHonorEmployeeController extends Controller {
@Post() @Post()
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) { public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -170,6 +171,7 @@ export class ProfileHonorEmployeeController extends Controller {
@Body() body: UpdateProfileHonor, @Body() body: UpdateProfileHonor,
@Path() honorId: string, @Path() honorId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.honorRepo.findOneBy({ id: honorId }); const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -188,7 +190,8 @@ export class ProfileHonorEmployeeController extends Controller {
} }
@Delete("{honorId}") @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({ await this.honorHistoryRepo.delete({
profileHonorId: honorId, profileHonorId: honorId,
}); });

View file

@ -25,7 +25,7 @@ import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { Insignia } from "../entities/Insignia"; import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/insignia") @Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia") @Tags("ProfileInsignia")
@Security("bearerAuth") @Security("bearerAuth")
@ -166,6 +166,7 @@ export class ProfileInsigniaController extends Controller {
@Post() @Post()
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) { public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -205,6 +206,7 @@ export class ProfileInsigniaController extends Controller {
@Body() body: UpdateProfileInsignia, @Body() body: UpdateProfileInsignia,
@Path() insigniaId: string, @Path() insigniaId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -230,7 +232,8 @@ export class ProfileInsigniaController extends Controller {
} }
@Delete("{insigniaId}") @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({ await this.insigniaHistoryRepo.delete({
profileInsigniaId: insigniaId, profileInsigniaId: insigniaId,
}); });

View file

@ -25,7 +25,7 @@ import { ProfileInsigniaHistory } from "../entities/ProfileInsigniaHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Insignia } from "../entities/Insignia"; import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/insignia") @Route("api/v1/org/profile-employee/insignia")
@Tags("ProfileEmployeeInsignia") @Tags("ProfileEmployeeInsignia")
@Security("bearerAuth") @Security("bearerAuth")
@ -166,6 +166,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
@Post() @Post()
public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeInsignia) { public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeInsignia) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -205,6 +206,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
@Body() body: UpdateProfileInsignia, @Body() body: UpdateProfileInsignia,
@Path() insigniaId: string, @Path() insigniaId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -230,7 +232,8 @@ export class ProfileInsigniaEmployeeController extends Controller {
} }
@Delete("{insigniaId}") @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({ await this.insigniaHistoryRepo.delete({
profileInsigniaId: insigniaId, profileInsigniaId: insigniaId,
}); });

View file

@ -22,12 +22,11 @@ import {
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { LeaveType } from "../entities/LeaveType"; import { LeaveType } from "../entities/LeaveType";
import { Brackets } from "typeorm"; import { Brackets } from "typeorm";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/leave") @Route("api/v1/org/profile/leave")
@Tags("ProfileLeave") @Tags("ProfileLeave")
@Security("bearerAuth") @Security("bearerAuth")
@ -248,6 +247,7 @@ export class ProfileLeaveController extends Controller {
@Post() @Post()
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) { public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -286,6 +286,7 @@ export class ProfileLeaveController extends Controller {
@Body() body: UpdateProfileLeave, @Body() body: UpdateProfileLeave,
@Path() leaveId: string, @Path() leaveId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.leaveRepo.findOneBy({ id: leaveId }); const record = await this.leaveRepo.findOneBy({ id: leaveId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -311,7 +312,8 @@ export class ProfileLeaveController extends Controller {
} }
@Delete("{leaveId}") @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({ await this.leaveHistoryRepo.delete({
profileLeaveId: leaveId, profileLeaveId: leaveId,
}); });

View file

@ -22,11 +22,10 @@ import {
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { LeaveType } from "../entities/LeaveType"; import { LeaveType } from "../entities/LeaveType";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/leave") @Route("api/v1/org/profile-employee/leave")
@Tags("ProfileLeave") @Tags("ProfileLeave")
@Security("bearerAuth") @Security("bearerAuth")
@ -69,6 +68,7 @@ export class ProfileLeaveEmployeeController extends Controller {
@Post() @Post()
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) { public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -107,6 +107,7 @@ export class ProfileLeaveEmployeeController extends Controller {
@Body() body: UpdateProfileLeave, @Body() body: UpdateProfileLeave,
@Path() leaveId: string, @Path() leaveId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.leaveRepo.findOneBy({ id: leaveId }); const record = await this.leaveRepo.findOneBy({ id: leaveId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -132,7 +133,8 @@ export class ProfileLeaveEmployeeController extends Controller {
} }
@Delete("{leaveId}") @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({ await this.leaveHistoryRepo.delete({
profileLeaveId: leaveId, profileLeaveId: leaveId,
}); });

View file

@ -20,7 +20,7 @@ import { ProfileNopaidHistory } from "../entities/ProfileNopaidHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid"; import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/nopaid") @Route("api/v1/org/profile/nopaid")
@Tags("ProfileNopaid") @Tags("ProfileNopaid")
@Security("bearerAuth") @Security("bearerAuth")
@ -96,6 +96,7 @@ export class ProfileNopaidController extends Controller {
@Post() @Post()
public async newNopaid(@Request() req: RequestWithUser, @Body() body: CreateProfileNopaid) { public async newNopaid(@Request() req: RequestWithUser, @Body() body: CreateProfileNopaid) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -128,6 +129,7 @@ export class ProfileNopaidController extends Controller {
@Body() body: UpdateProfileNopaid, @Body() body: UpdateProfileNopaid,
@Path() nopaidId: string, @Path() nopaidId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -149,7 +151,8 @@ export class ProfileNopaidController extends Controller {
} }
@Delete("{nopaidId}") @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({ await this.nopaidHistoryRepository.delete({
profileNopaidId: nopaidId, profileNopaidId: nopaidId,
}); });

View file

@ -24,7 +24,7 @@ import {
ProfileNopaid, ProfileNopaid,
UpdateProfileNopaid, UpdateProfileNopaid,
} from "../entities/ProfileNopaid"; } from "../entities/ProfileNopaid";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/nopaid") @Route("api/v1/org/profile-employee/nopaid")
@Tags("ProfileNopaid") @Tags("ProfileNopaid")
@Security("bearerAuth") @Security("bearerAuth")
@ -67,6 +67,7 @@ export class ProfileNopaidEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeNopaid, @Body() body: CreateProfileEmployeeNopaid,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -99,6 +100,7 @@ export class ProfileNopaidEmployeeController extends Controller {
@Body() body: UpdateProfileNopaid, @Body() body: UpdateProfileNopaid,
@Path() nopaidId: string, @Path() nopaidId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -120,7 +122,8 @@ export class ProfileNopaidEmployeeController extends Controller {
} }
@Delete("{nopaidId}") @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({ await this.nopaidHistoryRepository.delete({
profileNopaidId: nopaidId, profileNopaidId: nopaidId,
}); });

View file

@ -20,7 +20,7 @@ import { ProfileOtherHistory } from "../entities/ProfileOtherHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther"; import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/other") @Route("api/v1/org/profile/other")
@Tags("ProfileOther") @Tags("ProfileOther")
@Security("bearerAuth") @Security("bearerAuth")
@ -93,6 +93,7 @@ export class ProfileOtherController extends Controller {
@Post() @Post()
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileOther) { public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileOther) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -125,6 +126,7 @@ export class ProfileOtherController extends Controller {
@Body() body: UpdateProfileOther, @Body() body: UpdateProfileOther,
@Path() otherId: string, @Path() otherId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.otherRepository.findOneBy({ id: otherId }); const record = await this.otherRepository.findOneBy({ id: otherId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -146,7 +148,8 @@ export class ProfileOtherController extends Controller {
} }
@Delete("{otherId}") @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({ await this.otherHistoryRepository.delete({
profileOtherId: otherId, profileOtherId: otherId,
}); });

View file

@ -24,7 +24,7 @@ import {
ProfileOther, ProfileOther,
UpdateProfileOther, UpdateProfileOther,
} from "../entities/ProfileOther"; } from "../entities/ProfileOther";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/other") @Route("api/v1/org/profile-employee/other")
@Tags("ProfileOther") @Tags("ProfileOther")
@Security("bearerAuth") @Security("bearerAuth")
@ -64,6 +64,7 @@ export class ProfileOtherEmployeeController extends Controller {
@Post() @Post()
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) { public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -96,6 +97,7 @@ export class ProfileOtherEmployeeController extends Controller {
@Body() body: UpdateProfileOther, @Body() body: UpdateProfileOther,
@Path() otherId: string, @Path() otherId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.otherRepository.findOneBy({ id: otherId }); const record = await this.otherRepository.findOneBy({ id: otherId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -117,7 +119,8 @@ export class ProfileOtherEmployeeController extends Controller {
} }
@Delete("{otherId}") @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({ await this.otherHistoryRepository.delete({
profileOtherId: otherId, profileOtherId: otherId,
}); });

View file

@ -21,7 +21,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { LessThan, MoreThan } from "typeorm"; import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/salary") @Route("api/v1/org/profile/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -140,6 +140,7 @@ export class ProfileSalaryController extends Controller {
@Post() @Post()
public async newSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalary) { public async newSalary(@Request() req: RequestWithUser, @Body() body: CreateProfileSalary) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -178,6 +179,7 @@ export class ProfileSalaryController extends Controller {
@Body() body: UpdateProfileSalary, @Body() body: UpdateProfileSalary,
@Path() salaryId: string, @Path() salaryId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.salaryRepo.findOneBy({ id: salaryId }); const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -196,7 +198,8 @@ export class ProfileSalaryController extends Controller {
} }
@Delete("{salaryId}") @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({ await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId, profileSalaryId: salaryId,
}); });

View file

@ -25,7 +25,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { LessThan, MoreThan } from "typeorm"; import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/salary") @Route("api/v1/org/profile-employee/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -69,6 +69,7 @@ export class ProfileSalaryEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileSalaryEmployee, @Body() body: CreateProfileSalaryEmployee,
) { ) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -107,6 +108,7 @@ export class ProfileSalaryEmployeeController extends Controller {
@Body() body: UpdateProfileSalaryEmployee, @Body() body: UpdateProfileSalaryEmployee,
@Path() salaryId: string, @Path() salaryId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.salaryRepo.findOneBy({ id: salaryId }); const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -125,7 +127,8 @@ export class ProfileSalaryEmployeeController extends Controller {
} }
@Delete("{salaryId}") @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({ await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId, profileSalaryId: salaryId,
}); });

View file

@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory"; import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile/training") @Route("api/v1/org/profile/training")
@Tags("ProfileTraining") @Tags("ProfileTraining")
@Security("bearerAuth") @Security("bearerAuth")
@ -139,6 +139,7 @@ export class ProfileTrainingController extends Controller {
@Post() @Post()
public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) { public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) {
await new permission().PermissionCreate(req,"SYS_REGISTRY");
if (!body.profileId) { if (!body.profileId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
@ -171,6 +172,7 @@ export class ProfileTrainingController extends Controller {
@Body() body: UpdateProfileTraining, @Body() body: UpdateProfileTraining,
@Path() trainingId: string, @Path() trainingId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY");
const record = await this.trainingRepo.findOneBy({ id: trainingId }); const record = await this.trainingRepo.findOneBy({ id: trainingId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -189,7 +191,8 @@ export class ProfileTrainingController extends Controller {
} }
@Delete("{trainingId}") @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({ await this.trainingHistoryRepo.delete({
profileTrainingId: trainingId, profileTrainingId: trainingId,
}); });

View file

@ -24,7 +24,7 @@ import HttpError from "../interfaces/http-error";
import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory"; import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission";
@Route("api/v1/org/profile-employee/training") @Route("api/v1/org/profile-employee/training")
@Tags("ProfileEmployeeTraining") @Tags("ProfileEmployeeTraining")
@Security("bearerAuth") @Security("bearerAuth")
@ -139,6 +139,7 @@ export class ProfileTrainingEmployeeController extends Controller {
@Post() @Post()
public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeTraining) { public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeTraining) {
await new permission().PermissionCreate(req,"SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -171,6 +172,7 @@ export class ProfileTrainingEmployeeController extends Controller {
@Body() body: UpdateProfileTraining, @Body() body: UpdateProfileTraining,
@Path() trainingId: string, @Path() trainingId: string,
) { ) {
await new permission().PermissionUpdate(req,"SYS_REGISTRY_EMP");
const record = await this.trainingRepo.findOneBy({ id: trainingId }); const record = await this.trainingRepo.findOneBy({ id: trainingId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -189,7 +191,8 @@ export class ProfileTrainingEmployeeController extends Controller {
} }
@Delete("{trainingId}") @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({ await this.trainingHistoryRepo.delete({
profileTrainingId: trainingId, profileTrainingId: trainingId,
}); });

View file

@ -32,12 +32,12 @@ export class HR_EDUCATION {
}) })
EDUCATION_YEAR: string; EDUCATION_YEAR: string;
@Column({ // @Column({
nullable: true, // nullable: true,
type: "text", // type: "text",
default: null, // default: null,
}) // })
EDUCATION_NAME: string; // EDUCATION_NAME: string;
@Column({ @Column({
nullable: true, nullable: true,

View file

@ -32,12 +32,12 @@ export class HR_EDUCATION_EMP {
}) })
EDUCATION_YEAR: string; EDUCATION_YEAR: string;
@Column({ // @Column({
nullable: true, // nullable: true,
type: "text", // type: "text",
default: null, // default: null,
}) // })
EDUCATION_NAME: string; // EDUCATION_NAME: string;
@Column({ @Column({
nullable: true, nullable: true,

View file

@ -27,6 +27,25 @@ class Extension {
} }
return null; 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) { public static CheckRelationship(value: any) {
if (value != "" && value != null) { if (value != "" && value != null) {
@ -76,6 +95,36 @@ class Extension {
return ""; 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) { public static ToThaiShortMonth(value: number) {
switch (value) { switch (value) {

View file

@ -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;