fix: update validation logic in item managers to use 'not in' for time_group_id checks and enhance relation handling

pull/142/head
shancheas 2025-06-26 18:14:26 +07:00
parent 14a86343df
commit fd8b7cc45e
3 changed files with 22 additions and 3 deletions

View File

@ -71,6 +71,7 @@ export class ValidateRelationHelper<Entity> {
}
mappingValidator(column, operator, value) {
const candidates = Array.isArray(value) ? value : [value];
switch (operator) {
case '!=':
return column != value;
@ -79,9 +80,11 @@ export class ValidateRelationHelper<Entity> {
return column == value;
case 'in':
const candidates = Array.isArray(value) ? value : [value];
return candidates.includes(column);
case 'not in':
return !candidates.includes(column);
default:
return column == value;
}

View File

@ -32,7 +32,13 @@ export class ActiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
}
get validateRelations(): validateRelations[] {
return [
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
const relation =
this.data.bundling_items?.length > 0
? 'bundling_items'
: 'bundling_parents';
const validateRelations: validateRelations[] = [
{
relation: 'tenant',
singleQuery: ['status', '!=', STATUS.ACTIVE],
@ -44,6 +50,16 @@ export class ActiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
message: `Gagal! Terdapat item yang belum aktif`,
},
];
if (timeGroupId != null) {
validateRelations.push({
relation: relation,
singleQuery: ['time_group_id', 'not in', [timeGroupId, null]],
message: `Gagal Update! Time group item dan bundling item tidak sama`,
});
}
return validateRelations;
}
get entityTarget(): any {

View File

@ -50,7 +50,7 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
? [
{
relation: relation,
singleQuery: ['time_group_id', 'in', [timeGroupId, null]],
singleQuery: ['time_group_id', 'not in', [timeGroupId, null]],
message: `Gagal Update! Time group item dan bundling item tidak sama`,
},
]