Compare commits

...

4 Commits

4 changed files with 29 additions and 7 deletions

View File

@ -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;
} }

View File

@ -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 {

View File

@ -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`,
}, },
] ]

View File

@ -52,12 +52,15 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
}); });
if (!order) { if (!order) {
// Check if id is a valid UUID format
const uuidRegex =
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
const whereCondition = !uuidRegex.test(id)
? { invoice_code: id, booking_date: new Date() }
: { id, booking_date: new Date() };
const { customer_name, customer_phone } = const { customer_name, customer_phone } =
await this.transaction.findOneOrFail({ await this.transaction.findOneOrFail({
where: { where: whereCondition,
id,
booking_date: new Date(),
},
}); });
const start = moment().startOf('day').valueOf(); const start = moment().startOf('day').valueOf();