Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-17 16:40:35 +07:00
commit bd3cb33a5e
8 changed files with 316 additions and 84 deletions

View file

@ -1,23 +1,34 @@
AUTH_REALM_URL=https://id.frappet.synology.me/realms/bma-ehr AUTH_REALM_URL=https://id.frappet.synology.me/realms/bma-ehr
AUTH_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvYg0ZJvH6HgNOzyPp7PCvY3bJwD9WdsNn6gZbuvIfqJQZ8iSH1t0p3fgODO/fqwcj9UFeh1bVFOSjuW+JpnPehROqzt81KNl9zLLNXoN4LimReQHaMM3dU7DCbRylgVCouIDvObyjg8G+Cy5lZvFKWym/DPwGVpSdbvDZJ83qxq2dp7GJXS8PhOvA+MB1K009/jW5pBTUwNArLjoFccr+gIYIiOJDg2rYyIF3fDkwyWkuxr6xRt10+BRJytselwy/18kbDuJxVPaapdgTXI6wLzx7HWcDk30n5EvhJEumnIPpRst8gucqNYmB4MH+vsyoxV5WLuO3qmVRzFbtAppRQIDAQAB AUTH_PUBLIC_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1/QAH75nWgiRzWCTrGJv8q2A7z0qggC2IQ9Sva/Ok1RxeGE/ED2m4ELbF5B9MtugyXYGMUBXaKhooMpTE3wyR1OwsUlv/GtYSmMuKUnsSEXklsP8nIq8gZkCvISOVdvIC4ng5aZ5nBcp9cQ3eVbz4dfZcbLzcqLIIkxQmFBK0m1eFL5IdNj8Ac7U4eH4ylOckOu174f35NnFH6wDva6Iic3EXapMcE2BnXXCTajk2dmlWAzH13ybQBgHDfrOtulrmn1CzQxe9WUJes4qX5z72N05KsHvtUObaeN6cb+mIeH36GdysqgAdd2hhKkgUFXwtLPzldtrEc7xVyf3OLEg1QIDAQAB
AUTH_PREFERRED_MODE=online AUTH_PREFERRED_MODE=online
AUTH_ACCOUNT_SECRET=qsFwDb5anVoXKKwoeivrByIn9VYWQNRn AUTH_ACCOUNT_SECRET=qsFwDb5anVoXKKwoeivrByIn9VYWQNRn
APP_HOST=0.0.0.0 APP_HOST=0.0.0.0
APP_PORT=13001 APP_PORT=3001
DB_HOST=192.168.1.80
DB_PORT=3306 DB_HOST=192.168.1.81
DB_PORT=4063
DB_USERNAME=root DB_USERNAME=root
DB_PASSWORD=adminVM123 DB_PASSWORD=adminVM123
DB_NAME=bma_ehr_organization_demo DB_NAME=bma_ehr_organization
# DB_HOST=192.168.1.81
# DB_PORT=4063
# DB_USERNAME=root
# DB_PASSWORD=adminVM123
# DB_NAME=bma_ehr_organization
KC_URL=https://id.frappet.synology.me KC_URL=https://id.frappet.synology.me
KC_REALM=bma-ehr KC_REALM=bma-ehr
KC_SERVICE_ACCOUNT_CLIENT_ID=bma-ehr-dev KC_SERVICE_ACCOUNT_CLIENT_ID=bma-ehr-dev
KC_SERVICE_ACCOUNT_SECRET=f2mp7Xj4nz6gbgITve9J7AHXZI8dRhOd KC_SERVICE_ACCOUNT_SECRET=f2mp7Xj4nz6gbgITve9J7AHXZI8dRhOd
API_URL=https://bma-ehr.frappet.synology.me/api/v1 API_URL=https://bma-ehr.frappet.synology.me/api/v1
REDIS_HOST=192.168.1.81
REDIS_PORT=6379
ELASTICSEARCH_INDEX=bma-ehr-log-index ELASTICSEARCH_INDEX=bma-ehr-log-index
ELASTICSEARCH_PROTOCOL=http ELASTICSEARCH_PROTOCOL=http
ELASTICSEARCH_HOST=192.168.1.40 ELASTICSEARCH_HOST=192.168.1.90
ELASTICSEARCH_PORT=9200 ELASTICSEARCH_PORT=9200
REDIS_HOST=192.168.1.81
REDIS_PORT=6379
API_KEY=fKRL16yyEgbyTEJdsMw2h64tGSCmkW685PRtM3CygzX1JOSdptT9UJtpgWwKM8FybRTJups3GTFwj27ZRvlPdIkv3XgCoVJaD5LmR06ozuEPvCCRSdp2WFthg08V5xHc56fTPfZLpr1VmXrhd6dvYhHIqKkQUJR02Rlkss11cLRWEQOssEFVA4xdu2J5DIRO1EM5m7wRRvEwcDB4mYRXD9HH52SMq6iYqUWEWsMwLdbk7QW9yYESUEuzMW5gWrb6vIeWZxJV5bTz1PcWUyR7eO9Fyw1F5DiQYc9JgzTC1mW7cv31fEtTtrfbJYKIb5EbWilqIEUKC6A0UKBDDek35ML0006cqRVm0pvdOH6jeq7VQyYrhdXe59dBEyhYGUIfozoVBvW7Up4QBuOMjyPjSqJPlMBKwaseptfrblxQV1AOOivSBpf1ZcQyOZ8JktRtKUDSuXsmG0lsXwFlI3JCeSHdpVdgZWFYcJPegqfrB6KotR02t9AVkpLs1ZWrixwz API_KEY=fKRL16yyEgbyTEJdsMw2h64tGSCmkW685PRtM3CygzX1JOSdptT9UJtpgWwKM8FybRTJups3GTFwj27ZRvlPdIkv3XgCoVJaD5LmR06ozuEPvCCRSdp2WFthg08V5xHc56fTPfZLpr1VmXrhd6dvYhHIqKkQUJR02Rlkss11cLRWEQOssEFVA4xdu2J5DIRO1EM5m7wRRvEwcDB4mYRXD9HH52SMq6iYqUWEWsMwLdbk7QW9yYESUEuzMW5gWrb6vIeWZxJV5bTz1PcWUyR7eO9Fyw1F5DiQYc9JgzTC1mW7cv31fEtTtrfbJYKIb5EbWilqIEUKC6A0UKBDDek35ML0006cqRVm0pvdOH6jeq7VQyYrhdXe59dBEyhYGUIfozoVBvW7Up4QBuOMjyPjSqJPlMBKwaseptfrblxQV1AOOivSBpf1ZcQyOZ8JktRtKUDSuXsmG0lsXwFlI3JCeSHdpVdgZWFYcJPegqfrB6KotR02t9AVkpLs1ZWrixwz

View file

@ -19,7 +19,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Command } from "../entities/Command"; import { Command } from "../entities/Command";
import { Brackets, LessThan, MoreThan, Double, In, Not ,Between } from "typeorm"; import { Brackets, LessThan, MoreThan, Double, In, Not, Between } from "typeorm";
import { CommandType } from "../entities/CommandType"; import { CommandType } from "../entities/CommandType";
import { CommandSend } from "../entities/CommandSend"; import { CommandSend } from "../entities/CommandSend";
import { Profile, CreateProfileAllFields } from "../entities/Profile"; import { Profile, CreateProfileAllFields } from "../entities/Profile";
@ -262,7 +262,7 @@ export class CommandController extends Controller {
commandYear: _data.commandYear, commandYear: _data.commandYear,
commandAffectDate: _data.commandAffectDate, commandAffectDate: _data.commandAffectDate,
commandExcecuteDate: _data.commandExcecuteDate, commandExcecuteDate: _data.commandExcecuteDate,
assignFullName: _data.createdFullName, assignFullName: null, //xxxxxxxxxxxxxxx
createdFullName: _data.createdFullName, createdFullName: _data.createdFullName,
status: _data.status, status: _data.status,
issue: _data.issue, issue: _data.issue,
@ -1013,11 +1013,10 @@ export class CommandController extends Controller {
if (command.commandExcecuteDate == null) if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
let profiles = command && command.commandRecives.length > 0 let profiles =
? command.commandRecives command && command.commandRecives.length > 0
.filter((x) => x.profileId != null) ? command.commandRecives.filter((x) => x.profileId != null).map((x) => x.profileId)
.map((x) => x.profileId) : [];
: [];
await new CallAPI() await new CallAPI()
.PostData(request, "/placement/noti/profiles", { .PostData(request, "/placement/noti/profiles", {
@ -1073,12 +1072,12 @@ export class CommandController extends Controller {
const command = await this.commandRepository.find({ const command = await this.commandRepository.find({
relations: ["commandType", "commandRecives"], relations: ["commandType", "commandRecives"],
where:{ where: {
commandExcecuteDate: Between(today, tomorrow), commandExcecuteDate: Between(today, tomorrow),
status: "WAITING" status: "WAITING",
} },
}); });
const data = { const data = {
client_id: "gettoken", client_id: "gettoken",
client_secret: process.env.AUTH_ACCOUNT_SECRET, client_secret: process.env.AUTH_ACCOUNT_SECRET,
@ -1100,27 +1099,27 @@ export class CommandController extends Controller {
]); ]);
if (_data == null) { if (_data == null) {
return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง"); return new HttpError(HttpStatus.UNAUTHORIZED, "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง");
} }
command.forEach(async (x) => { command.forEach(async (x) => {
const path = this.commandTypePath(x.commandType.code); const path = this.commandTypePath(x.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = { const msg = {
data: { data: {
id: x.id, id: x.id,
status: "REPORTED", status: "REPORTED",
lastUpdateUserId: "system", lastUpdateUserId: "system",
lastUpdateFullName: "system", lastUpdateFullName: "system",
// lastUpdateUserId: _data.user.sub, // lastUpdateUserId: _data.user.sub,
// lastUpdateFullName: _data.user.name, // lastUpdateFullName: _data.user.name,
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}, },
user: _data.user, user: _data.user,
token: _data.access_token, token: _data.access_token,
}; };
sendToQueue(msg); sendToQueue(msg);
}) });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -2286,7 +2285,7 @@ export class CommandController extends Controller {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName, firstName: profile.firstName,
lastName: profile.lastName, lastName: profile.lastName,
email: profile.email, // email: profile.email,
}); });
if (typeof userKeycloakId !== "string") { if (typeof userKeycloakId !== "string") {
throw new Error(userKeycloakId.errorMessage); throw new Error(userKeycloakId.errorMessage);
@ -2305,6 +2304,7 @@ export class CommandController extends Controller {
); );
if (!result) throw new Error("Failed. Cannot set user's role."); if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = userKeycloakId; profile.keycloak = userKeycloakId;
profile.email = item.bodyProfile.email;
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile }); setLogDataDiff(req, { before, after: profile });
} }
@ -2773,7 +2773,7 @@ export class CommandController extends Controller {
case "C-PM-05": case "C-PM-05":
return "/placement/appointment/appoint/report"; return "/placement/appointment/appoint/report";
case "C-PM-06": case "C-PM-06":
return "/placement/appointment/slip/report"; return "/placement/slip/report";
case "C-PM-07": case "C-PM-07":
return "/placement/appointment/move/report"; return "/placement/appointment/move/report";
case "C-PM-08": case "C-PM-08":
@ -2781,7 +2781,7 @@ export class CommandController extends Controller {
case "C-PM-09": case "C-PM-09":
return "/retirement/other/out/report"; return "/retirement/other/out/report";
case "C-PM-10": case "C-PM-10":
return "/xxxxxx"; return "/probation/report/command10/officer/report";
case "C-PM-11": case "C-PM-11":
return "/probation/report/command11/officer/report"; return "/probation/report/command11/officer/report";
case "C-PM-12": case "C-PM-12":
@ -2839,7 +2839,7 @@ export class CommandController extends Controller {
case "C-PM-38": case "C-PM-38":
return "/org/command/command38/officer/report"; return "/org/command/command38/officer/report";
case "C-PM-39": case "C-PM-39":
return "/placement/slip/report"; return "/placement/appointment/slip/report";
case "C-PM-40": case "C-PM-40":
return "/org/command/command40/officer/report"; return "/org/command/command40/officer/report";
case "C-PM-41": case "C-PM-41":

View file

@ -3,13 +3,25 @@ import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags
import { DateTime } from "@elastic/elasticsearch/lib/api/types"; import { DateTime } from "@elastic/elasticsearch/lib/api/types";
import { Double } from "typeorm"; import { Double } from "typeorm";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { OrgRevision } from "../entities/OrgRevision";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
interface DPISResponse { interface DPISResponse {
/**
*
*/
status: number; status: number;
/**
*
*/
message: string; message: string;
/**
*
*/
result?: DPISResult; result?: DPISResult;
} }
@ -33,6 +45,7 @@ interface DPISResult {
educations: ProfileEducationResult[]; educations: ProfileEducationResult[];
leaves: ProfileLeaveResult[]; leaves: ProfileLeaveResult[];
salaries: ProfileSalaryResult[]; salaries: ProfileSalaryResult[];
organization: ProfileOrgResult;
} }
interface ProfileLeaveResult { interface ProfileLeaveResult {
@ -42,6 +55,33 @@ interface ProfileLeaveResult {
totalLeave: number; totalLeave: number;
} }
interface ProfileOrgResult {
/**
*
*/
orgRootName: string;
/**
* 1
*/
orgChild1Name: string;
/**
* 2
*/
orgChild2Name: string;
/**
* 3
*/
orgChild3Name: string;
/**
* 4
*/
orgChild4Name: string;
}
interface ProfileEducationResult { interface ProfileEducationResult {
country: string; country: string;
degree: string; degree: string;
@ -70,6 +110,7 @@ interface ProfileSalaryResult {
@SuccessResponse(HttpStatus.OK, "สำเร็จ") @SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class DPISController extends Controller { export class DPISController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile); private profileRepo = AppDataSource.getRepository(Profile);
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
/** /**
* *
@ -101,6 +142,13 @@ export class DPISController extends Controller {
leaveReason: null, leaveReason: null,
positionLevel: "ปฏิบัติงาน", positionLevel: "ปฏิบัติงาน",
positionType: "ทั่วไป", positionType: "ทั่วไป",
organization: {
orgRootName: "",
orgChild1Name: "",
orgChild2Name: "",
orgChild3Name: "",
orgChild4Name: "",
},
educations: [], educations: [],
salaries: [ salaries: [
{ {
@ -144,8 +192,10 @@ export class DPISController extends Controller {
profileSalary: true, profileSalary: true,
profileEducations: true, profileEducations: true,
profileLeaves: true, profileLeaves: true,
current_holders: true,
}, },
where: { citizenId: citizenId }, where: { citizenId: citizenId },
//relations: ["current_holders", "current_holders.orgRoot"],
order: { order: {
profileSalary: { profileSalary: {
date: "DESC", date: "DESC",
@ -159,6 +209,10 @@ export class DPISController extends Controller {
}, },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
var current_holder = profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id);
const mapProfile: DPISResult = { const mapProfile: DPISResult = {
citizenId: profile.citizenId, citizenId: profile.citizenId,
@ -178,6 +232,14 @@ export class DPISController extends Controller {
positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "", positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "",
positionType: profile.posType ? profile.posType.posTypeName : "", positionType: profile.posType ? profile.posType.posTypeName : "",
organization: {
orgRootName: current_holder?.orgRoot?.orgRootName || "",
orgChild1Name: current_holder?.orgChild1?.orgChild1Name || "",
orgChild2Name: current_holder?.orgChild2?.orgChild2Name || "",
orgChild3Name: current_holder?.orgChild3?.orgChild3Name || "",
orgChild4Name: current_holder?.orgChild4?.orgChild4Name || "",
},
// educations // educations
educations: profile.profileEducations.map((item) => { educations: profile.profileEducations.map((item) => {
return { return {

View file

@ -3514,10 +3514,10 @@ export class ProfileController extends Controller {
}, },
relations: ["orgChild1"], relations: ["orgChild1"],
}); });
if (posMasters == null || posMasters.orgRoot == null) { if (posMasters == null || posMasters.orgChild1 == null) {
return new HttpSuccess(false); return new HttpSuccess(false);
} }
return new HttpSuccess(posMasters); return new HttpSuccess(posMasters.orgChild1.isOfficer);
} }
/** /**
@ -3978,12 +3978,18 @@ export class ProfileController extends Controller {
// await new permission().PermissionOrgUserGet(request, "SYS_REGISTRY_OFFICER", id);//ไม่แน่ใจOFFปิดไว้ก่อน // await new permission().PermissionOrgUserGet(request, "SYS_REGISTRY_OFFICER", id);//ไม่แน่ใจOFFปิดไว้ก่อน
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: id }, where: { id: id },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot", "profileSalary"], relations: [
"posLevel",
"posType",
"current_holders",
"current_holders.orgRoot",
"profileSalary",
],
order: { order: {
profileSalary: { profileSalary: {
order: "DESC", order: "DESC",
} },
} },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");

View file

@ -1,4 +1,4 @@
import { Body, Controller, Post, Request, Route, Security, Tags } from "tsoa"; import { Body, Controller, Get, Path, Post, Request, Route, Security, Tags } from "tsoa";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
@ -14,6 +14,8 @@ import { StateUserComment } from "../entities/StateUserComment";
import { MetaWorkflow } from "../entities/MetaWorkflow"; import { MetaWorkflow } from "../entities/MetaWorkflow";
import { MetaState } from "../entities/MetaState"; import { MetaState } from "../entities/MetaState";
import { MetaStateOperator } from "../entities/MetaStateOperator"; import { MetaStateOperator } from "../entities/MetaStateOperator";
import { PosMaster } from "../entities/PosMaster";
import { IsNull, Not } from "typeorm";
@Route("api/v1/org/workflow") @Route("api/v1/org/workflow")
@Tags("Workflow") @Tags("Workflow")
@ -29,6 +31,7 @@ export class WorkflowController extends Controller {
private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow); private metaWorkflowRepo = AppDataSource.getRepository(MetaWorkflow);
private metaStateRepo = AppDataSource.getRepository(MetaState); private metaStateRepo = AppDataSource.getRepository(MetaState);
private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator); private metaStateOperatorRepo = AppDataSource.getRepository(MetaStateOperator);
private posMasterRepo = AppDataSource.getRepository(PosMaster);
@Post("add-workflow") @Post("add-workflow")
public async checkWorkflow( public async checkWorkflow(
@ -66,12 +69,19 @@ export class WorkflowController extends Controller {
lastUpdatedAt: new Date(), lastUpdatedAt: new Date(),
}; };
const workflow = new Workflow(); const workflow = new Workflow();
Object.assign(workflow, { ...metaWorkflow, id: undefined, ...meta }); Object.assign(workflow, {
this.workflowRepo.save(workflow); ...metaWorkflow,
id: undefined,
...meta,
...body,
system: body.sysName,
});
await this.workflowRepo.save(workflow);
const metaState = await this.metaStateRepo.find({ const metaState = await this.metaStateRepo.find({
where: { where: {
metaWorkflowId: metaWorkflow.id, metaWorkflowId: metaWorkflow.id,
}, },
order: { order: "ASC" },
}); });
await Promise.all( await Promise.all(
@ -79,15 +89,19 @@ export class WorkflowController extends Controller {
const state = new State(); const state = new State();
Object.assign(state, { ...item, id: undefined, workflowId: workflow.id, ...meta }); Object.assign(state, { ...item, id: undefined, workflowId: workflow.id, ...meta });
await this.stateRepo.save(state); await this.stateRepo.save(state);
if (state.order == 1) {
workflow.stateId = state.id;
await this.workflowRepo.save(workflow);
}
const metaStateOperator = await this.metaStateOperatorRepo.find({ const metaStateOperator = await this.metaStateOperatorRepo.find({
where: { where: {
metaStateId: item.id, metaStateId: item.id,
}, },
}); });
await Promise.all( await Promise.all(
metaStateOperator.map(async (item) => { metaStateOperator.map(async (item1) => {
const stateOperator = new StateOperator(); const stateOperator = new StateOperator();
Object.assign(stateOperator, { ...item, id: undefined, stateId: state.id, ...meta }); Object.assign(stateOperator, { ...item1, id: undefined, stateId: state.id, ...meta });
await this.stateOperatorRepo.save(stateOperator); await this.stateOperatorRepo.save(stateOperator);
}), }),
); );
@ -97,12 +111,46 @@ export class WorkflowController extends Controller {
const stateOperatorUser = new StateOperatorUser(); const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, { Object.assign(stateOperatorUser, {
profileId: profile.id, profileId: profile.id,
operator: "OWNER", operator: "Owner",
order: 1, order: 1,
workflowId: workflow.id, workflowId: workflow.id,
...meta, ...meta,
}); });
await this.stateOperatorUserRepo.save(stateOperatorUser); await this.stateOperatorUserRepo.save(stateOperatorUser);
const profileOfficer = await this.posMasterRepo.find({
where: {
posMasterAssigns: { assignId: body.sysName },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
relations: ["orgChild1"],
});
await Promise.all(
profileOfficer.map(async (item, i) => {
if (item.orgChild1 == null || item.orgChild1.isOfficer == false) {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: item.current_holderId,
operator: "Officer",
order: i + 2,
workflowId: workflow.id,
...meta,
});
await this.stateOperatorUserRepo.save(stateOperatorUser);
} else {
const stateOperatorUser = new StateOperatorUser();
Object.assign(stateOperatorUser, {
profileId: item.current_holderId,
operator: "PersonnelOfficer",
order: i + 2,
workflowId: workflow.id,
...meta,
});
await this.stateOperatorUserRepo.save(stateOperatorUser);
}
}),
);
return new HttpSuccess(); return new HttpSuccess();
} }
@ -174,7 +222,7 @@ export class WorkflowController extends Controller {
const workflow = await this.workflowRepo.findOne({ const workflow = await this.workflowRepo.findOne({
where: { where: {
refId: body.refId, refId: body.refId,
system: body.system, sysName: body.system,
}, },
relations: ["stateOperatorUsers"], relations: ["stateOperatorUsers"],
}); });
@ -207,7 +255,7 @@ export class WorkflowController extends Controller {
where: { where: {
workflow: { workflow: {
refId: body.refId, refId: body.refId,
system: body.system, sysName: body.system,
}, },
profile: { profile: {
keycloak: req.user.sub, keycloak: req.user.sub,
@ -217,7 +265,6 @@ export class WorkflowController extends Controller {
}); });
if (!stateOperatorUser) if (!stateOperatorUser)
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้");
const operator = await this.stateOperatorRepo.findOne({ const operator = await this.stateOperatorRepo.findOne({
where: { where: {
operator: stateOperatorUser.operator, operator: stateOperatorUser.operator,
@ -225,8 +272,25 @@ export class WorkflowController extends Controller {
}, },
relations: ["state"], relations: ["state"],
}); });
if (!operator) if (!operator) {
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในขั้นตอนนี้"); const state = await this.stateRepo.findOne({
where: {
id: stateOperatorUser.workflow.stateId,
},
});
return new HttpSuccess({
stateId: state?.id || null,
stateNo: state?.order || null,
stateName: state?.name || null,
operator: stateOperatorUser.operator,
can_view: false,
can_update: false,
can_operate: false,
can_change_state: false,
can_delete: false,
can_cancel: false,
});
}
return new HttpSuccess({ return new HttpSuccess({
stateId: operator.state.id, stateId: operator.state.id,
stateNo: operator.state.order, stateNo: operator.state.order,
@ -254,17 +318,29 @@ export class WorkflowController extends Controller {
where: { where: {
workflow: { workflow: {
refId: body.refId, refId: body.refId,
system: body.system, sysName: body.system,
}, },
}, },
order: { order: "ASC", stateUserComments: { order: "ASC" } }, order: { order: "ASC", stateUserComments: { order: "ASC" } },
relations: ["stateUserComments"], relations: ["stateUserComments", "stateUserComments.profile"],
}); });
const _state = state.map((x) => ({ const _state = state.map((x) => ({
stateId: x.id, stateId: x.id,
stateNo: x.order, stateNo: x.order,
stateName: x.name, stateName: x.name,
stateUserComments: x.stateUserComments, stateUserComments: x.stateUserComments.map((x) => ({
id: x.id,
prefix: x.profile.prefix,
firstName: x.profile.firstName,
lastName: x.profile.lastName,
profileId: x.profileId,
isAcceptSetting: x.isAcceptSetting,
isApproveSetting: x.isApproveSetting,
isReasonSetting: x.isReasonSetting,
isAccept: x.isAccept,
isApprove: x.isApprove,
reason: x.reason,
})),
})); }));
return new HttpSuccess(_state); return new HttpSuccess(_state);
} }
@ -278,24 +354,35 @@ export class WorkflowController extends Controller {
system: string; system: string;
}, },
) { ) {
const stateOperatorUser = await this.stateOperatorUserRepo.findOne({ const stateOperatorUserNow = await this.stateOperatorUserRepo.findOne({
where: { where: {
workflow: { workflow: {
refId: body.refId, refId: body.refId,
system: body.system, sysName: body.system,
}, },
profile: { profile: {
keycloak: req.user.sub, keycloak: req.user.sub,
}, },
}, },
}); });
if (!stateOperatorUser) const stateOperatorUser = await this.stateOperatorUserRepo.find({
throw new HttpError(HttpStatus.NOT_FOUND, "ผู้ใช้งานนี้ไม่มีหน้าที่ในกระบวนการนี้"); where: {
workflow: {
refId: body.refId,
sysName: body.system,
},
profile: {
keycloak: Not(req.user.sub),
},
operator: stateOperatorUserNow?.operator || "",
},
});
await this.stateOperatorUserRepo.remove(stateOperatorUser);
const workflow = await this.workflowRepo.findOne({ const workflow = await this.workflowRepo.findOne({
where: { where: {
refId: body.refId, refId: body.refId,
system: body.system, sysName: body.system,
}, },
relations: ["stateOperatorUsers"], relations: ["stateOperatorUsers"],
}); });
@ -538,4 +625,71 @@ export class WorkflowController extends Controller {
profileId: stateUserComment?.profileId || null, profileId: stateUserComment?.profileId || null,
}); });
} }
/**
*
*
*/
@Get("commander")
async getProfilePlacement(@Request() req: RequestWithUser) {
const posMasterUser = await this.posMasterRepo.findOne({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
current_holder: { keycloak: req.user.sub },
},
});
if (!posMasterUser || !posMasterUser.orgRootId)
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบตำแหน่งผู้ใช้งาน");
const posMasters = await this.posMasterRepo.find({
where: {
orgRevision: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
isDirector: true,
current_holderId: Not(IsNull()),
orgRootId: posMasterUser.orgRootId,
},
relations: ["current_holder", "orgRoot"],
});
let _posMasters = posMasters.map((data) => ({
id: data.current_holderId,
prefix: data.current_holder.prefix,
firstName: data.current_holder.firstName,
lastName: data.current_holder.lastName,
position: data.current_holder.position,
posLevel: data.current_holder.posLevel,
posType: data.current_holder.posType,
orgRoot: data.orgRoot.orgRootName,
}));
return new HttpSuccess(_posMasters);
}
/**
* API
*
* @summary
*
*/
@Get("keycloak/isofficer/{system}")
async getIsOfficerByKeycloak(@Path() system: string, @Request() req: RequestWithUser) {
const profile = await this.profileRepo.findOne({
where: {
keycloak: req.user.sub,
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งาน");
const profileOfficer = await this.posMasterRepo.findOne({
where: {
posMasterAssigns: { assignId: system },
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: profile.id,
},
relations: ["orgChild1"],
});
if (!profileOfficer) return new HttpSuccess({ isOfficer: false, isStaff: false });
let isOfficer = profileOfficer.orgChild1 == null ? false : profileOfficer.orgChild1.isOfficer;
return new HttpSuccess({ isOfficer: isOfficer, isStaff: !isOfficer });
}
} }

View file

@ -1,6 +1,5 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { StateOperator } from "./StateOperator";
import { Workflow } from "./Workflow"; import { Workflow } from "./Workflow";
import { Profile } from "./Profile"; import { Profile } from "./Profile";
@ -21,14 +20,6 @@ export class StateOperatorUser extends EntityBase {
}) })
order: number; order: number;
@Column({
nullable: true,
comment: "ผู้ดำเนินการ",
length: 255,
default: null,
})
refId: string;
@Column({ @Column({
nullable: true, nullable: true,
length: 40, length: 40,

View file

@ -13,14 +13,6 @@ export class Workflow extends EntityBase {
}) })
refId: string; refId: string;
@Column({
nullable: true,
comment: "system",
length: 255,
default: null,
})
system: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ชื่อ flow", comment: "ชื่อ flow",

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableWorkflow81729073909711 implements MigrationInterface {
name = 'AddTableWorkflow81729073909711'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`workflow\` DROP COLUMN \`system\``);
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`refId\``);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`refId\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
await queryRunner.query(`ALTER TABLE \`workflow\` ADD \`system\` varchar(255) NULL COMMENT 'system'`);
}
}