updated appoint & sen data to command
This commit is contained in:
parent
736a2f7940
commit
fd42120b9d
6 changed files with 1574 additions and 1429 deletions
|
|
@ -1,167 +1,209 @@
|
|||
import { Controller, Post, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query } from "tsoa"
|
||||
import { AppDataSource } from "../database/data-source"
|
||||
import HttpSuccess from "../interfaces/http-success"
|
||||
import HttpStatusCode from "../interfaces/http-status"
|
||||
import HttpError from "../interfaces/http-error"
|
||||
import { RequestWithUser } from "../middlewares/user"
|
||||
import { setLogDataDiff } from "../interfaces/utils"
|
||||
import { Personal, PostPersonal } from "../entities/Personal"
|
||||
import permission from "../interfaces/permission"
|
||||
import { Assign } from "../entities/Assign"
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { Personal, PostPersonal } from "../entities/Personal";
|
||||
import permission from "../interfaces/permission";
|
||||
import { Assign } from "../entities/Assign";
|
||||
|
||||
@Route("api/v1/probation/personal")
|
||||
@Tags("Personal")
|
||||
@Security("bearerAuth")
|
||||
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
export class PersonalController extends Controller {
|
||||
private personalRepository = AppDataSource.getRepository(Personal)
|
||||
private assignRepository = AppDataSource.getRepository(Assign)
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Post("add")
|
||||
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION")
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Post("add")
|
||||
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||
|
||||
const checkPersonal: number = await this.personalRepository.count({
|
||||
where: { personal_id: requestBody.id },
|
||||
})
|
||||
if (checkPersonal > 0) {
|
||||
throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว")
|
||||
}
|
||||
const checkPersonal: number = await this.personalRepository.count({
|
||||
where: { personal_id: requestBody.id },
|
||||
});
|
||||
if (checkPersonal > 0) {
|
||||
throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว");
|
||||
}
|
||||
|
||||
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "/" : "")
|
||||
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "/" : "")
|
||||
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "/" : "")
|
||||
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "/" : "")
|
||||
organization += await (requestBody.orgRootName ? requestBody.orgRootName : "")
|
||||
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "/" : "");
|
||||
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "/" : "");
|
||||
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "/" : "");
|
||||
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "/" : "");
|
||||
organization += await (requestBody.orgRootName ? requestBody.orgRootName : "");
|
||||
|
||||
const personalData = Object.assign(new Personal())
|
||||
personalData.personal_id = requestBody.id
|
||||
personalData.order_number = requestBody.order_number ? requestBody.order_number : ""
|
||||
personalData.probation_status = 1
|
||||
personalData.createdUserId = request.user.sub
|
||||
personalData.createdFullName = request.user.name
|
||||
personalData.updateUserId = request.user.sub
|
||||
personalData.updateFullName = request.user.name
|
||||
const personalData = Object.assign(new Personal());
|
||||
personalData.personal_id = requestBody.id;
|
||||
personalData.order_number = requestBody.order_number ? requestBody.order_number : "";
|
||||
personalData.probation_status = 1;
|
||||
personalData.createdUserId = request.user.sub;
|
||||
personalData.createdFullName = request.user.name;
|
||||
personalData.updateUserId = request.user.sub;
|
||||
personalData.updateFullName = request.user.name;
|
||||
|
||||
personalData.idcard = requestBody.idcard
|
||||
personalData.prefixName = requestBody.prefix
|
||||
personalData.firstName = requestBody.firstName
|
||||
personalData.lastName = requestBody.lastName
|
||||
personalData.isProbation = requestBody.isProbation ? 1 : 0
|
||||
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : ""
|
||||
personalData.positionName = requestBody.position ? requestBody.position : ""
|
||||
personalData.positionLineName = requestBody.posLineName
|
||||
personalData.positionTypeName = requestBody.posTypeName
|
||||
personalData.posNo = requestBody.posNo ? requestBody.posNo : ""
|
||||
personalData.orgRootName = requestBody.orgRootName
|
||||
personalData.organization = organization
|
||||
personalData.idcard = requestBody.idcard;
|
||||
personalData.prefixName = requestBody.prefix;
|
||||
personalData.firstName = requestBody.firstName;
|
||||
personalData.lastName = requestBody.lastName;
|
||||
personalData.isProbation = requestBody.isProbation ? 1 : 0;
|
||||
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : "";
|
||||
personalData.positionName = requestBody.position ? requestBody.position : "";
|
||||
personalData.positionLineName = requestBody.posLineName;
|
||||
personalData.positionTypeName = requestBody.posTypeName;
|
||||
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
|
||||
personalData.orgRootName = requestBody.orgRootName;
|
||||
personalData.organization = organization;
|
||||
|
||||
const before = null
|
||||
const personal = await this.personalRepository.save(personalData, {
|
||||
data: request,
|
||||
})
|
||||
setLogDataDiff(request, { before, after: personal })
|
||||
const before = null;
|
||||
const personal = await this.personalRepository.save(personalData, {
|
||||
data: request,
|
||||
});
|
||||
setLogDataDiff(request, { before, after: personal });
|
||||
|
||||
return new HttpSuccess()
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("list")
|
||||
async ListPersonal(@Query() status: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION")
|
||||
const conditions: any = {}
|
||||
if (status) {
|
||||
conditions.probation_status = status
|
||||
}
|
||||
/**
|
||||
* API รายการบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("list")
|
||||
async ListPersonal(
|
||||
@Query() status: string = "",
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_PROBATION");
|
||||
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
|
||||
|
||||
const [lists, total] = await this.personalRepository.findAndCount({
|
||||
order: { createdAt: "DESC" },
|
||||
where: conditions,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
})
|
||||
const conditions: any = {};
|
||||
if (status) {
|
||||
conditions.probation_status = status;
|
||||
}
|
||||
|
||||
if (!lists) {
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้")
|
||||
}
|
||||
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
||||
conditions.root = _data.root;
|
||||
}
|
||||
|
||||
let result: any = []
|
||||
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
||||
conditions.child1 = _data.child1;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
lists.map(async (item, index) => {
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: {
|
||||
personal_id: item.personal_id,
|
||||
},
|
||||
})
|
||||
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
||||
conditions.child2 = _data.child2;
|
||||
}
|
||||
|
||||
await result.push({
|
||||
personal_id: item.personal_id,
|
||||
ordering: index + 1,
|
||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
||||
idcard: item.idcard,
|
||||
prefixName: item.prefixName,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position_line: item.positionName,
|
||||
position_level: item.positionLevelName,
|
||||
position_type: item.positionTypeName,
|
||||
organization: item.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: item.order_number,
|
||||
probation_status: item.probation_status,
|
||||
})
|
||||
})
|
||||
)
|
||||
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
||||
conditions.child3 = _data.child3;
|
||||
}
|
||||
|
||||
return new HttpSuccess({ data: result, total: total })
|
||||
}
|
||||
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
||||
conditions.child4 = _data.child4;
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
||||
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION")
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: { personal_id: personal_id },
|
||||
})
|
||||
const [lists, total] = await this.personalRepository.findAndCount({
|
||||
order: { createdAt: "DESC" },
|
||||
where: conditions,
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
||||
}
|
||||
if (!lists) {
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
||||
}
|
||||
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: { personal_id: person.personal_id },
|
||||
})
|
||||
let result: any = [];
|
||||
|
||||
const result = await {
|
||||
personal_id: person.personal_id,
|
||||
name: person.prefixName + person.firstName + " " + person.lastName,
|
||||
position_line: person.positionName,
|
||||
position_level: person.positionLevelName,
|
||||
position_type: person.positionTypeName,
|
||||
organization: person.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: person.order_number,
|
||||
probation_status: person.probation_status,
|
||||
}
|
||||
await Promise.all(
|
||||
lists.map(async (item, index) => {
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: {
|
||||
personal_id: item.personal_id,
|
||||
},
|
||||
});
|
||||
|
||||
return new HttpSuccess(result)
|
||||
}
|
||||
await result.push({
|
||||
personal_id: item.personal_id,
|
||||
ordering: index + 1,
|
||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
||||
idcard: item.idcard,
|
||||
prefixName: item.prefixName,
|
||||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position_line: item.positionName,
|
||||
position_level: item.positionLevelName,
|
||||
position_type: item.positionTypeName,
|
||||
organization: item.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: item.order_number,
|
||||
probation_status: item.probation_status,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess({ data: result, total: total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||
*
|
||||
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
||||
*
|
||||
*/
|
||||
@Get("")
|
||||
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
||||
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
const person = await this.personalRepository.findOne({
|
||||
where: { personal_id: personal_id },
|
||||
});
|
||||
|
||||
if (!person) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||
}
|
||||
|
||||
const probation_no = await this.assignRepository.count({
|
||||
where: { personal_id: person.personal_id },
|
||||
});
|
||||
|
||||
const result = await {
|
||||
personal_id: person.personal_id,
|
||||
name: person.prefixName + person.firstName + " " + person.lastName,
|
||||
position_line: person.positionName,
|
||||
position_level: person.positionLevelName,
|
||||
position_type: person.positionTypeName,
|
||||
organization: person.organization,
|
||||
probation_no: probation_no,
|
||||
order_number: person.order_number,
|
||||
probation_status: person.probation_status,
|
||||
};
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -45,10 +45,10 @@ export class AppointDirector extends EntityBase {
|
|||
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: ["chairman", "committee"],
|
||||
enum: ["chairman", "committee", "caregiver"],
|
||||
nullable: false,
|
||||
default: "committee",
|
||||
comment: "บทบาท ประธาน/กรรมการ",
|
||||
comment: "บทบาท ประธาน/กรรมการ/ผู้ดูแล",
|
||||
})
|
||||
role: string;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,4 @@
|
|||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn,
|
||||
OneToOne,
|
||||
JoinColumn,
|
||||
OneToMany,
|
||||
} from "typeorm";
|
||||
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { Assign } from "./Assign";
|
||||
|
||||
|
|
@ -55,8 +48,7 @@ export class Personal extends EntityBase {
|
|||
|
||||
@Column({
|
||||
type: Boolean,
|
||||
comment:
|
||||
"สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน",
|
||||
comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน",
|
||||
default: 0,
|
||||
})
|
||||
isProbation: number;
|
||||
|
|
@ -109,6 +101,21 @@ export class Personal extends EntityBase {
|
|||
})
|
||||
idcard: string;
|
||||
|
||||
@Column({ nullable: true, comment: "id หน่วยงาน root", default: null })
|
||||
root: string;
|
||||
|
||||
@Column({ nullable: true, comment: "id หน่วยงาน child1", default: null })
|
||||
child1: string;
|
||||
|
||||
@Column({ nullable: true, comment: "id หน่วยงาน child2", default: null })
|
||||
child2: string;
|
||||
|
||||
@Column({ nullable: true, comment: "id หน่วยงาน child3", default: null })
|
||||
child3: string;
|
||||
|
||||
@Column({ nullable: true, comment: "id หน่วยงาน child4", default: null })
|
||||
child4: string;
|
||||
|
||||
@OneToMany(() => Assign, (assign: Assign) => assign.personal_id)
|
||||
@JoinColumn({ name: "personal_id" })
|
||||
assign: Assign[];
|
||||
|
|
|
|||
14
src/migration/1729823259868-alterColumnAppoint.ts
Normal file
14
src/migration/1729823259868-alterColumnAppoint.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AlterColumnAppoint1729823259868 implements MigrationInterface {
|
||||
name = 'AlterColumnAppoint1729823259868'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`appointDirector\` CHANGE \`role\` \`role\` enum ('chairman', 'committee', 'caregiver') NOT NULL COMMENT 'บทบาท ประธาน/กรรมการ/ผู้ดูแล' DEFAULT 'committee'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`appointDirector\` CHANGE \`role\` \`role\` enum ('chairman', 'committee') NOT NULL COMMENT 'บทบาท ประธาน/กรรมการ' DEFAULT 'committee'`);
|
||||
}
|
||||
|
||||
}
|
||||
22
src/migration/1729832583096-addColumnPersonal.ts
Normal file
22
src/migration/1729832583096-addColumnPersonal.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddColumnPersonal1729832583096 implements MigrationInterface {
|
||||
name = 'AddColumnPersonal1729832583096'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`root\` varchar(255) NULL COMMENT 'id หน่วยงาน root'`);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child1\` varchar(255) NULL COMMENT 'id หน่วยงาน child1'`);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child2\` varchar(255) NULL COMMENT 'id หน่วยงาน child2'`);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child3\` varchar(255) NULL COMMENT 'id หน่วยงาน child3'`);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`child4\` varchar(255) NULL COMMENT 'id หน่วยงาน child4'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child4\``);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child3\``);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`child1\``);
|
||||
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`root\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue