feat: add login queue customer
parent
d6c02ac29f
commit
e9d864c922
|
@ -0,0 +1,19 @@
|
|||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddTransactionIdToQueueOrder1729653046392
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'AddTransactionIdToQueueOrder1729653046392';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "queue_orders" ADD "transaction_id" character varying NOT NULL`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "queue_orders" DROP COLUMN "transaction_id"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,9 @@ export class QueueOrderModel
|
|||
@Column('varchar', { nullable: true })
|
||||
phone: string;
|
||||
|
||||
@Column('varchar', { nullable: false })
|
||||
transaction_id: string;
|
||||
|
||||
@OneToMany(() => QueueTicketModel, (model) => model.order, {
|
||||
cascade: true,
|
||||
onDelete: 'CASCADE',
|
||||
|
|
|
@ -22,4 +22,13 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
async createQueueOrder(order: QueueOrder): Promise<QueueOrderModel> {
|
||||
return await this.order.save(order);
|
||||
}
|
||||
|
||||
async loginQueue(id: string): Promise<QueueOrder> {
|
||||
return this.order.findOneOrFail({
|
||||
relations: ['tickets'],
|
||||
where: {
|
||||
transaction_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@ export interface QueueOrder extends BaseCoreEntity {
|
|||
customer: string;
|
||||
phone: string;
|
||||
date: number;
|
||||
transaction_id: string;
|
||||
tickets: QueueTicket[];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { TicketDataService } from '../data/services/ticket.service';
|
||||
import { QueueOrder } from './entities/order.entity';
|
||||
|
||||
@Injectable()
|
||||
export class QueueOrchestrator {
|
||||
// constructor() {}
|
||||
constructor(private readonly dataService: TicketDataService) {}
|
||||
|
||||
async loginCustomer(id: string): Promise<QueueOrder> {
|
||||
try {
|
||||
return await this.dataService.loginQueue(id);
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException({
|
||||
message: 'Invoice tidak ditemukan',
|
||||
error: 'INVOICE_NOT_FOUND',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
|
@ -14,11 +14,17 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|||
|
||||
import { Public } from 'src/core/guards';
|
||||
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||
|
||||
@ApiTags(`Queue`)
|
||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||
@Public(false)
|
||||
@Public(true)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class QueueController {
|
||||
constructor(private orchestrator: QueueOrchestrator) {}
|
||||
|
||||
@Get('login/:id')
|
||||
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
||||
return await this.orchestrator.loginCustomer(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,14 @@ export class QueueTransactionHandler
|
|||
relations: ['items'],
|
||||
});
|
||||
|
||||
const { customer_name, customer_phone, invoice_code } = transaction;
|
||||
const { id, customer_name, customer_phone, invoice_code } = transaction;
|
||||
const current_date = new Date().valueOf();
|
||||
const customerOrder = {
|
||||
code: invoice_code,
|
||||
customer: customer_name,
|
||||
phone: customer_phone,
|
||||
date: current_date,
|
||||
transaction_id: id,
|
||||
};
|
||||
|
||||
const items = transaction.items.map<QueueItem>((item) => {
|
||||
|
|
Loading…
Reference in New Issue