feat: add detail queue item
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
01b2796c26
commit
32d4064f0a
|
@ -40,4 +40,17 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
},
|
||||
});
|
||||
}
|
||||
|
||||
async queueItemTickets(
|
||||
order_id: string,
|
||||
item_id: string,
|
||||
): Promise<QueueTicketModel[]> {
|
||||
return this.repo.find({
|
||||
relations: ['items', 'items.item', 'items.item.item_queue'],
|
||||
where: {
|
||||
order_id,
|
||||
items: [{ item_id }, { item: { item_queue: { id: item_id } } }],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { TicketDataService } from '../data/services/ticket.service';
|
||||
import { QueueOrder } from './entities/order.entity';
|
||||
import { title } from 'process';
|
||||
import { QueueItemModel } from '../data/models/queue.model';
|
||||
|
||||
@Injectable()
|
||||
export class QueueOrchestrator {
|
||||
|
@ -20,12 +20,85 @@ export class QueueOrchestrator {
|
|||
|
||||
async queueTickets(order_id: string): Promise<any> {
|
||||
const tickets = await this.dataService.queueTickets(order_id);
|
||||
const items = tickets[0].items;
|
||||
return items.map((item) => {
|
||||
return tickets.map((ticket) => {
|
||||
const totalActivities = ticket.items.length;
|
||||
const totalTickets = ticket.items.reduce(
|
||||
(acc, item) => acc + item.qty,
|
||||
0,
|
||||
);
|
||||
const totalUsed = 0;
|
||||
const totalQueue = 0;
|
||||
return {
|
||||
id: item.id,
|
||||
title: item.item.name,
|
||||
qty: item.qty,
|
||||
id: ticket.id,
|
||||
code: ticket.code,
|
||||
customer: ticket.customer,
|
||||
phone: ticket.phone,
|
||||
date: ticket.date,
|
||||
summary: {
|
||||
total_activities: totalActivities,
|
||||
total_tickets: totalTickets,
|
||||
total_used: totalUsed,
|
||||
total_queue: totalQueue,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async queueItemDetail(order_id: string, item_id: string): Promise<any> {
|
||||
const tickets = await this.dataService.queueItemTickets(order_id, item_id);
|
||||
return tickets.map((ticket) => {
|
||||
const totalActivities = ticket.items.length;
|
||||
const totalTickets = ticket.items.reduce(
|
||||
(acc, item) => acc + item.qty,
|
||||
0,
|
||||
);
|
||||
const totalUsed = 0;
|
||||
const totalQueue = 0;
|
||||
return {
|
||||
id: ticket.id,
|
||||
code: ticket.code,
|
||||
customer: ticket.customer,
|
||||
phone: ticket.phone,
|
||||
date: ticket.date,
|
||||
summary: {
|
||||
total_activities: totalActivities,
|
||||
total_tickets: totalTickets,
|
||||
total_used: totalUsed,
|
||||
total_queue: totalQueue,
|
||||
},
|
||||
queue: [
|
||||
{
|
||||
code: 'A001',
|
||||
qty: 1,
|
||||
time: '15:00',
|
||||
status: 'waiting',
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async queueItems(order_id: string): Promise<any> {
|
||||
const tickets = await this.dataService.queueTickets(order_id);
|
||||
const ticketItems = {};
|
||||
|
||||
tickets.forEach((ticket) => {
|
||||
ticket.items.forEach((item) => {
|
||||
const item_id = item.item.item_queue?.id ?? item.item.id;
|
||||
const currentItem = ticketItems[item_id];
|
||||
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
||||
});
|
||||
});
|
||||
|
||||
return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
|
||||
const item = items[0];
|
||||
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
||||
return {
|
||||
id: item.item_id,
|
||||
title: item.item.item_queue?.name ?? item.item.name,
|
||||
image_url: item.item.image_url,
|
||||
qty: item_qty,
|
||||
|
||||
available: true,
|
||||
average: 12,
|
||||
nearest: '13:10',
|
||||
|
|
|
@ -28,8 +28,21 @@ export class QueueController {
|
|||
return await this.orchestrator.loginCustomer(id);
|
||||
}
|
||||
|
||||
@Get('tickets/:id')
|
||||
@Get(':id/tickets')
|
||||
async queueTickets(@Param('id') id: string): Promise<void> {
|
||||
return await this.orchestrator.queueTickets(id);
|
||||
}
|
||||
|
||||
@Get(':id/items')
|
||||
async queueItems(@Param('id') id: string): Promise<void> {
|
||||
return await this.orchestrator.queueItems(id);
|
||||
}
|
||||
|
||||
@Get(':id/items/:item_id')
|
||||
async queueItemTickets(
|
||||
@Param('id') id: string,
|
||||
@Param('item_id') item_id: string,
|
||||
): Promise<void> {
|
||||
return await this.orchestrator.queueItemDetail(id, item_id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue