Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-09-16 18:01:30 +07:00
commit 52fd0d2634
11 changed files with 413 additions and 22 deletions

View file

@ -0,0 +1,219 @@
import {
Controller,
Post,
Put,
Delete,
Route,
Security,
Tags,
Body,
Path,
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 { CommandSalary, CreateCommandSalary, UpdateCommandSalary } from "../entities/CommandSalary";
import { Not } from "typeorm";
import { CommandSys } from "../entities/CommandSys";
@Route("api/v1/org/commandSalary")
@Tags("CommandSalary")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class CommandSalaryController extends Controller {
private commandSalaryRepository = AppDataSource.getRepository(CommandSalary);
private commandSysRepository = AppDataSource.getRepository(CommandSys);
/**
* API list
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
*/
@Get("list")
async Get(@Query() commandSysId: string) {
const _commandSalary = await this.commandSalaryRepository.find({
where: { isActive: true, commandSysId: commandSysId },
select: [
"id",
"name",
"commandSysId",
"createdAt",
"lastUpdatedAt",
"createdFullName",
"lastUpdateFullName",
],
order: { createdAt: "ASC" },
});
return new HttpSuccess(_commandSalary);
}
/**
* API list
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
*/
@Get("admin")
async GetAdmin(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query() commandSysId?: string | null,
@Query() isActive?: boolean | null,
) {
const [commandSalarys, total] = await this.commandSalaryRepository
.createQueryBuilder("commandSalary")
.andWhere(
isActive != null && isActive != undefined ? "commandSalary.isActive = :isActive" : "1=1",
{
isActive:
isActive == null || isActive == undefined ? null : `${isActive == true ? 1 : 0}`,
},
)
.andWhere(
commandSysId != null && commandSysId != undefined && commandSysId != ""
? "commandSalary.commandSysId = :commandSysId"
: "1=1",
{
commandSysId:
commandSysId == null || commandSysId == undefined || commandSysId == ""
? null
: `${commandSysId}`,
},
)
.orderBy("commandSalary.createdAt", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ commandSalarys, total });
}
/**
* API
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
* @param {string} id Id
*/
@Get("{id}")
async GetById(@Path() id: string) {
const _commandSalary = await this.commandSalaryRepository.findOne({
where: { id },
select: ["id", "name", "commandSysId", "isActive"],
});
if (!_commandSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
return new HttpSuccess(_commandSalary);
}
/**
* API body
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
*/
@Post()
async Post(
@Body()
requestBody: CreateCommandSalary,
@Request() request: { user: Record<string, any> },
) {
const _commandSalary = Object.assign(new CommandSalary(), requestBody);
// const checkName = await this.commandSalaryRepository.findOne({
// where: { name: requestBody.name },
// });
// if (checkName) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อ Template นี้มีอยู่ในระบบแล้ว");
// }
const checkNameSys = await this.commandSysRepository.findOne({
where: { id: requestBody.commandSysId },
});
if (!checkNameSys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทนี้มีอยู่ในระบบ");
}
_commandSalary.createdUserId = request.user.sub;
_commandSalary.createdFullName = request.user.name;
_commandSalary.lastUpdateUserId = request.user.sub;
_commandSalary.lastUpdateFullName = request.user.name;
_commandSalary.createdAt = new Date();
_commandSalary.lastUpdatedAt = new Date();
await this.commandSalaryRepository.save(_commandSalary);
return new HttpSuccess(_commandSalary.id);
}
/**
* API body
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
* @param {string} id Id
*/
@Put("{id}")
async Put(
@Path() id: string,
@Body()
requestBody: UpdateCommandSalary,
@Request() request: { user: Record<string, any> },
) {
const _commandSalary = await this.commandSalaryRepository.findOne({ where: { id: id } });
if (!_commandSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล Template นี้");
}
// const checkName = await this.commandSalaryRepository.findOne({
// where: { id: Not(id), name: requestBody.name },
// });
// if (checkName) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
// }
const checkNameSys = await this.commandSysRepository.findOne({
where: { id: requestBody.commandSysId },
});
if (!checkNameSys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทนี้มีอยู่ในระบบ");
}
_commandSalary.lastUpdateUserId = request.user.sub;
_commandSalary.lastUpdateFullName = request.user.name;
_commandSalary.lastUpdatedAt = new Date();
this.commandSalaryRepository.merge(_commandSalary, requestBody);
await this.commandSalaryRepository.save(_commandSalary);
return new HttpSuccess(_commandSalary.id);
}
/**
* API
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
const _delCommandSalary = await this.commandSalaryRepository.findOne({
where: { id: id },
});
if (!_delCommandSalary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล Template นี้");
}
await this.commandSalaryRepository.delete(_delCommandSalary.id);
return new HttpSuccess();
}
}

View file

@ -49,6 +49,8 @@ export class CommandTypeController extends Controller {
"name",
"commandSysId",
"code",
"fileCover",
"fileAttachment",
"detailHeader",
"detailBody",
"detailFooter",
@ -57,7 +59,7 @@ export class CommandTypeController extends Controller {
"createdFullName",
"lastUpdateFullName",
],
order: { name: "ASC" },
order: { order: "ASC" },
});
return new HttpSuccess(_commandType);
}
@ -83,7 +85,7 @@ export class CommandTypeController extends Controller {
isActive == null || isActive == undefined ? null : `${isActive == true ? 1 : 0}`,
},
)
.orderBy("commandType.name", "ASC")
.orderBy("commandType.order", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
@ -106,6 +108,8 @@ export class CommandTypeController extends Controller {
"name",
"commandSysId",
"code",
"fileCover",
"fileAttachment",
"isActive",
"detailHeader",
"detailBody",
@ -229,6 +233,60 @@ export class CommandTypeController extends Controller {
return new HttpSuccess(_commandType.id);
}
/**
* API body
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
* @param {string} id Id
*/
@Put("cover/{id}")
async PutCover(
@Path() id: string,
@Body()
requestBody: { name: string },
@Request() request: { user: Record<string, any> },
) {
const _commandType = await this.commandTypeRepository.findOne({ where: { id: id } });
if (!_commandType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้");
}
_commandType.fileCover = requestBody.name;
_commandType.lastUpdateUserId = request.user.sub;
_commandType.lastUpdateFullName = request.user.name;
_commandType.lastUpdatedAt = new Date();
this.commandTypeRepository.merge(_commandType, requestBody);
await this.commandTypeRepository.save(_commandType);
return new HttpSuccess(_commandType.id);
}
/**
* API body
*
* @summary ORG_056 - CRUD (ADMIN) #61
*
* @param {string} id Id
*/
@Put("attachment/{id}")
async PutAttachment(
@Path() id: string,
@Body()
requestBody: { name: string },
@Request() request: { user: Record<string, any> },
) {
const _commandType = await this.commandTypeRepository.findOne({ where: { id: id } });
if (!_commandType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้");
}
_commandType.fileAttachment = requestBody.name;
_commandType.lastUpdateUserId = request.user.sub;
_commandType.lastUpdateFullName = request.user.name;
_commandType.lastUpdatedAt = new Date();
this.commandTypeRepository.merge(_commandType, requestBody);
await this.commandTypeRepository.save(_commandType);
return new HttpSuccess(_commandType.id);
}
/**
* API
*

View file

@ -296,7 +296,7 @@ export class ImportDataController extends Controller {
await Promise.all(
profiles.map(async (_item) => {
const existingProfile = await this.HR_POSITION_OFFICERRepo.find({
where: { CIT: _item.citizenId },
where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" },
select: [
"CIT",
"MP_POS_DATE",
@ -319,7 +319,9 @@ export class ImportDataController extends Controller {
rowCount++;
const profileSalary = new ProfileSalary();
profileSalary.date =
item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE);
item.MP_POS_DATE == ""
? null_
: new Date(item.MP_POS_DATE.replace(" +0700 +07:00", ""));
const SALARY: any =
item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY);
profileSalary.amount = SALARY;

View file

@ -1,21 +1,4 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { Controller, Get, Route, Security, Tags, SuccessResponse, Response } from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";

View file

@ -0,0 +1,45 @@
import { Entity, Column, JoinColumn, ManyToOne } from "typeorm";
import { EntityBase } from "./base/Base";
import { CommandSys } from "./CommandSys";
@Entity("commandSalary")
export class CommandSalary extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อคำสั่ง",
length: 255,
default: null,
})
name: string;
@Column({
comment: "สถานะการใช้งาน",
default: true,
})
isActive: boolean;
@Column({
nullable: true,
length: 255,
comment: "คีย์นอก(FK)ของตาราง CommandSys",
default: null,
})
commandSysId: string;
@ManyToOne(() => CommandSys, (commandSys) => commandSys.commandSalarys)
@JoinColumn({ name: "commandSysId" })
commandSalarySys: CommandSys;
}
export class CreateCommandSalary {
@Column()
name: string;
@Column()
isActive: boolean;
@Column()
commandSysId: string;
}
export type UpdateCommandSalary = Partial<CreateCommandSalary>;

View file

@ -7,6 +7,7 @@ import {
OneToMany,
} from "typeorm";
import { CommandType } from "./CommandType";
import { CommandSalary } from "./CommandSalary";
@Entity("commandSys")
export class CommandSys {
@ -60,6 +61,9 @@ export class CommandSys {
@OneToMany(() => CommandType, (commandType) => commandType.commandTypeSys)
commandTypes: CommandType[];
@OneToMany(() => CommandSalary, (commandSalary) => commandSalary.commandSalarySys)
commandSalarys: CommandSalary[];
}
export class CreateCommandSys {

View file

@ -5,6 +5,13 @@ import { CommandSys } from "./CommandSys";
@Entity("commandType")
export class CommandType extends EntityBase {
@Column({
nullable: true,
comment: "ลำดับความสำคัญ",
default: null,
})
order: number;
@Column({
nullable: true,
comment: "ชื่อคำสั่ง",
@ -21,6 +28,22 @@ export class CommandType extends EntityBase {
})
code: string;
@Column({
nullable: true,
comment: "คำสั่งเรื่อง",
length: 255,
default: null,
})
fileCover: string;
@Column({
nullable: true,
comment: "คำสั่งเรื่อง",
length: 255,
default: null,
})
fileAttachment: string;
@Column({
nullable: true,
comment: "เนื้อหาคำสั่งส่วนต้น",

View file

@ -11,6 +11,13 @@ export class HR_POSITION_OFFICER {
@PrimaryGeneratedColumn()
id!: number;
@Column({
nullable: true,
type: "text",
default: null,
})
FLAG_PERSON_TYPE: string;
@Column({
nullable: true,
type: "text",

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddCommandSalary1726455828396 implements MigrationInterface {
name = 'AddCommandSalary1726455828396'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`commandSalary\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อคำสั่ง', \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 1, \`commandSysId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง CommandSys', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`commandSalary\` ADD CONSTRAINT \`FK_52519043506061e558b992ba0dd\` FOREIGN KEY (\`commandSysId\`) REFERENCES \`commandSys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandSalary\` DROP FOREIGN KEY \`FK_52519043506061e558b992ba0dd\``);
await queryRunner.query(`DROP TABLE \`commandSalary\``);
}
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddCommandSalary1726474393379 implements MigrationInterface {
name = 'AddCommandSalary1726474393379'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`fileCover\` varchar(255) NULL COMMENT 'คำสั่งเรื่อง'`);
await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`fileAttachment\` varchar(255) NULL COMMENT 'คำสั่งเรื่อง'`);
// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``);
await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`fileAttachment\``);
await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`fileCover\``);
}
}

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateCommandTypeAddOrder1726479252659 implements MigrationInterface {
name = 'UpdateCommandTypeAddOrder1726479252659'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`order\` int NULL COMMENT 'ลำดับความสำคัญ'`);
// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``);
await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`order\``);
}
}