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) {
|
mappingValidator(column, operator, value) {
|
||||||
|
const candidates = Array.isArray(value) ? value : [value];
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '!=':
|
case '!=':
|
||||||
return column != value;
|
return column != value;
|
||||||
|
@ -79,9 +80,11 @@ export class ValidateRelationHelper<Entity> {
|
||||||
return column == value;
|
return column == value;
|
||||||
|
|
||||||
case 'in':
|
case 'in':
|
||||||
const candidates = Array.isArray(value) ? value : [value];
|
|
||||||
return candidates.includes(column);
|
return candidates.includes(column);
|
||||||
|
|
||||||
|
case 'not in':
|
||||||
|
return !candidates.includes(column);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return column == value;
|
return column == value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,13 @@ export class ActiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
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',
|
relation: 'tenant',
|
||||||
singleQuery: ['status', '!=', STATUS.ACTIVE],
|
singleQuery: ['status', '!=', STATUS.ACTIVE],
|
||||||
|
@ -44,6 +50,16 @@ export class ActiveItemManager extends BaseUpdateStatusManager<ItemEntity> {
|
||||||
message: `Gagal! Terdapat item yang belum aktif`,
|
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 {
|
get entityTarget(): any {
|
||||||
|
|
|
@ -50,7 +50,7 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
relation: relation,
|
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`,
|
message: `Gagal Update! Time group item dan bundling item tidak sama`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue