feat: login customer
parent
319d9eecef
commit
5f46432327
|
@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { In, Repository } from 'typeorm';
|
||||
import { Between, In, Repository } from 'typeorm';
|
||||
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||
import {
|
||||
QueueItemModel,
|
||||
|
@ -10,6 +10,7 @@ import {
|
|||
QueueTicketModel,
|
||||
} from '../models/queue.model';
|
||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||
|
@ -39,6 +40,20 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
});
|
||||
}
|
||||
|
||||
async loginPhone(user: string, phone: string): Promise<QueueOrder> {
|
||||
const start = moment().startOf('day').valueOf();
|
||||
const end = moment().endOf('day').valueOf();
|
||||
|
||||
return this.order.findOneOrFail({
|
||||
relations: ['tickets'],
|
||||
where: {
|
||||
customer: user,
|
||||
phone: `+${phone}`,
|
||||
date: Between(start, end),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async orders(order_id: string): Promise<QueueOrderModel[]> {
|
||||
const order = await this.order.findOneOrFail({
|
||||
where: {
|
||||
|
|
|
@ -16,6 +16,8 @@ import { CustomerQueueItemListManager } from './usecases/queue/customer-queue-it
|
|||
import { CustomerQueueListManager } from './usecases/queue/customer-queue-list.manager';
|
||||
import { SplitQueueDto } from '../infrastructure/controllers/dto/split-queue.dto';
|
||||
import { SplitQueueManager } from './usecases/split-queue.manager';
|
||||
import { LoginQueueDto } from '../infrastructure/controllers/dto/login-queue.dto';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class QueueOrchestrator {
|
||||
|
@ -38,6 +40,19 @@ export class QueueOrchestrator {
|
|||
}
|
||||
}
|
||||
|
||||
async loginPhone(login: LoginQueueDto): Promise<QueueOrder> {
|
||||
const { name, phone } = login;
|
||||
const now = moment().format('DD/MM/YYYY');
|
||||
try {
|
||||
return await this.dataService.loginPhone(name, phone);
|
||||
} catch (error) {
|
||||
throw new UnauthorizedException({
|
||||
message: `Antrian atas nama ${name} dan nomor telepon ${phone} pada tanggal ${now} tidak ditemukan`,
|
||||
error: 'INVOICE_NOT_FOUND',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async create(data: RegisterQueueDto): Promise<Queue> {
|
||||
const queue = await this.queueService.getTicketItems(
|
||||
data.ticket_id,
|
||||
|
@ -56,16 +71,6 @@ export class QueueOrchestrator {
|
|||
async split(data: SplitQueueDto): Promise<QueueOrder> {
|
||||
const queueIds = data.items.map((i) => i.queue_item_id);
|
||||
const queue = await this.dataService.orderItems(data.order_id, queueIds);
|
||||
// queue.tickets = queue.tickets.map((ticket) => {
|
||||
// ticket.items = ticket.items.map((item) => {
|
||||
// const itemQty = data.items.find((i) => i.queue_item_id === item.id);
|
||||
// return {
|
||||
// ...item,
|
||||
// qty: itemQty.qty,
|
||||
// };
|
||||
// });
|
||||
// return ticket;
|
||||
// });
|
||||
|
||||
this.splitQueueManager.setRequestData(data);
|
||||
this.splitQueueManager.setData(queue);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString, Matches } from 'class-validator';
|
||||
|
||||
export class LoginQueueDto {
|
||||
@ApiProperty({ name: 'name', required: true })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
name: 'phone',
|
||||
required: true,
|
||||
description: 'Phone Number Must Start With 62, no + or 0',
|
||||
example: '628123456789',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^628\d+$/i, { message: 'Nomor Telepon tidak valid' })
|
||||
phone: string;
|
||||
}
|
|
@ -4,6 +4,7 @@ import {
|
|||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsString,
|
||||
Matches,
|
||||
Min,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
@ -35,9 +36,15 @@ export class SplitQueueDto {
|
|||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ name: 'phone', required: true })
|
||||
@ApiProperty({
|
||||
name: 'phone',
|
||||
required: true,
|
||||
description: 'Phone Number Must Start With 62, no + or 0',
|
||||
example: '+628123456789',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^\+628\d+$/i, { message: 'Nomor Telepon tidak valid' })
|
||||
phone: string;
|
||||
|
||||
@ApiProperty({
|
||||
|
|
|
@ -9,6 +9,7 @@ import { QueueOrder } from '../../domain/entities/order.entity';
|
|||
import { Queue } from '../../domain/entities/queue.entity';
|
||||
import { RegisterQueueDto } from './dto/register-queue.dto';
|
||||
import { SplitQueueDto } from './dto/split-queue.dto';
|
||||
import { LoginQueueDto } from './dto/login-queue.dto';
|
||||
|
||||
@ApiTags(`Queue`)
|
||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||
|
@ -27,6 +28,11 @@ export class QueueController {
|
|||
return await this.orchestrator.split(data);
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
async loginQueue(@Body() data: LoginQueueDto): Promise<QueueOrder> {
|
||||
return await this.orchestrator.loginPhone(data);
|
||||
}
|
||||
|
||||
@Get('login/:id')
|
||||
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
||||
return await this.orchestrator.loginCustomer(id);
|
||||
|
|
Loading…
Reference in New Issue