Compare commits

...

4 Commits

7 changed files with 31 additions and 8 deletions

View File

@ -52,13 +52,12 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
? [
{
column: 'name',
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
query: `((${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
},
]
: [
{
column: 'name',
query: `(status = '${STATUS.ACTIVE}')`,
},
];
}

View File

@ -62,7 +62,7 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
return [
{
column: 'name',
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
query: `((${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
},
];
}

View File

@ -6,6 +6,8 @@ import {
Param,
RelationParam,
} from 'src/core/modules/domain/entities/base-filter.entity';
import * as moment from 'moment';
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
// TODO:
// Implementasikan filter by start_time, end_timen, dan max_usage_time
@ -13,6 +15,10 @@ import {
@Injectable()
export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntity> {
async prepareData(): Promise<void> {
Object.assign(this.filterParam, {
order_by: `${this.tableName}.start_time`,
order_type: ORDER_TYPE.ASC,
});
return;
}
@ -60,6 +66,15 @@ export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntit
queryBuilder: SelectQueryBuilder<TimeGroupEntity>,
): SelectQueryBuilder<TimeGroupEntity> {
queryBuilder.andWhere(`items.id is not null`);
if (!this.filterParam.date) {
const currentTime = moment().utcOffset('+07:00').format('HH:mm:ss');
queryBuilder.andWhere(`${this.tableName}.end_time >= :current_time`, {
current_time: currentTime,
});
}
return queryBuilder;
}
}

View File

@ -30,4 +30,12 @@ export class FilterTimeGroupDto
@ApiProperty({ type: 'string', required: false })
@ValidateIf((body) => body.max_usage_time_to)
max_usage_time_to: string;
@ApiProperty({
type: Date,
required: false,
example: '2024-01-01',
})
@ValidateIf((body) => body.date)
date: Date;
}

View File

@ -56,6 +56,7 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
await this.transaction.findOneOrFail({
where: {
id,
booking_date: new Date(),
},
});

View File

@ -56,7 +56,7 @@ export class QueueOrchestrator {
return order;
} catch (error) {
throw new UnauthorizedException({
message: 'Invoice tidak ditemukan',
message: 'Invoice tidak ditemukan untuk tanggal hari ini',
error: 'INVOICE_NOT_FOUND',
});
}

View File

@ -27,6 +27,7 @@ export class GenerateQueueManager {
async generate(transaction: TransactionModel) {
const date = transaction.booking_date ?? transaction.invoice_date;
const queue_date = moment(date, 'YYYY-MM-DD').unix();
const isToday = moment(date, 'YYYY-MM-DD').isSame(moment(), 'day');
const { id, customer_name, customer_phone, invoice_code } = transaction;
@ -40,10 +41,9 @@ export class GenerateQueueManager {
const items = this.generateItems(transaction.items);
const existTicket = await this.ticketService.ticketByUser(
customer_name,
customer_phone,
);
const existTicket = isToday
? await this.ticketService.ticketByUser(customer_name, customer_phone)
: null;
const insertTickets: QueueTicket[] = [];
if (customer_name && customer_phone && existTicket) {