feat: add register queue
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
e9de46fff8
commit
487f59ae93
|
@ -1,6 +1,10 @@
|
|||
import { ValidateRelationHelper } from 'src/core/helpers/validation/validate-relation.helper';
|
||||
import { BaseManager } from '../base.manager';
|
||||
import { OPERATION, STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import {
|
||||
OPERATION,
|
||||
QUEUE_STATUS,
|
||||
STATUS,
|
||||
} from 'src/core/strings/constants/base.constants';
|
||||
import * as _ from 'lodash';
|
||||
import { RecordLog } from 'src/modules/configuration/log/domain/entities/log.event';
|
||||
|
||||
|
@ -8,12 +12,12 @@ export abstract class BaseUpdateStatusManager<Entity> extends BaseManager {
|
|||
protected dataId: string;
|
||||
protected result: Entity;
|
||||
protected oldData: Entity;
|
||||
protected dataStatus: STATUS;
|
||||
protected dataStatus: STATUS | QUEUE_STATUS;
|
||||
protected relations = [];
|
||||
protected duplicateColumn: string[];
|
||||
abstract get entityTarget(): any;
|
||||
|
||||
setData(id: string, status: STATUS): void {
|
||||
setData(id: string, status: STATUS | QUEUE_STATUS): void {
|
||||
/**
|
||||
* // TODO: Handle case confirm multiple tabs;
|
||||
* Pola id yang dikirim dirubah menjadi data_id___updated_at
|
||||
|
|
|
@ -15,6 +15,11 @@ export enum STATUS {
|
|||
WAITING = 'waiting',
|
||||
}
|
||||
|
||||
export enum QUEUE_STATUS {
|
||||
DONE = 'done',
|
||||
CALLED = 'called',
|
||||
}
|
||||
|
||||
export enum ORDER_TYPE {
|
||||
ASC = 'ASC',
|
||||
DESC = 'DESC',
|
||||
|
|
|
@ -5,6 +5,7 @@ import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
|||
import { Repository } from 'typeorm';
|
||||
import { QueueModel } from '../models/queue.model';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
|
||||
@Injectable()
|
||||
export class QueueDataService extends BaseReadService<QueueModel> {
|
||||
|
@ -15,3 +16,13 @@ export class QueueDataService extends BaseReadService<QueueModel> {
|
|||
super(repo);
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class QueueService extends BaseDataService<QueueModel> {
|
||||
constructor(
|
||||
@InjectRepository(QueueModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<QueueModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { QueueDataService } from '../data/services/queue.service';
|
||||
import { QueueDataService, QueueService } from '../data/services/queue.service';
|
||||
import { IndexQueueManager } from './usecases/index-queue.manager';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Queue } from './entities/queue.entity';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { CallQueueManager } from './usecases/call-queue.manager';
|
||||
import { QUEUE_STATUS } from 'src/core/strings/constants/base.constants';
|
||||
|
||||
@Injectable()
|
||||
export class QueueAdminOrchestrator {
|
||||
constructor(
|
||||
private readonly dataService: QueueDataService,
|
||||
private readonly service: QueueService,
|
||||
private indexManager: IndexQueueManager,
|
||||
private callManager: CallQueueManager,
|
||||
) {}
|
||||
|
||||
async index(params): Promise<PaginationResponse<Queue>> {
|
||||
|
@ -18,4 +22,11 @@ export class QueueAdminOrchestrator {
|
|||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async call(dataId): Promise<string> {
|
||||
this.callManager.setData(dataId, QUEUE_STATUS.CALLED);
|
||||
this.callManager.setService(this.service, TABLE_NAME.QUEUE);
|
||||
await this.callManager.execute();
|
||||
return this.callManager.getResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,18 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|||
import { TicketDataService } from '../data/services/ticket.service';
|
||||
import { QueueOrder } from './entities/order.entity';
|
||||
import { QueueItemModel } from '../data/models/queue.model';
|
||||
import { Queue } from './entities/queue.entity';
|
||||
import { QueueService } from '../data/services/queue.service';
|
||||
import { RegisterQueueManager } from './usecases/register-queue.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
|
||||
@Injectable()
|
||||
export class QueueOrchestrator {
|
||||
constructor(private readonly dataService: TicketDataService) {}
|
||||
constructor(
|
||||
private readonly dataService: TicketDataService,
|
||||
private readonly queueService: QueueService,
|
||||
private readonly registerQueueManager: RegisterQueueManager,
|
||||
) {}
|
||||
|
||||
async loginCustomer(id: string): Promise<QueueOrder> {
|
||||
try {
|
||||
|
@ -18,6 +26,13 @@ export class QueueOrchestrator {
|
|||
}
|
||||
}
|
||||
|
||||
async create(data): Promise<Queue> {
|
||||
this.registerQueueManager.setData(data);
|
||||
this.registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||
await this.registerQueueManager.execute();
|
||||
return this.registerQueueManager.getResult();
|
||||
}
|
||||
|
||||
async queueTickets(order_id: string): Promise<any> {
|
||||
const tickets = await this.dataService.queueTickets(order_id);
|
||||
return tickets.map((ticket) => {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { BaseUpdateStatusManager } from 'src/core/modules/domain/usecase/managers/base-update-status.manager';
|
||||
import {
|
||||
EventTopics,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { Queue } from '../entities/queue.entity';
|
||||
import { QueueModel } from '../../data/models/queue.model';
|
||||
|
||||
@Injectable()
|
||||
export class CallQueueManager extends BaseUpdateStatusManager<Queue> {
|
||||
getResult(): string {
|
||||
return `Success call Queue ${this.result.code}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
this.data.call_time = new Date().getTime();
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return QueueModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
EventTopics,
|
||||
columnUniques,
|
||||
validateRelations,
|
||||
} from 'src/core/strings/constants/interface.constants';
|
||||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||
import { Queue } from '../entities/queue.entity';
|
||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||
import { QueueModel } from '../../data/models/queue.model';
|
||||
import { generateRandom } from 'src/modules/transaction/vip-code/domain/usecases/managers/helpers/generate-random.helper';
|
||||
|
||||
@Injectable()
|
||||
export class RegisterQueueManager extends BaseCreateManager<Queue> {
|
||||
async beforeProcess(): Promise<void> {
|
||||
Object.assign(this.data, {
|
||||
status: STATUS.WAITING,
|
||||
time: new Date().getTime(),
|
||||
vip: false,
|
||||
code: `Q${generateRandom(4, true)}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get validateRelations(): validateRelations[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get uniqueColumns(): columnUniques[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return QueueModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsNumber, IsString, Min } from 'class-validator';
|
||||
|
||||
export class RegisterQueueDto {
|
||||
@ApiProperty({ name: 'item_id', required: true })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
item_id: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
required: true,
|
||||
example: 1,
|
||||
})
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@IsNotEmpty()
|
||||
qty: number;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { Controller, Get, Param, Post, Query } from '@nestjs/common';
|
||||
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
|
@ -22,4 +22,9 @@ export class QueueAdminController {
|
|||
async index(@Query() params: QueueDto): Promise<PaginationResponse<Queue>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Post('queues/:id/call')
|
||||
async call(@Param('id') id: string) {
|
||||
return await this.orchestrator.call(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
|
@ -6,6 +6,8 @@ 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';
|
||||
import { Queue } from '../../domain/entities/queue.entity';
|
||||
import { RegisterQueueDto } from './dto/register-queue.dto';
|
||||
|
||||
@ApiTags(`Queue`)
|
||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||
|
@ -14,6 +16,11 @@ import { QueueOrder } from '../../domain/entities/order.entity';
|
|||
export class QueueController {
|
||||
constructor(private orchestrator: QueueOrchestrator) {}
|
||||
|
||||
@Post('register')
|
||||
async registerQueue(@Body() data: RegisterQueueDto): Promise<Queue> {
|
||||
return await this.orchestrator.create(data);
|
||||
}
|
||||
|
||||
@Get('login/:id')
|
||||
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
||||
return await this.orchestrator.loginCustomer(id);
|
||||
|
|
|
@ -18,10 +18,12 @@ import { QueueTransactionHandler } from './infrastructure/handlers/transaction.h
|
|||
import { TransactionDataService } from '../transaction/transaction/data/services/transaction-data.service';
|
||||
import { TransactionModel } from '../transaction/transaction/data/models/transaction.model';
|
||||
import { TicketDataService } from './data/services/ticket.service';
|
||||
import { QueueDataService } from './data/services/queue.service';
|
||||
import { QueueDataService, QueueService } from './data/services/queue.service';
|
||||
import { QueueAdminController } from './infrastructure/controllers/queue-admin.controller';
|
||||
import { QueueAdminOrchestrator } from './domain/queue-admin.orchestrator';
|
||||
import { IndexQueueManager } from './domain/usecases/index-queue.manager';
|
||||
import { CallQueueManager } from './domain/usecases/call-queue.manager';
|
||||
import { RegisterQueueManager } from './domain/usecases/register-queue.manager';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -49,8 +51,11 @@ import { IndexQueueManager } from './domain/usecases/index-queue.manager';
|
|||
TransactionDataService,
|
||||
TicketDataService,
|
||||
QueueDataService,
|
||||
QueueService,
|
||||
|
||||
IndexQueueManager,
|
||||
CallQueueManager,
|
||||
RegisterQueueManager,
|
||||
],
|
||||
})
|
||||
export class QueueModule {}
|
||||
|
|
Loading…
Reference in New Issue