#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

@ -11,6 +11,7 @@ import { ProfileSalary } from "../entities/ProfileSalary";
import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CommandRecive } from "../entities/CommandRecive";
import { PosMasterAct } from "../entities/PosMasterAct";
export function calculateAge(start: Date, end = new Date()) {
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) {
const commandRepository = AppDataSource.getRepository(Command);
const _type = await commandRepository.findOne({