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 })
|
@Column('varchar', { nullable: true })
|
||||||
phone: string;
|
phone: string;
|
||||||
|
|
||||||
|
@Column('varchar', { nullable: false })
|
||||||
|
transaction_id: string;
|
||||||
|
|
||||||
@OneToMany(() => QueueTicketModel, (model) => model.order, {
|
@OneToMany(() => QueueTicketModel, (model) => model.order, {
|
||||||
cascade: true,
|
cascade: true,
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
|
|
|
@ -22,4 +22,13 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
async createQueueOrder(order: QueueOrder): Promise<QueueOrderModel> {
|
async createQueueOrder(order: QueueOrder): Promise<QueueOrderModel> {
|
||||||
return await this.order.save(order);
|
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;
|
customer: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
date: number;
|
date: number;
|
||||||
|
transaction_id: string;
|
||||||
tickets: QueueTicket[];
|
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()
|
@Injectable()
|
||||||
export class QueueOrchestrator {
|
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 {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Get,
|
||||||
Param,
|
Param,
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
|
@ -14,11 +14,17 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
||||||
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
|
|
||||||
@ApiTags(`Queue`)
|
@ApiTags(`Queue`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||||
@Public(false)
|
@Public(true)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class QueueController {
|
export class QueueController {
|
||||||
constructor(private orchestrator: QueueOrchestrator) {}
|
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'],
|
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 current_date = new Date().valueOf();
|
||||||
const customerOrder = {
|
const customerOrder = {
|
||||||
code: invoice_code,
|
code: invoice_code,
|
||||||
customer: customer_name,
|
customer: customer_name,
|
||||||
phone: customer_phone,
|
phone: customer_phone,
|
||||||
date: current_date,
|
date: current_date,
|
||||||
|
transaction_id: id,
|
||||||
};
|
};
|
||||||
|
|
||||||
const items = transaction.items.map<QueueItem>((item) => {
|
const items = transaction.items.map<QueueItem>((item) => {
|
||||||
|
|
Loading…
Reference in New Issue