role โครงสร้างอัตรากำลัง

This commit is contained in:
AdisakKanthawilang 2024-08-16 17:36:08 +07:00
parent deb8194b7f
commit 2ce5138a4f
9 changed files with 109 additions and 48 deletions

View file

@ -36,6 +36,9 @@ import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4"; import { OrgChild4 } from "../entities/OrgChild4";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { AuthRole } from "../entities/AuthRole"; import { AuthRole } from "../entities/AuthRole";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { request } from "axios";
@Route("api/v1/org/employee/pos") @Route("api/v1/org/employee/pos")
@Tags("Employee") @Tags("Employee")
@Security("bearerAuth") @Security("bearerAuth")
@ -69,8 +72,9 @@ export class EmployeePositionController extends Controller {
async CreateEmployeePosition( async CreateEmployeePosition(
@Body() @Body()
requestBody: CreateEmployeePosDict, requestBody: CreateEmployeePosDict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG_EMP");
const empPosDict = Object.assign(new EmployeePosDict(), requestBody); const empPosDict = Object.assign(new EmployeePosDict(), requestBody);
if (!empPosDict) { if (!empPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -120,8 +124,9 @@ export class EmployeePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateEmployeePosDict, requestBody: UpdateEmployeePosDict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG_EMP");
const empPosDict = await this.employeePosDictRepository.findOne({ const empPosDict = await this.employeePosDictRepository.findOne({
where: { id: id }, where: { id: id },
}); });
@ -170,7 +175,8 @@ export class EmployeePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("position/{id}") @Delete("position/{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG_EMP");
const delEmpPosDict = await this.employeePosDictRepository.findOne({ where: { id } }); const delEmpPosDict = await this.employeePosDictRepository.findOne({ where: { id } });
if (!delEmpPosDict) { if (!delEmpPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งลูกจ้างประจำนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งลูกจ้างประจำนี้");
@ -359,8 +365,9 @@ export class EmployeePositionController extends Controller {
async createEmpMaster( async createEmpMaster(
@Body() @Body()
requestBody: CreateEmployeePosMaster, requestBody: CreateEmployeePosMaster,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG_EMP");
const posMaster = Object.assign(new EmployeePosMaster(), requestBody); const posMaster = Object.assign(new EmployeePosMaster(), requestBody);
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -607,8 +614,9 @@ export class EmployeePositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreateEmployeePosMaster, requestBody: CreateEmployeePosMaster,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG_EMP");
const posMaster = await this.employeePosMasterRepository.findOne({ where: { id: id } }); const posMaster = await this.employeePosMasterRepository.findOne({ where: { id: id } });
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
@ -847,7 +855,8 @@ export class EmployeePositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("master/{id}") @Delete("master/{id}")
async deleteEmpPosMaster(@Path() id: string) { async deleteEmpPosMaster(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_ORG_EMP");
const delPosMaster = await this.employeePosMasterRepository.findOne({ const delPosMaster = await this.employeePosMasterRepository.findOne({
where: { id }, where: { id },
}); });
@ -1177,7 +1186,8 @@ export class EmployeePositionController extends Controller {
* *
*/ */
@Post("sort") @Post("sort")
async SortEmp(@Body() requestBody: { id: string; type: number; sortId: string[] }) { async SortEmp(@Body() requestBody: { id: string; type: number; sortId: string[] }, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG_EMP");
switch (requestBody.type) { switch (requestBody.type) {
case 0: { case 0: {
const rootId = await this.employeePosMasterRepository.findOne({ const rootId = await this.employeePosMasterRepository.findOne({
@ -1401,8 +1411,9 @@ export class EmployeePositionController extends Controller {
@Post("move") @Post("move")
async moveEmpPosMaster( async moveEmpPosMaster(
@Body() requestBody: { id: string; type: number; positionMaster: string[] }, @Body() requestBody: { id: string; type: number; positionMaster: string[] },
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG_EMP");
const posMasters = await this.employeePosMasterRepository.find({ const posMasters = await this.employeePosMasterRepository.find({
where: { id: In(requestBody.positionMaster) }, where: { id: In(requestBody.positionMaster) },
}); });
@ -2067,7 +2078,9 @@ export class EmployeePositionController extends Controller {
@Post("profile") @Post("profile")
async createEmpHolder( async createEmpHolder(
@Body() requestBody: { posMaster: string; position: string; profileId: string; isSit: boolean }, @Body() requestBody: { posMaster: string; position: string; profileId: string; isSit: boolean },
@Request() request: RequestWithUser
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG_EMP");
const dataMaster = await this.employeePosMasterRepository.findOne({ const dataMaster = await this.employeePosMasterRepository.findOne({
where: { id: requestBody.posMaster }, where: { id: requestBody.posMaster },
relations: ["positions"], relations: ["positions"],
@ -2100,7 +2113,8 @@ export class EmployeePositionController extends Controller {
* @param {string} id *Id posMaster * @param {string} id *Id posMaster
*/ */
@Post("profile/delete/{id}") @Post("profile/delete/{id}")
async deleteEmpHolder(@Path() id: string) { async deleteEmpHolder(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG_EMP");
const dataMaster = await this.employeePosMasterRepository.findOne({ const dataMaster = await this.employeePosMasterRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["positions"], relations: ["positions"],
@ -2130,7 +2144,8 @@ export class EmployeePositionController extends Controller {
* *
*/ */
@Post("dna") @Post("dna")
async dnaEmp(@Body() requestBody: { draftPositionId: string; publishPositionId: string }) { async dnaEmp(@Body() requestBody: { draftPositionId: string; publishPositionId: string }, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG_EMP");
const findDraft = await this.orgRevisionRepository.findOne({ const findDraft = await this.orgRevisionRepository.findOne({
where: { where: {
orgRevisionIsDraft: true, orgRevisionIsDraft: true,
@ -2185,7 +2200,9 @@ export class EmployeePositionController extends Controller {
positionId: string; positionId: string;
profileId: string; profileId: string;
}, },
@Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG_EMP");
const posMaster = await this.employeePosMasterRepository.findOne({ const posMaster = await this.employeePosMasterRepository.findOne({
where: { id: body.posmasterId }, where: { id: body.posmasterId },
relations: ["orgRoot"], relations: ["orgRoot"],

View file

@ -29,6 +29,8 @@ import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { Like } from "typeorm/browser"; import { Like } from "typeorm/browser";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/child1") @Route("api/v1/org/child1")
@Tags("OrgChild1") @Tags("OrgChild1")
@Security("bearerAuth") @Security("bearerAuth")
@ -91,10 +93,8 @@ export class OrgChild1Controller {
* *
*/ */
@Post() @Post()
async save( async save(@Body() requestBody: CreateOrgChild1, @Request() request: RequestWithUser) {
@Body() requestBody: CreateOrgChild1, await new permission().PermissionCreate(request, "SYS_ORG");
@Request() request: { user: Record<string, any> },
) {
const rootIdExits = await this.orgRootRepository.findOne({ const rootIdExits = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
@ -186,8 +186,9 @@ export class OrgChild1Controller {
async Edit( async Edit(
@Path() id: string, @Path() id: string,
@Body() requestBody: UpdateOrgChild1, @Body() requestBody: UpdateOrgChild1,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const rootIdExits = await this.orgRootRepository.findOne({ const rootIdExits = await this.orgRootRepository.findOne({
where: { id: requestBody.orgRootId }, where: { id: requestBody.orgRootId },
}); });
@ -320,7 +321,8 @@ export class OrgChild1Controller {
* @param {string} id id 1 * @param {string} id id 1
*/ */
@Delete("{id}") @Delete("{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const child1 = await this.child1Repository.findOne({ where: { id } }); const child1 = await this.child1Repository.findOne({ where: { id } });
if (!child1) { if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -30,6 +30,8 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/child2") @Route("api/v1/org/child2")
@Tags("OrgChild2") @Tags("OrgChild2")
@Security("bearerAuth") @Security("bearerAuth")
@ -108,8 +110,9 @@ export class OrgChild2Controller extends Controller {
async create( async create(
@Body() @Body()
requestBody: CreateOrgChild2, requestBody: CreateOrgChild2,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
const child1 = await this.child1Repository.findOne({ const child1 = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id }, where: { id: requestBody.orgChild1Id },
}); });
@ -183,8 +186,9 @@ export class OrgChild2Controller extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateOrgChild2, requestBody: UpdateOrgChild2,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const child1IdExits = await this.child1Repository.findOne({ const child1IdExits = await this.child1Repository.findOne({
where: { id: requestBody.orgChild1Id }, where: { id: requestBody.orgChild1Id },
}); });
@ -239,7 +243,8 @@ export class OrgChild2Controller extends Controller {
* @param {string} id Guid, *Id Child2 * @param {string} id Guid, *Id Child2
*/ */
@Delete("{id}") @Delete("{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const child2 = await this.child2Repository.findOne({ where: { id } }); const child2 = await this.child2Repository.findOne({ where: { id } });
if (!child2) { if (!child2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -27,6 +27,8 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/child3") @Route("api/v1/org/child3")
@Tags("OrgChild3") @Tags("OrgChild3")
@Security("bearerAuth") @Security("bearerAuth")
@ -88,10 +90,8 @@ export class OrgChild3Controller {
* *
*/ */
@Post() @Post()
async save( async save(@Body() requestBody: CreateOrgChild3, @Request() request: RequestWithUser) {
@Body() requestBody: CreateOrgChild3, await new permission().PermissionCreate(request, "SYS_ORG");
@Request() request: { user: Record<string, any> },
) {
const child2 = await this.child2Repository.findOne({ const child2 = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id }, where: { id: requestBody.orgChild2Id },
}); });
@ -152,8 +152,9 @@ export class OrgChild3Controller {
async Edit( async Edit(
@Path() id: string, @Path() id: string,
@Body() requestBody: UpdateOrgChild3, @Body() requestBody: UpdateOrgChild3,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const child2IdExits = await this.child2Repository.findOne({ const child2IdExits = await this.child2Repository.findOne({
where: { id: requestBody.orgChild2Id }, where: { id: requestBody.orgChild2Id },
}); });
@ -209,7 +210,8 @@ export class OrgChild3Controller {
* @param {string} id id 3 * @param {string} id id 3
*/ */
@Delete("{id}") @Delete("{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const child3 = await this.child3Repository.findOne({ where: { id } }); const child3 = await this.child3Repository.findOne({ where: { id } });
if (!child3) { if (!child3) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -29,6 +29,8 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org/child4") @Route("api/v1/org/child4")
@Tags("OrgChild4") @Tags("OrgChild4")
@ -106,8 +108,9 @@ export class OrgChild4Controller extends Controller {
async create( async create(
@Body() @Body()
requestBody: CreateOrgChild4, requestBody: CreateOrgChild4,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
const child3 = await this.child3Repository.findOne({ const child3 = await this.child3Repository.findOne({
where: { id: requestBody.orgChild3Id }, where: { id: requestBody.orgChild3Id },
}); });
@ -184,8 +187,9 @@ export class OrgChild4Controller extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateOrgChild4, requestBody: UpdateOrgChild4,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const child3IdExits = await this.child3Repository.findOne({ const child3IdExits = await this.child3Repository.findOne({
where: { id: requestBody.orgChild3Id }, where: { id: requestBody.orgChild3Id },
}); });
@ -242,7 +246,8 @@ export class OrgChild4Controller extends Controller {
* @param {string} id Guid, *Id Child4 * @param {string} id Guid, *Id Child4
*/ */
@Delete("{id}") @Delete("{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const child4 = await this.child4Repository.findOne({ where: { id } }); const child4 = await this.child4Repository.findOne({ where: { id } });
if (!child4) { if (!child4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found."); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");

View file

@ -28,6 +28,8 @@ import { PosMaster } from "../entities/PosMaster";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/root") @Route("api/v1/org/root")
@Tags("OrgRoot") @Tags("OrgRoot")
@ -97,8 +99,9 @@ export class OrgRootController extends Controller {
// @Path() id: string, // @Path() id: string,
@Body() @Body()
requestBody: CreateOrgRoot, requestBody: CreateOrgRoot,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"]; const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) { if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank"); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
@ -178,11 +181,12 @@ export class OrgRootController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreateOrgRoot, requestBody: CreateOrgRoot,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"]; const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) { if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank"); throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRo otRank");
} }
const revisionIdExits = await this.orgRevisionRepository.findOne({ const revisionIdExits = await this.orgRevisionRepository.findOne({
@ -322,7 +326,8 @@ export class OrgRootController extends Controller {
* @param {string} id Guid, *Id root * @param {string} id Guid, *Id root
*/ */
@Delete("{id}") @Delete("{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const orgRoot = await this.orgRootRepository.findOne({ where: { id } }); const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
if (!orgRoot) { if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้างระดับ Root นี้");

View file

@ -28,6 +28,9 @@ import { Position } from "../entities/Position";
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";
import { request } from "axios";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
@Route("api/v1/org") @Route("api/v1/org")
@Tags("Organization") @Tags("Organization")
@ -1483,7 +1486,8 @@ export class OrganizationController extends Controller {
* *
*/ */
@Post("sort") @Post("sort")
async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }) { async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG");
switch (requestBody.type) { switch (requestBody.type) {
case 0: { case 0: {
const revisionId = await this.orgRevisionRepository.findOne({ const revisionId = await this.orgRevisionRepository.findOne({

View file

@ -38,6 +38,9 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosType } from "../entities/EmployeePosType";
import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { AuthRole } from "../entities/AuthRole"; import { AuthRole } from "../entities/AuthRole";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { request } from "axios";
@Route("api/v1/org/pos") @Route("api/v1/org/pos")
@Tags("Position") @Tags("Position")
@Security("bearerAuth") @Security("bearerAuth")
@ -85,8 +88,9 @@ export class PositionController extends Controller {
async createPosition( async createPosition(
@Body() @Body()
requestBody: CreatePosDict, requestBody: CreatePosDict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
const posDict = Object.assign(new PosDict(), requestBody); const posDict = Object.assign(new PosDict(), requestBody);
if (!posDict) { if (!posDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -164,8 +168,9 @@ export class PositionController extends Controller {
async createPositionNameExe( async createPositionNameExe(
@Body() @Body()
requestBody: CreatePosDictExe, requestBody: CreatePosDictExe,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
// let posDict: PosDict; // let posDict: PosDict;
let posDict: any = new PosDict(); let posDict: any = new PosDict();
posDict.posDictName = requestBody.posDictName; posDict.posDictName = requestBody.posDictName;
@ -267,8 +272,9 @@ export class PositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdatePosDict, requestBody: UpdatePosDict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const posDict = await this.posDictRepository.findOne({ const posDict = await this.posDictRepository.findOne({
where: { id: id }, where: { id: id },
}); });
@ -348,7 +354,8 @@ export class PositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("position/{id}") @Delete("position/{id}")
async delete(@Path() id: string) { async delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const delPosDict = await this.posDictRepository.findOne({ where: { id } }); const delPosDict = await this.posDictRepository.findOne({ where: { id } });
if (!delPosDict) { if (!delPosDict) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในสายงานนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในสายงานนี้");
@ -517,8 +524,9 @@ export class PositionController extends Controller {
async createMaster( async createMaster(
@Body() @Body()
requestBody: CreatePosMaster, requestBody: CreatePosMaster,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionCreate(request, "SYS_ORG");
const posMaster = Object.assign(new PosMaster(), requestBody); const posMaster = Object.assign(new PosMaster(), requestBody);
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -793,8 +801,9 @@ export class PositionController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreatePosMaster, requestBody: CreatePosMaster,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const posMaster = await this.posMasterRepository.findOne({ where: { id: id } }); const posMaster = await this.posMasterRepository.findOne({ where: { id: id } });
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
@ -1022,7 +1031,8 @@ export class PositionController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("master/{id}") @Delete("master/{id}")
async deletePosMaster(@Path() id: string) { async deletePosMaster(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const delPosMaster = await this.posMasterRepository.findOne({ const delPosMaster = await this.posMasterRepository.findOne({
where: { id }, where: { id },
// relations: ["position"], // relations: ["position"],
@ -1397,7 +1407,8 @@ export class PositionController extends Controller {
* *
*/ */
@Post("sort") @Post("sort")
async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }) { async Sort(@Body() requestBody: { id: string; type: number; sortId: string[] }, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG");
switch (requestBody.type) { switch (requestBody.type) {
case 0: { case 0: {
const rootId = await this.posMasterRepository.findOne({ const rootId = await this.posMasterRepository.findOne({
@ -1626,8 +1637,9 @@ export class PositionController extends Controller {
@Post("move") @Post("move")
async movePosMaster( async movePosMaster(
@Body() requestBody: { id: string; type: number; positionMaster: string[] }, @Body() requestBody: { id: string; type: number; positionMaster: string[] },
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const posMasters = await this.posMasterRepository.find({ const posMasters = await this.posMasterRepository.find({
where: { id: In(requestBody.positionMaster) }, where: { id: In(requestBody.positionMaster) },
}); });
@ -2464,7 +2476,9 @@ export class PositionController extends Controller {
@Post("profile") @Post("profile")
async createHolder( async createHolder(
@Body() requestBody: { posMaster: string; position: string; profileId: string; isSit: boolean }, @Body() requestBody: { posMaster: string; position: string; profileId: string; isSit: boolean },
@Request() request: RequestWithUser
) { ) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const dataMaster = await this.posMasterRepository.findOne({ const dataMaster = await this.posMasterRepository.findOne({
where: { id: requestBody.posMaster }, where: { id: requestBody.posMaster },
relations: ["positions"], relations: ["positions"],
@ -2496,7 +2510,8 @@ export class PositionController extends Controller {
* @param {string} id *Id posMaster * @param {string} id *Id posMaster
*/ */
@Post("profile/delete/{id}") @Post("profile/delete/{id}")
async deleteHolder(@Path() id: string) { async deleteHolder(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_ORG");
const dataMaster = await this.posMasterRepository.findOne({ const dataMaster = await this.posMasterRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["positions"], relations: ["positions"],
@ -2525,7 +2540,8 @@ export class PositionController extends Controller {
* *
*/ */
@Post("dna") @Post("dna")
async dna(@Body() requestBody: { draftPositionId: string; publishPositionId: string }) { async dna(@Body() requestBody: { draftPositionId: string; publishPositionId: string }, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const findDraft = await this.orgRevisionRepository.findOne({ const findDraft = await this.orgRevisionRepository.findOne({
where: { where: {
orgRevisionIsDraft: true, orgRevisionIsDraft: true,

View file

@ -66,6 +66,7 @@ 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"; import permission from "../interfaces/permission";
import { request } from "axios";
@Route("api/v1/org/profile-employee") @Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee") @Tags("ProfileEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -2029,6 +2030,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdatePositionTempProfileEmployee, @Body() body: UpdatePositionTempProfileEmployee,
) { ) {
await new permission().PermissionCreate(request, "SYS_REGISTRY_TEMP");
if (body.posLevelId === "") body.posLevelId = null; if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null; if (body.posTypeId === "") body.posTypeId = null;
@ -2841,6 +2843,7 @@ export class ProfileEmployeeController extends Controller {
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
@Body() body: UpdateInformationProfileEmployee, @Body() body: UpdateInformationProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request, "SYS_REGISTRY_TEMP");
const profileEmp = await this.profileRepo.findOneBy({ id: profileEmployeeId }); const profileEmp = await this.profileRepo.findOneBy({ id: profileEmployeeId });
if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
@ -3030,7 +3033,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("employment/{id}") @Delete("employment/{id}")
async DeleteEmployment(@Path() id: string) { async DeleteEmployment(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_REGISTRY_TEMP");
await this.employmentHistoryRepository.delete({ await this.employmentHistoryRepository.delete({
profileEmployeeEmploymentId: id, profileEmployeeEmploymentId: id,
}); });
@ -3055,6 +3059,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateEmploymentProfileEmployee, @Body() body: UpdateEmploymentProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request, "SYS_REGISTRY_TEMP");
const employment = await this.employmentRepository.findOneBy({ id }); const employment = await this.employmentRepository.findOneBy({ id });
if (!employment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!employment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");