เพิ่ม commandcode

This commit is contained in:
kittapath 2025-03-08 00:46:01 +07:00
parent 2b0865ea9f
commit 76a2213cd8
3 changed files with 231 additions and 36 deletions

View file

@ -67,40 +67,40 @@ jobs:
docker compose pull
docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- name: Notify Discord Success
if: success()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "✅ Deployment Success!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
"color": 3066993,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/success-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
# - name: Notify Discord Success
# if: success()
# run: |
# curl -H "Content-Type: application/json" \
# -X POST \
# -d '{
# "embeds": [{
# "title": "✅ Deployment Success!",
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
# "color": 3066993,
# "footer": {
# "text": "Release Notification",
# "icon_url": "https://example.com/success-icon.png"
# },
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
# }]
# }' \
# ${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure
if: failure()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "❌ Deployment Failed!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
# - name: Notify Discord Failure
# if: failure()
# run: |
# curl -H "Content-Type: application/json" \
# -X POST \
# -d '{
# "embeds": [{
# "title": "❌ Deployment Failed!",
# "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
# "color": 15158332,
# "footer": {
# "text": "Release Notification",
# "icon_url": "https://example.com/failure-icon.png"
# },
# "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
# }]
# }' \
# ${{ secrets.DISCORD_WEBHOOK }}

View 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();
}
}

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