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