update org

This commit is contained in:
mamoss 2025-11-03 21:37:50 +07:00
parent 2094973dd0
commit 40bc95bb87

View file

@ -6316,45 +6316,49 @@ export class ImportDataController extends Controller {
@Post("updateRetireClearOrg") @Post("updateRetireClearOrg")
async updateRetireClearOrg(@Request() request: { user: Record<string, any> }) { async updateRetireClearOrg(@Request() request: { user: Record<string, any> }) {
const profiles = await this.profileRepo.find({ const profiles = await this.profileRepo.find({
where: { where: { isLeave: true },
isLeave: true, select: ["id"],
},
}); });
const profileIds = profiles.map((p) => p.id);
for (const item of profiles) { if (profileIds.length > 0) {
const posmaster = await this.posMasterRepo.findOne({ const posmasters = await this.posMasterRepo.find({
where: { where: {
orgRevision: { orgRevision: {
orgRevisionIsCurrent: false, orgRevisionIsCurrent: false,
orgRevisionIsDraft: true, orgRevisionIsDraft: true,
}, },
next_holderId: item.id, next_holderId: In(profileIds),
}, },
}); });
if (!posmaster) continue; for (const posmaster of posmasters) {
posmaster.next_holderId = null; posmaster.next_holderId = null;
await this.posMasterRepo.save(posmaster); }
if (posmasters.length > 0) {
await this.posMasterRepo.save(posmasters);
}
} }
const profileEmps = await this.profileEmpRepo.find({ const profileEmps = await this.profileEmpRepo.find({
where: { where: { isLeave: true },
isLeave: true, select: ["id"],
},
}); });
const profileEmpIds = profileEmps.map((p) => p.id);
for (const item of profileEmps) { if (profileEmpIds.length > 0) {
const posmaster = await this.posMasterEmpRepo.findOne({ const posmasterEmps = await this.posMasterEmpRepo.find({
where: { where: {
orgRevision: { orgRevision: {
orgRevisionIsCurrent: false, orgRevisionIsCurrent: false,
orgRevisionIsDraft: true, orgRevisionIsDraft: true,
}, },
next_holderId: item.id, next_holderId: In(profileEmpIds),
}, },
}); });
if (!posmaster) continue; for (const posmasterEmp of posmasterEmps) {
posmaster.next_holderId = null; posmasterEmp.next_holderId = null;
await this.posMasterEmpRepo.save(posmaster); }
if (posmasterEmps.length > 0) {
await this.posMasterEmpRepo.save(posmasterEmps);
}
} }
return new HttpSuccess(); return new HttpSuccess();
} }