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

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