update clear user in org draft

This commit is contained in:
Adisak 2025-11-10 15:35:30 +07:00
parent 7739af7d44
commit b329dcaa0e

View file

@ -259,7 +259,13 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
if (!currentRevision) {
const draftRevision = await AppDataSource.getRepository(OrgRevision)
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
.getOne();
if (!currentRevision && !draftRevision) {
return;
}
if (type === "OFFICER") {
@ -276,7 +282,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
.where("id = :id", { id: findProfileInposMaster?.id })
.execute();
if (!findProfileInposMaster) {
const findProfileInposMasterDraft = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: draftRevision?.id })
.andWhere("posMaster.current_holderId = :profileId", { profileId })
.getOne();
await AppDataSource.getRepository(PosMaster)
.createQueryBuilder()
.update(PosMaster)
.set({ next_holderId: null })
.where("id = :id", { id: findProfileInposMasterDraft?.id })
.execute();
if (!findProfileInposMaster && !findProfileInposMasterDraft) {
return;
}
const findPosition = await AppDataSource.getRepository(Position)