feat: vip auto enter queue
parent
c129a59d47
commit
6c53610ec4
|
@ -9,6 +9,7 @@ import { QueueOrder } from '../../domain/entities/order.entity';
|
|||
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
||||
import * as moment from 'moment';
|
||||
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
||||
|
||||
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
||||
export class QueueTransactionHandler
|
||||
|
@ -17,6 +18,7 @@ export class QueueTransactionHandler
|
|||
constructor(
|
||||
private dataService: TransactionDataService,
|
||||
private queueService: TicketDataService,
|
||||
private orchestrator: QueueOrchestrator,
|
||||
) {}
|
||||
|
||||
async handle(event: TransactionChangeStatusEvent) {
|
||||
|
@ -31,7 +33,7 @@ export class QueueTransactionHandler
|
|||
where: {
|
||||
id: event.data.id,
|
||||
},
|
||||
relations: ['items'],
|
||||
relations: ['customer_category', 'items', 'items.item'],
|
||||
});
|
||||
|
||||
const date = transaction.booking_date ?? transaction.invoice_date;
|
||||
|
@ -47,7 +49,9 @@ export class QueueTransactionHandler
|
|||
transaction_id: id,
|
||||
};
|
||||
|
||||
const items = transaction.items.map<QueueItem>((item) => {
|
||||
const items = transaction.items
|
||||
.filter((item) => item.item.use_queue)
|
||||
.map<QueueItem>((item) => {
|
||||
return {
|
||||
item_id: item.item_id,
|
||||
qty: item.qty,
|
||||
|
@ -57,6 +61,24 @@ export class QueueTransactionHandler
|
|||
const ticket: QueueTicket = { ...customerOrder, items };
|
||||
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
||||
|
||||
this.queueService.createQueueOrder(order);
|
||||
const queueOrder = await this.queueService.createQueueOrder(order);
|
||||
if (transaction.customer_category?.has_vip_pass) {
|
||||
queueOrder.tickets.forEach((ticket) => {
|
||||
const ticket_id = ticket.id;
|
||||
ticket.items.forEach((item) => {
|
||||
const item_id = item.item_id;
|
||||
|
||||
for (let i = 0; i < item.qty; i++) {
|
||||
const payload = {
|
||||
item_id,
|
||||
ticket_id,
|
||||
qty: 1,
|
||||
};
|
||||
|
||||
this.orchestrator.create(payload);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
import { TransactionModel } from './transaction.model';
|
||||
import { RefundItemModel } from 'src/modules/transaction/refund/data/models/refund-item.model';
|
||||
import { TransactionTaxEntity } from '../../domain/entities/transaction-tax.entity';
|
||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||
|
||||
@Entity(TABLE_NAME.TRANSACTION_ITEM)
|
||||
export class TransactionItemModel
|
||||
|
@ -126,6 +127,10 @@ export class TransactionItemModel
|
|||
onUpdate: 'CASCADE',
|
||||
})
|
||||
item_taxes: TransactionItemTaxModel[];
|
||||
|
||||
@ManyToOne(() => ItemModel)
|
||||
@JoinColumn({ name: 'item_id' })
|
||||
item: ItemModel;
|
||||
}
|
||||
|
||||
@Entity(TABLE_NAME.TRANSACTION_ITEM_BREAKDOWN)
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
} from 'typeorm';
|
||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||
import {
|
||||
TransactionType,
|
||||
|
@ -12,6 +19,7 @@ import { TransactionTaxModel } from './transaction-tax.model';
|
|||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { RefundModel } from 'src/modules/transaction/refund/data/models/refund.model';
|
||||
import { TransactionDemographyModel } from './transaction-demography.model';
|
||||
import { VipCategoryModel } from 'src/modules/transaction/vip-category/data/models/vip-category.model';
|
||||
|
||||
@Entity(TABLE_NAME.TRANSACTION)
|
||||
export class TransactionModel
|
||||
|
@ -51,6 +59,10 @@ export class TransactionModel
|
|||
@Column('varchar', { name: 'season_period_type_name', nullable: true })
|
||||
season_period_type_name: string;
|
||||
|
||||
@ManyToOne(() => TransactionDemographyModel)
|
||||
@JoinColumn({ name: 'customer_category_id' })
|
||||
customer_category: VipCategoryModel;
|
||||
|
||||
// customer info
|
||||
@Column('enum', {
|
||||
name: 'customer_type',
|
||||
|
|
Loading…
Reference in New Issue