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

View file

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