feat: vip auto generate queue
parent
6807d00cbe
commit
1878d03c0f
|
@ -97,9 +97,7 @@ export class ChangeStatusBookingHandler
|
||||||
},
|
},
|
||||||
relations: ['items', 'items.bundling_items'],
|
relations: ['items', 'items.bundling_items'],
|
||||||
});
|
});
|
||||||
console.log('change status', { dataID, couchData, booking });
|
|
||||||
mappingTransaction(booking);
|
mappingTransaction(booking);
|
||||||
console.log('after mapping');
|
|
||||||
|
|
||||||
if (!couchData) {
|
if (!couchData) {
|
||||||
console.log('save data to couch');
|
console.log('save data to couch');
|
||||||
|
|
|
@ -19,11 +19,13 @@ import { SplitQueueManager } from './usecases/split-queue.manager';
|
||||||
import { LoginQueueDto } from '../infrastructure/controllers/dto/login-queue.dto';
|
import { LoginQueueDto } from '../infrastructure/controllers/dto/login-queue.dto';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { CustomerQueueTicketSummaryManager } from './usecases/queue/customer-queue-ticket.manager';
|
import { CustomerQueueTicketSummaryManager } from './usecases/queue/customer-queue-ticket.manager';
|
||||||
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueOrchestrator {
|
export class QueueOrchestrator {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly dataService: TicketDataService,
|
public readonly dataService: TicketDataService,
|
||||||
|
public readonly transactionService: TransactionDataService,
|
||||||
private readonly queueService: QueueService,
|
private readonly queueService: QueueService,
|
||||||
private readonly queueOrderService: QueueOrderService,
|
private readonly queueOrderService: QueueOrderService,
|
||||||
private readonly registerQueueManager: RegisterQueueManager,
|
private readonly registerQueueManager: RegisterQueueManager,
|
||||||
|
|
|
@ -28,7 +28,7 @@ export class CustomerQueueItemListManager extends CustomerQueueManager {
|
||||||
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
||||||
const queueItem = item.item.item_queue ?? item.item;
|
const queueItem = item.item.item_queue ?? item.item;
|
||||||
return {
|
return {
|
||||||
id: item.item_id,
|
id: queueItem.id,
|
||||||
queue_item_id: item.id,
|
queue_item_id: item.id,
|
||||||
title: queueItem.name,
|
title: queueItem.name,
|
||||||
image_url: item.item.image_url,
|
image_url: item.item.image_url,
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { CustomerQueueManager } from './customer-queue.manager';
|
||||||
export class CustomerQueueItemManager extends CustomerQueueManager {
|
export class CustomerQueueItemManager extends CustomerQueueManager {
|
||||||
get data() {
|
get data() {
|
||||||
return this.tickets.map((ticket) => {
|
return this.tickets.map((ticket) => {
|
||||||
|
const queueItems = this.mergeQueueItems(ticket);
|
||||||
const item = ticket.items[0];
|
const item = ticket.items[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: ticket.id,
|
id: ticket.id,
|
||||||
code: ticket.code,
|
code: ticket.code,
|
||||||
|
@ -17,7 +19,7 @@ export class CustomerQueueItemManager extends CustomerQueueManager {
|
||||||
total_used: this.totalUsedTickets(ticket),
|
total_used: this.totalUsedTickets(ticket),
|
||||||
total_queue: this.totalQueueTickets(ticket),
|
total_queue: this.totalQueueTickets(ticket),
|
||||||
},
|
},
|
||||||
queue: item.queue
|
queue: queueItems[0].queues
|
||||||
.sort((a, b) => b.time - a.time)
|
.sort((a, b) => b.time - a.time)
|
||||||
.map((q) => {
|
.map((q) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { Queue } from '../../domain/entities/queue.entity';
|
||||||
import { RegisterQueueDto } from './dto/register-queue.dto';
|
import { RegisterQueueDto } from './dto/register-queue.dto';
|
||||||
import { SplitQueueDto } from './dto/split-queue.dto';
|
import { SplitQueueDto } from './dto/split-queue.dto';
|
||||||
import { LoginQueueDto } from './dto/login-queue.dto';
|
import { LoginQueueDto } from './dto/login-queue.dto';
|
||||||
|
import { LoginReceiptDto } from './dto/login-receipt.dto';
|
||||||
|
|
||||||
@ApiTags(`Queue`)
|
@ApiTags(`Queue`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||||
|
@ -33,6 +34,12 @@ export class QueueController {
|
||||||
return await this.orchestrator.loginPhone(data);
|
return await this.orchestrator.loginPhone(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('login/receipt')
|
||||||
|
async loginReceipt(@Body() { id }: LoginReceiptDto): Promise<QueueOrder> {
|
||||||
|
console.log(id);
|
||||||
|
return await this.orchestrator.loginCustomer(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('login/:id')
|
@Get('login/:id')
|
||||||
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
||||||
return await this.orchestrator.loginCustomer(id);
|
return await this.orchestrator.loginCustomer(id);
|
||||||
|
|
|
@ -9,17 +9,22 @@ import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||||
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
|
||||||
import { TransactionUserType } from 'src/modules/transaction/transaction/constants';
|
import { TransactionUserType } from 'src/modules/transaction/transaction/constants';
|
||||||
|
import { RegisterQueueManager } from '../../domain/usecases/register-queue.manager';
|
||||||
|
import { RegisterQueueDto } from '../controllers/dto/register-queue.dto';
|
||||||
|
import { QueueService } from '../../data/services/queue.service';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
||||||
|
|
||||||
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
||||||
export class QueueTransactionHandler
|
export class QueueTransactionHandler
|
||||||
implements IEventHandler<TransactionChangeStatusEvent>
|
implements IEventHandler<TransactionChangeStatusEvent>
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
private dataService: TransactionDataService,
|
private readonly dataService: TransactionDataService,
|
||||||
private queueService: TicketDataService,
|
private readonly ticketService: TicketDataService,
|
||||||
private orchestrator: QueueOrchestrator,
|
private readonly queueService: QueueService,
|
||||||
|
private readonly bucketService: QueueBucketReadService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
async handle(event: TransactionChangeStatusEvent) {
|
||||||
|
@ -62,7 +67,7 @@ export class QueueTransactionHandler
|
||||||
const ticket: QueueTicket = { ...customerOrder, items };
|
const ticket: QueueTicket = { ...customerOrder, items };
|
||||||
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
||||||
|
|
||||||
const queueOrder = await this.queueService.createQueueOrder(order);
|
const queueOrder = await this.ticketService.createQueueOrder(order);
|
||||||
if (
|
if (
|
||||||
transaction.customer_category?.has_vip_pass ||
|
transaction.customer_category?.has_vip_pass ||
|
||||||
transaction.customer_type === TransactionUserType.VIP
|
transaction.customer_type === TransactionUserType.VIP
|
||||||
|
@ -79,10 +84,25 @@ export class QueueTransactionHandler
|
||||||
qty: 1,
|
qty: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.orchestrator.create(payload);
|
this.create(payload);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async create(data: RegisterQueueDto): Promise<void> {
|
||||||
|
const queue = await this.queueService.getTicketItems(
|
||||||
|
data.ticket_id,
|
||||||
|
data.item_id,
|
||||||
|
);
|
||||||
|
const queueRequest: any = {
|
||||||
|
qty: data.qty,
|
||||||
|
item_id: queue.id,
|
||||||
|
};
|
||||||
|
const registerQueueManager = new RegisterQueueManager(this.bucketService);
|
||||||
|
registerQueueManager.setData(queueRequest);
|
||||||
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
|
await registerQueueManager.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,11 @@ import { SplitQueueManager } from './domain/usecases/split-queue.manager';
|
||||||
],
|
],
|
||||||
controllers: [QueueController, QueueAdminController],
|
controllers: [QueueController, QueueAdminController],
|
||||||
providers: [
|
providers: [
|
||||||
QueueTransactionHandler,
|
|
||||||
|
|
||||||
QueueOrchestrator,
|
QueueOrchestrator,
|
||||||
QueueAdminOrchestrator,
|
QueueAdminOrchestrator,
|
||||||
|
|
||||||
|
QueueTransactionHandler,
|
||||||
|
|
||||||
TransactionDataService,
|
TransactionDataService,
|
||||||
TicketDataService,
|
TicketDataService,
|
||||||
QueueDataService,
|
QueueDataService,
|
||||||
|
|
|
@ -59,7 +59,7 @@ export class TransactionModel
|
||||||
@Column('varchar', { name: 'season_period_type_name', nullable: true })
|
@Column('varchar', { name: 'season_period_type_name', nullable: true })
|
||||||
season_period_type_name: string;
|
season_period_type_name: string;
|
||||||
|
|
||||||
@ManyToOne(() => TransactionDemographyModel)
|
@ManyToOne(() => VipCategoryModel)
|
||||||
@JoinColumn({ name: 'customer_category_id' })
|
@JoinColumn({ name: 'customer_category_id' })
|
||||||
customer_category: VipCategoryModel;
|
customer_category: VipCategoryModel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue