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> {
|
async deleteQueue(transaction_id: string): Promise<void> {
|
||||||
const transactions = await this.transactions(transaction_id);
|
try {
|
||||||
await this.order.remove(transactions);
|
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[]> {
|
async orderIds(order_id: string): Promise<string[]> {
|
||||||
|
|
|
@ -59,6 +59,7 @@ export class QueueTransactionHandler
|
||||||
.filter((item) => item.item.use_queue)
|
.filter((item) => item.item.use_queue)
|
||||||
.map<QueueItem>((item) => {
|
.map<QueueItem>((item) => {
|
||||||
return {
|
return {
|
||||||
|
item_queue_id: item.item.item_queue_id,
|
||||||
item_id: item.item_id,
|
item_id: item.item_id,
|
||||||
qty: item.qty,
|
qty: item.qty,
|
||||||
};
|
};
|
||||||
|
@ -69,7 +70,7 @@ export class QueueTransactionHandler
|
||||||
customer_phone,
|
customer_phone,
|
||||||
);
|
);
|
||||||
|
|
||||||
const insertTickets = [];
|
const insertTickets: QueueTicket[] = [];
|
||||||
if (customer_name && customer_phone && existTicket) {
|
if (customer_name && customer_phone && existTicket) {
|
||||||
existTicket.items.push(...items);
|
existTicket.items.push(...items);
|
||||||
await this.ticketService.updateQueueTicket(existTicket);
|
await this.ticketService.updateQueueTicket(existTicket);
|
||||||
|
@ -90,18 +91,25 @@ export class QueueTransactionHandler
|
||||||
) {
|
) {
|
||||||
insertTickets.forEach((ticket) => {
|
insertTickets.forEach((ticket) => {
|
||||||
const ticket_id = ticket.id;
|
const ticket_id = ticket.id;
|
||||||
|
const items = {};
|
||||||
ticket.items.forEach((item) => {
|
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++) {
|
if (currentItem) {
|
||||||
const payload = {
|
currentItem.qty += item.qty;
|
||||||
item_id,
|
}
|
||||||
ticket_id,
|
items[item_id] = currentItem
|
||||||
qty: item.qty,
|
? currentItem
|
||||||
};
|
: {
|
||||||
|
item_id,
|
||||||
|
ticket_id,
|
||||||
|
qty: item.qty,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(items).forEach((payload: any) => {
|
||||||
this.create(payload);
|
this.create(payload);
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue