fix: update validation logic in item managers to use 'not in' for time_group_id checks and enhance relation handling
parent
14a86343df
commit
fd8b7cc45e
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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`,
|
||||
},
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue