เพิ่ม commandcode
This commit is contained in:
parent
2b0865ea9f
commit
76a2213cd8
3 changed files with 231 additions and 36 deletions
72
.github/workflows/release.yaml
vendored
72
.github/workflows/release.yaml
vendored
|
|
@ -67,40 +67,40 @@ jobs:
|
||||||
docker compose pull
|
docker compose pull
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
|
||||||
- name: Notify Discord Success
|
# - name: Notify Discord Success
|
||||||
if: success()
|
# if: success()
|
||||||
run: |
|
# run: |
|
||||||
curl -H "Content-Type: application/json" \
|
# curl -H "Content-Type: application/json" \
|
||||||
-X POST \
|
# -X POST \
|
||||||
-d '{
|
# -d '{
|
||||||
"embeds": [{
|
# "embeds": [{
|
||||||
"title": "✅ Deployment Success!",
|
# "title": "✅ Deployment Success!",
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
|
||||||
"color": 3066993,
|
# "color": 3066993,
|
||||||
"footer": {
|
# "footer": {
|
||||||
"text": "Release Notification",
|
# "text": "Release Notification",
|
||||||
"icon_url": "https://example.com/success-icon.png"
|
# "icon_url": "https://example.com/success-icon.png"
|
||||||
},
|
# },
|
||||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
}]
|
# }]
|
||||||
}' \
|
# }' \
|
||||||
${{ secrets.DISCORD_WEBHOOK }}
|
# ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
||||||
- name: Notify Discord Failure
|
# - name: Notify Discord Failure
|
||||||
if: failure()
|
# if: failure()
|
||||||
run: |
|
# run: |
|
||||||
curl -H "Content-Type: application/json" \
|
# curl -H "Content-Type: application/json" \
|
||||||
-X POST \
|
# -X POST \
|
||||||
-d '{
|
# -d '{
|
||||||
"embeds": [{
|
# "embeds": [{
|
||||||
"title": "❌ Deployment Failed!",
|
# "title": "❌ Deployment Failed!",
|
||||||
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
|
||||||
"color": 15158332,
|
# "color": 15158332,
|
||||||
"footer": {
|
# "footer": {
|
||||||
"text": "Release Notification",
|
# "text": "Release Notification",
|
||||||
"icon_url": "https://example.com/failure-icon.png"
|
# "icon_url": "https://example.com/failure-icon.png"
|
||||||
},
|
# },
|
||||||
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
|
||||||
}]
|
# }]
|
||||||
}' \
|
# }' \
|
||||||
${{ secrets.DISCORD_WEBHOOK }}
|
# ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
|
|
||||||
165
src/controllers/CommandCodeController.ts
Normal file
165
src/controllers/CommandCodeController.ts
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
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 { Not } from "typeorm";
|
||||||
|
import { setLogDataDiff } from "../interfaces/utils";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import { CommandCode, CreateCommandCode, UpdateCommandCode } from "../entities/CommandCode";
|
||||||
|
|
||||||
|
@Route("api/v1/org/metadata/commandCode")
|
||||||
|
@Tags("CommandCode")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
export class CommandCodeController extends Controller {
|
||||||
|
private commandCodeRepository = AppDataSource.getRepository(CommandCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API list รายการเชื่อมโยงคำสั่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เชื่อมโยงคำสั่ง (ADMIN) #62
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async GetResult() {
|
||||||
|
const _commandCode = await this.commandCodeRepository.find({
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"code",
|
||||||
|
"createdAt",
|
||||||
|
"lastUpdatedAt",
|
||||||
|
"createdFullName",
|
||||||
|
"lastUpdateFullName",
|
||||||
|
],
|
||||||
|
order: { code: "ASC" },
|
||||||
|
});
|
||||||
|
return new HttpSuccess(_commandCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการเชื่อมโยงคำสั่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เชื่อมโยงคำสั่ง (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เชื่อมโยงคำสั่ง
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async GetById(@Path() id: string) {
|
||||||
|
const _commandCode = await this.commandCodeRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name", "code"],
|
||||||
|
});
|
||||||
|
if (!_commandCode) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงคำสั่งนี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess(_commandCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างรายการ body เชื่อมโยงคำสั่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เชื่อมโยงคำสั่ง (ADMIN) #62
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async Post(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateCommandCode,
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
const _commandCode = Object.assign(new CommandCode(), requestBody);
|
||||||
|
if (!_commandCode) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงคำสั่งนี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.commandCodeRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
const before = null;
|
||||||
|
_commandCode.createdUserId = request.user.sub;
|
||||||
|
_commandCode.createdFullName = request.user.name;
|
||||||
|
_commandCode.lastUpdateUserId = request.user.sub;
|
||||||
|
_commandCode.lastUpdateFullName = request.user.name;
|
||||||
|
_commandCode.createdAt = new Date();
|
||||||
|
_commandCode.lastUpdatedAt = new Date();
|
||||||
|
await this.commandCodeRepository.save(_commandCode, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: _commandCode });
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขรายการ body เชื่อมโยงคำสั่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เชื่อมโยงคำสั่ง (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เชื่อมโยงคำสั่ง
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async Put(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: UpdateCommandCode,
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
) {
|
||||||
|
const _commandCode = await this.commandCodeRepository.findOne({ where: { id: id } });
|
||||||
|
if (!_commandCode) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงคำสั่งนี้");
|
||||||
|
}
|
||||||
|
const checkName = await this.commandCodeRepository.findOne({
|
||||||
|
where: { id: Not(id), name: requestBody.name },
|
||||||
|
});
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
const before = structuredClone(_commandCode);
|
||||||
|
_commandCode.lastUpdateUserId = request.user.sub;
|
||||||
|
_commandCode.lastUpdateFullName = request.user.name;
|
||||||
|
_commandCode.lastUpdatedAt = new Date();
|
||||||
|
this.commandCodeRepository.merge(_commandCode, requestBody);
|
||||||
|
await this.commandCodeRepository.save(_commandCode, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: _commandCode });
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบรายการเชื่อมโยงคำสั่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เชื่อมโยงคำสั่ง (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เชื่อมโยงคำสั่ง
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
|
const _delCommandCode = await this.commandCodeRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!_delCommandCode) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเชื่อมโยงคำสั่งนี้");
|
||||||
|
}
|
||||||
|
await this.commandCodeRepository.remove(_delCommandCode, { data: request });
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/entities/CommandCode.ts
Normal file
30
src/entities/CommandCode.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { Entity, Column } from "typeorm";
|
||||||
|
import { EntityBase } from "./base/Base";
|
||||||
|
|
||||||
|
@Entity("commandCode")
|
||||||
|
export class CommandCode extends EntityBase {
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "คำสั่ง",
|
||||||
|
length: 255,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "HRMS Id",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
code: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateCommandCode {
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
code: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateCommandCode = Partial<CreateCommandCode>;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue