fix(SPG-1047): merge item queue with same item
parent
5e4401a974
commit
ea25e0cae1
|
@ -118,8 +118,12 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
}
|
||||
|
||||
async deleteQueue(transaction_id: string): Promise<void> {
|
||||
const transactions = await this.transactions(transaction_id);
|
||||
await this.order.remove(transactions);
|
||||
try {
|
||||
const transactions = await this.transactions(transaction_id);
|
||||
await this.order.remove(transactions);
|
||||
} catch (error) {
|
||||
console.log('transaction not found');
|
||||
}
|
||||
}
|
||||
|
||||
async orderIds(order_id: string): Promise<string[]> {
|
||||
|
|
|
@ -59,6 +59,7 @@ export class QueueTransactionHandler
|
|||
.filter((item) => item.item.use_queue)
|
||||
.map<QueueItem>((item) => {
|
||||
return {
|
||||
item_queue_id: item.item.item_queue_id,
|
||||
item_id: item.item_id,
|
||||
qty: item.qty,
|
||||
};
|
||||
|
@ -69,7 +70,7 @@ export class QueueTransactionHandler
|
|||
customer_phone,
|
||||
);
|
||||
|
||||
const insertTickets = [];
|
||||
const insertTickets: QueueTicket[] = [];
|
||||
if (customer_name && customer_phone && existTicket) {
|
||||
existTicket.items.push(...items);
|
||||
await this.ticketService.updateQueueTicket(existTicket);
|
||||
|
@ -90,18 +91,25 @@ export class QueueTransactionHandler
|
|||
) {
|
||||
insertTickets.forEach((ticket) => {
|
||||
const ticket_id = ticket.id;
|
||||
const items = {};
|
||||
ticket.items.forEach((item) => {
|
||||
const item_id = item.item_id;
|
||||
const item_id = item['item_queue_id'];
|
||||
const currentItem = items[item_id];
|
||||
|
||||
// for (let i = 0; i < item.qty; i++) {
|
||||
const payload = {
|
||||
item_id,
|
||||
ticket_id,
|
||||
qty: item.qty,
|
||||
};
|
||||
if (currentItem) {
|
||||
currentItem.qty += item.qty;
|
||||
}
|
||||
items[item_id] = currentItem
|
||||
? currentItem
|
||||
: {
|
||||
item_id,
|
||||
ticket_id,
|
||||
qty: item.qty,
|
||||
};
|
||||
});
|
||||
|
||||
Object.values(items).forEach((payload: any) => {
|
||||
this.create(payload);
|
||||
// }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue