Migrate update_command_add_shortName #242
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m2s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m2s
This commit is contained in:
parent
136a4c562e
commit
81e8dadd9b
3 changed files with 108 additions and 22 deletions
|
|
@ -372,7 +372,7 @@ export class CommandController extends Controller {
|
||||||
|
|
||||||
const data = commands.map((_data) => ({
|
const data = commands.map((_data) => ({
|
||||||
id: _data.id,
|
id: _data.id,
|
||||||
commandNo: _data.commandNo,
|
commandNo: `${_data.shortName ?? ""} ${_data.commandNo}`.trim(),
|
||||||
commandYear: _data.commandYear,
|
commandYear: _data.commandYear,
|
||||||
commandAffectDate: _data.commandAffectDate,
|
commandAffectDate: _data.commandAffectDate,
|
||||||
commandExcecuteDate: _data.commandExcecuteDate,
|
commandExcecuteDate: _data.commandExcecuteDate,
|
||||||
|
|
@ -522,7 +522,7 @@ export class CommandController extends Controller {
|
||||||
const _command = {
|
const _command = {
|
||||||
id: command.id,
|
id: command.id,
|
||||||
status: command.status,
|
status: command.status,
|
||||||
commandNo: command.commandNo,
|
commandNo: `${command.shortName ?? ""} ${command.commandNo}`.trim(),
|
||||||
commandYear: command.commandYear,
|
commandYear: command.commandYear,
|
||||||
issue: command.issue,
|
issue: command.issue,
|
||||||
detailHeader: command.detailHeader,
|
detailHeader: command.detailHeader,
|
||||||
|
|
@ -572,6 +572,34 @@ export class CommandController extends Controller {
|
||||||
}
|
}
|
||||||
const data = new Command();
|
const data = new Command();
|
||||||
Object.assign(data, { ...command, ...requestBody });
|
Object.assign(data, { ...command, ...requestBody });
|
||||||
|
|
||||||
|
// ถ้าเป็น officer (isOfficer == true) ดึง orgRoot.shortName มาใช้
|
||||||
|
const userProfile = await this.profileRepository.findOne({
|
||||||
|
where: { keycloak: request.user.sub },
|
||||||
|
relations: {
|
||||||
|
current_holders: {
|
||||||
|
orgRevision: true,
|
||||||
|
orgRoot: true,
|
||||||
|
orgChild1: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (userProfile) {
|
||||||
|
const currentHolder = userProfile.current_holders?.find(
|
||||||
|
(x: any) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (currentHolder && currentHolder.orgChild1?.isOfficer) {
|
||||||
|
data.shortName =
|
||||||
|
requestBody.isBangkok && requestBody.isBangkok === "BANGKOK"
|
||||||
|
? "กทม."
|
||||||
|
: currentHolder.orgRoot?.orgRootShortName ?? "สนป.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data.lastUpdateUserId = request.user.sub;
|
data.lastUpdateUserId = request.user.sub;
|
||||||
data.lastUpdateFullName = request.user.name;
|
data.lastUpdateFullName = request.user.name;
|
||||||
data.lastUpdatedAt = new Date();
|
data.lastUpdatedAt = new Date();
|
||||||
|
|
@ -1982,7 +2010,7 @@ export class CommandController extends Controller {
|
||||||
if (!["C-PM-21", "C-PM-23"].includes(commandCode)) {
|
if (!["C-PM-21", "C-PM-23"].includes(commandCode)) {
|
||||||
_command = {
|
_command = {
|
||||||
issue: issue,
|
issue: issue,
|
||||||
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
|
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(`${command.shortName ?? ""} ${command.commandNo}`.trim()),
|
||||||
commandYear:
|
commandYear:
|
||||||
command.commandYear == null
|
command.commandYear == null
|
||||||
? ""
|
? ""
|
||||||
|
|
@ -2235,7 +2263,7 @@ export class CommandController extends Controller {
|
||||||
);
|
);
|
||||||
_command = {
|
_command = {
|
||||||
issue: issue,
|
issue: issue,
|
||||||
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
|
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(`${command.shortName ?? ""} ${command.commandNo}`.trim()),
|
||||||
commandYear:
|
commandYear:
|
||||||
command.commandYear == null
|
command.commandYear == null
|
||||||
? ""
|
? ""
|
||||||
|
|
@ -2374,7 +2402,7 @@ export class CommandController extends Controller {
|
||||||
data: {
|
data: {
|
||||||
data: _command,
|
data: _command,
|
||||||
issuerOrganizationName: issue,
|
issuerOrganizationName: issue,
|
||||||
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
|
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(`${command.shortName ?? ""} ${command.commandNo}`.trim()),
|
||||||
commandYear:
|
commandYear:
|
||||||
command.commandYear == null
|
command.commandYear == null
|
||||||
? ""
|
? ""
|
||||||
|
|
@ -2588,6 +2616,7 @@ export class CommandController extends Controller {
|
||||||
let command = new Command();
|
let command = new Command();
|
||||||
let commandCode: string = "";
|
let commandCode: string = "";
|
||||||
let _null: any = null;
|
let _null: any = null;
|
||||||
|
let userProfile: any = null;
|
||||||
if (
|
if (
|
||||||
requestBody.commandId != undefined &&
|
requestBody.commandId != undefined &&
|
||||||
requestBody.commandId != null &&
|
requestBody.commandId != null &&
|
||||||
|
|
@ -2647,15 +2676,9 @@ export class CommandController extends Controller {
|
||||||
command.lastUpdateUserId = request.user.sub;
|
command.lastUpdateUserId = request.user.sub;
|
||||||
command.lastUpdateFullName = request.user.name;
|
command.lastUpdateFullName = request.user.name;
|
||||||
command.lastUpdatedAt = now;
|
command.lastUpdatedAt = now;
|
||||||
await this.commandRepository.save(command);
|
|
||||||
}
|
// Query profile ครั้งเดียว ใช้ร่วมกันทั้ง shortName และ CommandOperator
|
||||||
// insert commandOperator
|
userProfile = await this.profileRepository.findOne({
|
||||||
const checkCommandOperator = await this.commandOperatorRepository.findOne({
|
|
||||||
where: { commandId: command.id, roleName: "เจ้าหน้าที่ดำเนินการ" },
|
|
||||||
});
|
|
||||||
if (!checkCommandOperator) {
|
|
||||||
if (request.user.sub) {
|
|
||||||
const profile = await this.profileRepository.findOne({
|
|
||||||
where: { keycloak: request.user.sub },
|
where: { keycloak: request.user.sub },
|
||||||
relations: {
|
relations: {
|
||||||
posLevel: true,
|
posLevel: true,
|
||||||
|
|
@ -2670,9 +2693,50 @@ export class CommandController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// เช็คถ้าไม่ใช่ กสจ. ดึง root.shortName มาปั๊ม
|
||||||
|
if (userProfile) {
|
||||||
|
const currentHolder = userProfile.current_holders?.find(
|
||||||
|
(x: any) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (currentHolder && !currentHolder.orgChild1?.isOfficer) {
|
||||||
|
command.shortName = currentHolder.orgRoot?.orgRootShortName ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.commandRepository.save(command);
|
||||||
|
}
|
||||||
|
// insert commandOperator
|
||||||
|
const checkCommandOperator = await this.commandOperatorRepository.findOne({
|
||||||
|
where: { commandId: command.id, roleName: "เจ้าหน้าที่ดำเนินการ" },
|
||||||
|
});
|
||||||
|
if (!checkCommandOperator) {
|
||||||
|
if (request.user.sub) {
|
||||||
|
// ใช้ userProfile ที่ query ไปแล้วถ้ามี ถ้าไม่มีค่อย query ใหม่
|
||||||
|
let profile = userProfile;
|
||||||
|
if (!profile) {
|
||||||
|
profile = await this.profileRepository.findOne({
|
||||||
|
where: { keycloak: request.user.sub },
|
||||||
|
relations: {
|
||||||
|
posLevel: true,
|
||||||
|
posType: true,
|
||||||
|
current_holders: {
|
||||||
|
orgRevision: true,
|
||||||
|
orgRoot: true,
|
||||||
|
orgChild1: true,
|
||||||
|
orgChild2: true,
|
||||||
|
orgChild3: true,
|
||||||
|
orgChild4: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
if (profile) {
|
if (profile) {
|
||||||
const currentHolder = profile!.current_holders?.find(
|
const currentHolder = profile!.current_holders?.find(
|
||||||
(x) =>
|
(x: any) =>
|
||||||
x.orgRevision?.orgRevisionIsDraft === false &&
|
x.orgRevision?.orgRevisionIsDraft === false &&
|
||||||
x.orgRevision?.orgRevisionIsCurrent === true,
|
x.orgRevision?.orgRevisionIsCurrent === true,
|
||||||
);
|
);
|
||||||
|
|
@ -8658,7 +8722,7 @@ export class CommandController extends Controller {
|
||||||
if (issue == null) issue = "...................................";
|
if (issue == null) issue = "...................................";
|
||||||
const _command = {
|
const _command = {
|
||||||
issue: issue,
|
issue: issue,
|
||||||
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
|
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(`${command.shortName ?? ""} ${command.commandNo}`.trim()),
|
||||||
commandYear:
|
commandYear:
|
||||||
command.commandYear == null
|
command.commandYear == null
|
||||||
? ""
|
? ""
|
||||||
|
|
@ -8763,7 +8827,7 @@ export class CommandController extends Controller {
|
||||||
data: {
|
data: {
|
||||||
data: _command,
|
data: _command,
|
||||||
issuerOrganizationName: issue,
|
issuerOrganizationName: issue,
|
||||||
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
|
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(`${command.shortName ?? ""} ${command.commandNo}`.trim()),
|
||||||
commandYear:
|
commandYear:
|
||||||
command.commandYear == null
|
command.commandYear == null
|
||||||
? ""
|
? ""
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,14 @@ export class Command extends EntityBase {
|
||||||
})
|
})
|
||||||
issue: string;
|
issue: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ชื่อย่อหน่วยงานที่ออกคำสั่ง",
|
||||||
|
length: 16,
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
shortName: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "เลขที่คำสั่ง",
|
comment: "เลขที่คำสั่ง",
|
||||||
|
|
|
||||||
14
src/migration/1779776860350-update_command_add_shortName.ts
Normal file
14
src/migration/1779776860350-update_command_add_shortName.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class UpdateCommandAddShortName1779776860350 implements MigrationInterface {
|
||||||
|
name = 'UpdateCommandAddShortName1779776860350'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`command\` ADD \`shortName\` varchar(16) NULL COMMENT 'ชื่อย่อหน่วยงานที่ออกคำสั่ง'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`command\` DROP COLUMN \`shortName\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue