เพิ่มตำแหน่งเจ้าหน้าที่
This commit is contained in:
parent
3b0d8c24a7
commit
6f11eecb8f
15 changed files with 771 additions and 33 deletions
144
src/controllers/CommandSysController.ts
Normal file
144
src/controllers/CommandSysController.ts
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Get,
|
||||
} 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 { CommandSys, CreateCommandSys, UpdateCommandSys } from "../entities/CommandSys";
|
||||
|
||||
@Route("api/v1/org/commandSys")
|
||||
@Tags("CommandSys")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class CommandSysController extends Controller {
|
||||
private commandSysRepository = AppDataSource.getRepository(CommandSys);
|
||||
|
||||
/**
|
||||
* API list รายการระบบคำสั่ง
|
||||
*
|
||||
* @summary ORG_058 - CRUD ระบบคำสั่ง (ADMIN) #62
|
||||
*
|
||||
*/
|
||||
@Get("list")
|
||||
async GetResult() {
|
||||
const _commandSys = await this.commandSysRepository.find({
|
||||
select: ["id", "sysName", "sysDescription", "createdAt", "lastUpdatedAt", "createdFullName", "lastUpdateFullName"],
|
||||
order: { id: "ASC" },
|
||||
});
|
||||
return new HttpSuccess(_commandSys);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการระบบคำสั่ง
|
||||
*
|
||||
* @summary ORG_058 - CRUD ระบบคำสั่ง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id ระบบคำสั่ง
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetById(@Path() id: string) {
|
||||
const _commandSys = await this.commandSysRepository.findOne({
|
||||
where: { id },
|
||||
select: ["id", "sysName", "sysDescription"],
|
||||
});
|
||||
if (!_commandSys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระบบคำสั่งนี้");
|
||||
}
|
||||
|
||||
return new HttpSuccess(_commandSys);
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้างรายการ body ระบบคำสั่ง
|
||||
*
|
||||
* @summary ORG_058 - CRUD ระบบคำสั่ง (ADMIN) #62
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateCommandSys,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const _commandSys = Object.assign(new CommandSys(), requestBody);
|
||||
const checkName = await this.commandSysRepository.findOne({
|
||||
where: { id: requestBody.id,sysName: requestBody.sysName,sysDescription: requestBody.sysDescription },
|
||||
});
|
||||
|
||||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
_commandSys.createdUserId = request.user.sub;
|
||||
_commandSys.createdFullName = request.user.name;
|
||||
_commandSys.lastUpdateUserId = request.user.sub;
|
||||
_commandSys.lastUpdateFullName = request.user.name;
|
||||
_commandSys.createdAt = new Date();
|
||||
_commandSys.lastUpdatedAt = new Date();
|
||||
await this.commandSysRepository.save(_commandSys);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรายการ body ระบบคำสั่ง
|
||||
*
|
||||
* @summary ORG_058 - CRUD ระบบคำสั่ง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id ระบบคำสั่ง
|
||||
*/
|
||||
@Put("{id}")
|
||||
async Put(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateCommandSys,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const _commandSys = await this.commandSysRepository.findOne({ where: { id: id } });
|
||||
if (!_commandSys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระบบคำสั่งนี้");
|
||||
}
|
||||
|
||||
_commandSys.lastUpdateUserId = request.user.sub;
|
||||
_commandSys.lastUpdateFullName = request.user.name;
|
||||
_commandSys.lastUpdatedAt = new Date();
|
||||
this.commandSysRepository.merge(_commandSys, requestBody);
|
||||
await this.commandSysRepository.save(_commandSys);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบรายการระบบคำสั่ง
|
||||
*
|
||||
* @summary ORG_058 - CRUD ระบบคำสั่ง (ADMIN) #62
|
||||
*
|
||||
* @param {string} id Id ระบบคำสั่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
const _delCommandSys = await this.commandSysRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!_delCommandSys) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระบบคำสั่งนี้");
|
||||
}
|
||||
await this.commandSysRepository.delete(_delCommandSys.id);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue