api ออกคำสั่ง

This commit is contained in:
kittapath 2024-10-01 23:33:45 +07:00
parent 566ac716ee
commit 000bc2aad9
3 changed files with 93 additions and 65 deletions

View file

@ -831,9 +831,9 @@ export class CommandController extends Controller {
}
/**
* API
* API
*
* @summary API
* @summary API
*
* @param {string} id Id
*/
@ -844,7 +844,10 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
const command = await this.commandRepository.findOne({ where: { id: id } });
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
@ -861,16 +864,25 @@ export class CommandController extends Controller {
) {
command.status = "WAITING";
} else {
let path = this.commandTypePath(command.commandType.name);
const path = this.commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
new CallAPI()
.PostData(request, path + "excecute", {
refIds: command.commandRecives.map((x) => x.refId),
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
commandAffectDate: command.commandAffectDate,
commandNo: command.commandNo,
commandYear: command.commandYear,
templateDoc: command.positionDetail,
})),
})
.then(async (res) => {})
.catch(() => {});
command.status = "REPORTED";
.catch((e) => {
command.status = "REPORTED";
});
}
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
@ -940,7 +952,7 @@ export class CommandController extends Controller {
}
let _command: any = [];
let path = this.commandTypePath(command.commandType.name);
const path = this.commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
new CallAPI()
@ -985,6 +997,7 @@ export class CommandController extends Controller {
@Request() request: RequestWithUser,
) {
let command = new Command();
let commandCode = null;
if (
requestBody.commandId != undefined &&
requestBody.commandId != null &&
@ -992,7 +1005,7 @@ export class CommandController extends Controller {
) {
const _command = await this.commandRepository.findOne({
where: { id: requestBody.commandId },
relations: ["commandRecives"],
relations: ["commandRecives", "commandType"],
order: {
commandRecives: {
order: "DESC",
@ -1002,6 +1015,7 @@ export class CommandController extends Controller {
if (!_command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบคำสั่งนี้ในระบบ");
}
commandCode = _command.commandType.code;
command = _command;
} else {
command = Object.assign(new Command(), requestBody);
@ -1012,6 +1026,7 @@ export class CommandController extends Controller {
if (!commandType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
}
commandCode = commandType.code;
command.detailHeader = commandType.detailHeader;
command.detailBody = commandType.detailBody;
command.detailFooter = commandType.detailFooter;
@ -1027,7 +1042,7 @@ export class CommandController extends Controller {
await this.commandRepository.save(command);
}
let path = this.commandTypePath(command.commandType.name);
const path = this.commandTypePath(commandCode);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
new CallAPI()
.PostData(request, path, {
@ -1066,94 +1081,92 @@ export class CommandController extends Controller {
return new HttpSuccess(command.id);
}
commandTypePath(commandType: string) {
let path = null;
switch (commandType) {
commandTypePath(commandCode: string) {
switch (commandCode) {
case "C-PM-01":
path = "/placemant/main/report/";
return "/placement/recruit/report/";
case "C-PM-02":
path = "/placemant/recive/report/";
return "/placemant/recruit/report/";
case "C-PM-03":
path = "/discipline/recive/report/";
return "/discipline/recive/report/";
case "C-PM-04":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-05":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-06":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-07":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-08":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-09":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-10":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-11":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-12":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-13":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-14":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-15":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-16":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-17":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-18":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-19":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-20":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-21":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-22":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-23":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-24":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-25":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-26":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-27":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-28":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-29":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-30":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-31":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-32":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-33":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-34":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-35":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-36":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-37":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-38":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-39":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-40":
path = "/xxxxxx/";
return "/xxxxxx/";
case "C-PM-41":
path = "/xxxxxx/";
return "/xxxxxx/";
default:
path = null;
return null;
}
return path;
}
}

View file

@ -1,11 +1,4 @@
import {
Entity,
Column,
OneToMany,
JoinColumn,
ManyToOne,
Double,
} from "typeorm";
import { Entity, Column, OneToMany, JoinColumn, ManyToOne, Double } from "typeorm";
import { EntityBase } from "./base/Base";
import { Profile } from "./Profile";
import { ProfileEmployee } from "./ProfileEmployee";
@ -174,7 +167,7 @@ export class CreateProfileSalary {
positionType: string | null;
positionLevel: string | null;
refCommandNo: string | null;
commandType?: string | null;
// commandType?: string | null;
templateDoc: string | null;
}

View file

@ -0,0 +1,22 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateProfileDevelopment11727795520589 implements MigrationInterface {
name = 'UpdateProfileDevelopment11727795520589'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP FOREIGN KEY \`FK_fb29bfd315d0d43d0b49b362995\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`org\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`position\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`profileId\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`refId\` varchar(40) NULL COMMENT 'refId'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`refId\``);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`org\` varchar(255) NULL COMMENT 'หน่วยงาน'`);
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD CONSTRAINT \`FK_fb29bfd315d0d43d0b49b362995\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
}