development #116
|
@ -11,6 +11,7 @@ import {
|
||||||
} from '../models/queue.model';
|
} from '../models/queue.model';
|
||||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TicketDataService extends BaseDataService<QueueTicket> {
|
export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
@ -23,6 +24,9 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
|
||||||
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
private item: Repository<QueueItemModel>,
|
private item: Repository<QueueItemModel>,
|
||||||
|
|
||||||
|
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private transaction: Repository<TransactionModel>,
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
@ -36,13 +40,37 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginQueue(id: string): Promise<QueueOrder> {
|
async loginQueue(id: string): Promise<QueueOrder> {
|
||||||
return this.order.findOneOrFail({
|
const order = await this.order.findOne({
|
||||||
relations: ['tickets'],
|
relations: ['tickets'],
|
||||||
where: [
|
where: [
|
||||||
{ transaction_id: id },
|
{ transaction_id: id },
|
||||||
{ code: id, transaction_id: Not(IsNull()) },
|
{ code: id, transaction_id: Not(IsNull()) },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!order) {
|
||||||
|
const { customer_name, customer_phone } =
|
||||||
|
await this.transaction.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
const order = this.order.findOneOrFail({
|
||||||
|
relations: ['tickets'],
|
||||||
|
where: {
|
||||||
|
customer: customer_name,
|
||||||
|
phone: customer_phone,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
async ticketByCode(code: string): Promise<QueueTicketModel[]> {
|
async ticketByCode(code: string): Promise<QueueTicketModel[]> {
|
||||||
|
|
|
@ -89,10 +89,13 @@ export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
|
|
||||||
console.log({ start, end, item_queue_id: this.filterParam.queue_id });
|
console.log({ start, end, item_queue_id: this.filterParam.queue_id });
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.time BETWEEN :start AND :end`, {
|
queryBuilder.andWhere(
|
||||||
start,
|
`${this.tableName}.created_at BETWEEN :start AND :end`,
|
||||||
end,
|
{
|
||||||
});
|
start,
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.item_queue_id = :item_queue_id`, {
|
queryBuilder.andWhere(`${this.tableName}.item_queue_id = :item_queue_id`, {
|
||||||
item_queue_id: this.filterParam.queue_id,
|
item_queue_id: this.filterParam.queue_id,
|
||||||
|
|
Loading…
Reference in New Issue