feat: merge item queue
parent
d413f1fa7b
commit
c129a59d47
|
@ -1,6 +1,7 @@
|
|||
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { QueueTicket } from './ticket.entity';
|
||||
import { QueueModel } from '../../data/models/queue.model';
|
||||
|
||||
export interface QueueItem extends BaseCoreEntity {
|
||||
ticket?: QueueTicket;
|
||||
|
@ -8,3 +9,12 @@ export interface QueueItem extends BaseCoreEntity {
|
|||
item_id: string;
|
||||
qty: number;
|
||||
}
|
||||
|
||||
export interface MergedItemQueue extends BaseCoreEntity {
|
||||
id: string;
|
||||
queue_item_id: string;
|
||||
title: string;
|
||||
image_url: string;
|
||||
qty: number;
|
||||
queues: QueueModel[];
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ export class CustomerQueueDetailManager extends CustomerQueueManager {
|
|||
get data() {
|
||||
const queueCondition = new QueueCondition(this.queues);
|
||||
return this.tickets.map((ticket) => {
|
||||
const queueItems = this.mergeQueueItems(ticket);
|
||||
return {
|
||||
id: ticket.id,
|
||||
code: ticket.code,
|
||||
|
@ -22,19 +23,18 @@ export class CustomerQueueDetailManager extends CustomerQueueManager {
|
|||
total_used: this.totalUsedTickets(ticket),
|
||||
total_queue: this.totalQueueTickets(ticket),
|
||||
},
|
||||
items: ticket.items.map((item) => {
|
||||
const queueItem = item.item.item_queue ?? item.item;
|
||||
items: queueItems.map((item) => {
|
||||
return {
|
||||
id: item.item_id,
|
||||
item_queue_id: item.id,
|
||||
title: queueItem.name,
|
||||
image_url: item.item.image_url,
|
||||
id: item.id,
|
||||
item_queue_id: item.queue_item_id,
|
||||
title: item.title,
|
||||
image_url: item.image_url,
|
||||
summary: {
|
||||
total_tickets: item.qty,
|
||||
total_used: this.totalUsedItems(item),
|
||||
total_queue: this.totalQueueItems(item),
|
||||
total_used: this.totalUsedItems(item.queues),
|
||||
total_queue: this.totalQueueItems(item.queues),
|
||||
},
|
||||
queue: item.queue
|
||||
queue: item.queues
|
||||
.sort((a, b) => b.time - a.time)
|
||||
.map((q) => {
|
||||
return {
|
||||
|
@ -44,7 +44,7 @@ export class CustomerQueueDetailManager extends CustomerQueueManager {
|
|||
status: q.status,
|
||||
};
|
||||
}),
|
||||
queue_condition: queueCondition.condition(queueItem.id),
|
||||
queue_condition: queueCondition.condition(item.queue_item_id),
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -12,10 +12,9 @@ export class CustomerQueueItemListManager extends CustomerQueueManager {
|
|||
}
|
||||
get data() {
|
||||
const tickets = this.tickets;
|
||||
const ticketItems = {};
|
||||
|
||||
const queueCondition = new QueueCondition(this.queues);
|
||||
|
||||
const ticketItems = {};
|
||||
tickets.forEach((ticket) => {
|
||||
ticket.items.forEach((item) => {
|
||||
const item_id = item.item.item_queue?.id ?? item.item.id;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import {
|
||||
QueueItemModel,
|
||||
QueueModel,
|
||||
QueueTicketModel,
|
||||
} from '../../../data/models/queue.model';
|
||||
import { MergedItemQueue } from '../../entities/queue-item.entity';
|
||||
import { toTime } from '../../helpers/time.helper';
|
||||
|
||||
export class CustomerQueueManager {
|
||||
|
@ -22,32 +24,61 @@ export class CustomerQueueManager {
|
|||
return ticket.items.reduce((acc, item) => acc + item.qty, 0);
|
||||
}
|
||||
|
||||
totalUsedItems(item: QueueItemModel): number {
|
||||
return item.queue
|
||||
totalUsedItems(queues: QueueModel[]): number {
|
||||
return queues
|
||||
.filter((q) => ['done', 'called'].includes(q.status))
|
||||
.reduce((acc, item) => acc + item.qty, 0);
|
||||
}
|
||||
|
||||
totalUsedTickets(ticket: QueueTicketModel): number {
|
||||
const tickets = ticket.items.map((item) => {
|
||||
return this.totalUsedItems(item);
|
||||
return this.totalUsedItems(item.queue);
|
||||
});
|
||||
|
||||
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
||||
return tickets.reduce(reducer, 0);
|
||||
}
|
||||
|
||||
totalQueueItems(item: QueueItemModel): number {
|
||||
return item.queue
|
||||
totalQueueItems(queues: QueueModel[]): number {
|
||||
return queues
|
||||
.filter((q) => ['waiting'].includes(q.status))
|
||||
.reduce((acc, item) => acc + item.qty, 0);
|
||||
}
|
||||
totalQueueTickets(ticket: QueueTicketModel): number {
|
||||
const tickets = ticket.items.map((item) => {
|
||||
return this.totalQueueItems(item);
|
||||
return this.totalQueueItems(item.queue);
|
||||
});
|
||||
|
||||
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
||||
return tickets.reduce(reducer, 0);
|
||||
}
|
||||
|
||||
mergeQueueItems(ticket: QueueTicketModel): MergedItemQueue[] {
|
||||
const ticketItems = {};
|
||||
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 queues: QueueModel[] = [];
|
||||
|
||||
items.forEach((item) => {
|
||||
queues.push(...item.queue);
|
||||
});
|
||||
|
||||
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
||||
const queueItem = item.item.item_queue ?? item.item;
|
||||
return {
|
||||
id: item.item_id,
|
||||
queue_item_id: item.id,
|
||||
title: queueItem.name,
|
||||
image_url: item.item.image_url,
|
||||
qty: item_qty,
|
||||
queues,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
TransactionUserType,
|
||||
TransactionPaymentType,
|
||||
} from '../../constants';
|
||||
import { TransactionItemEntity } from '../../domain/entities/transaction-item.entity';
|
||||
import { TransactionItemModel } from './transaction-item.model';
|
||||
import { TransactionTaxModel } from './transaction-tax.model';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
|
@ -239,7 +238,7 @@ export class TransactionModel
|
|||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
items: TransactionItemEntity[];
|
||||
items: TransactionItemModel[];
|
||||
|
||||
// relations to tax data
|
||||
@OneToMany(() => TransactionTaxModel, (model) => model.transaction, {
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { TransactionModel } from '../models/transaction.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionDataService extends BaseDataService<TransactionEntity> {
|
||||
export class TransactionDataService extends BaseDataService<TransactionModel> {
|
||||
constructor(
|
||||
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<TransactionModel>,
|
||||
|
|
Loading…
Reference in New Issue