#1305 ลบ posMasterAct

This commit is contained in:
AdisakKanthawilang 2025-07-25 17:54:26 +07:00
parent c297572c79
commit 018aae2c57
3 changed files with 57 additions and 3 deletions

View file

@ -42,6 +42,7 @@ import {
checkReturnCommandType, checkReturnCommandType,
checkExceptCommandType, checkExceptCommandType,
checkCommandType, checkCommandType,
removePostMasterAct,
} from "../interfaces/utils"; } from "../interfaces/utils";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
@ -3381,6 +3382,7 @@ export class CommandController extends Controller {
let _posNumCodeSit: string = ""; let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = ""; let _posNumCodeSitAbb: string = "";
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
relations: ["commandType"],
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
}); });
if (_command) { if (_command) {
@ -3430,6 +3432,11 @@ export class CommandController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-08","C-PM-17", "C-PM-18"].includes(code)){
removePostMasterAct(profile.id);
}
let _commandYear = item.commandYear; let _commandYear = item.commandYear;
if (item.commandYear) { if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
@ -3492,6 +3499,7 @@ export class CommandController extends Controller {
// profile.posTypeId = _null; // profile.posTypeId = _null;
// profile.posLevelId = _null; // profile.posLevelId = _null;
} }
if (item.isGovernment == true) { if (item.isGovernment == true) {
if (returnWork) { if (returnWork) {
//ปลดตำแหน่งเดิมที่ไม่ถูกปลดออกจากกิ่งครั้งเมื่อออกคำสั่งพักราชการหรือออกราชการไว้ //ปลดตำแหน่งเดิมที่ไม่ถูกปลดออกจากกิ่งครั้งเมื่อออกคำสั่งพักราชการหรือออกราชการไว้
@ -3499,7 +3507,8 @@ export class CommandController extends Controller {
//ปั๊มตำแหน่งใหม่ //ปั๊มตำแหน่งใหม่
const posMaster = await this.posMasterRepository.findOne({ const posMaster = await this.posMasterRepository.findOne({
where: { id: item.posmasterId?.toString() }, where: { id: item.posmasterId?.toString() },
}); });
if (posMaster) { if (posMaster) {
const checkPosition = await this.positionRepository.find({ const checkPosition = await this.positionRepository.find({
where: { where: {
@ -3846,6 +3855,7 @@ export class CommandController extends Controller {
let _posNumCodeSit: string = ""; let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = ""; let _posNumCodeSitAbb: string = "";
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
relations: ["commandType"],
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
}); });
if (_command) { if (_command) {
@ -3895,6 +3905,13 @@ export class CommandController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-13"].includes(code)){
removePostMasterAct(profile.id);
}
let _commandYear = item.commandYear; let _commandYear = item.commandYear;
if (item.commandYear) { if (item.commandYear) {
_commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543; _commandYear = item.commandYear > 2500 ? item.commandYear : item.commandYear + 543;
@ -4159,6 +4176,7 @@ export class CommandController extends Controller {
let _posNumCodeSit: string = ""; let _posNumCodeSit: string = "";
let _posNumCodeSitAbb: string = ""; let _posNumCodeSitAbb: string = "";
const _command = await this.commandRepository.findOne({ const _command = await this.commandRepository.findOne({
relations: ["commandType"],
where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" },
}); });
if (_command) { if (_command) {
@ -4231,6 +4249,13 @@ export class CommandController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
} }
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if(code && ["C-PM-19", "C-PM-20"].includes(code)){
removePostMasterAct(profile.id);
}
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { where: {
orgRevisionIsCurrent: true, orgRevisionIsCurrent: true,

View file

@ -26,7 +26,7 @@ import { PosMaster } from "../entities/PosMaster";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils"; import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq"; import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
@ -3255,7 +3255,7 @@ export class OrganizationController extends Controller {
user: request.user, user: request.user,
token: request.headers["authorization"], token: request.headers["authorization"],
}; };
sendToQueueOrg(msg); await sendToQueueOrg(msg);
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) { } catch (error: any) {
if (error?.status && error?.message) { if (error?.status && error?.message) {

View file

@ -11,6 +11,7 @@ import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CommandRecive } from "../entities/CommandRecive"; import { CommandRecive } from "../entities/CommandRecive";
import { PosMasterAct } from "../entities/PosMasterAct";
export function calculateAge(start: Date, end = new Date()) { export function calculateAge(start: Date, end = new Date()) {
if (start.getTime() > end.getTime()) return null; if (start.getTime() > end.getTime()) return null;
@ -331,6 +332,34 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
} }
} }
export async function removePostMasterAct(profileId: string) {
const currentRevision = await AppDataSource.getRepository(OrgRevision)
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
if (!currentRevision) {
return;
}
const findProfileInposMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id })
.andWhere("posMaster.current_holderId = :profileId", { profileId })
.getOne();
if (!findProfileInposMaster) {
return;
}
const posMasterAct = await AppDataSource.getRepository(PosMasterAct)
.createQueryBuilder("posMasterAct")
.where("posMasterAct.posMasterChildId = :posMasterChildId", { posMasterChildId: findProfileInposMaster.id })
.getMany();
await AppDataSource.getRepository(PosMasterAct).remove(posMasterAct);
}
export async function checkReturnCommandType(commandId: string) { export async function checkReturnCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command); const commandRepository = AppDataSource.getRepository(Command);
const _type = await commandRepository.findOne({ const _type = await commandRepository.findOne({