Compare commits
42 Commits
1.3.0-prod
...
production
Author | SHA1 | Date |
---|---|---|
|
0b482be669 | |
|
064112e731 | |
|
05473fce3d | |
|
d6a238a224 | |
|
a8b3f67d1b | |
|
dc5e938f75 | |
|
eb4da7ccc4 | |
|
bef9f99f13 | |
|
46caaba6bd | |
|
8e0c8462b9 | |
|
7953c7dbbd | |
|
6911f6f0a2 | |
|
762340a72b | |
|
00e2b6e015 | |
|
61cbbf81ef | |
|
7b864d4163 | |
|
4ea53f7088 | |
|
00ec2c9342 | |
|
0548141e5f | |
|
440a589f8a | |
|
29e4dc5400 | |
|
f9d8f85179 | |
|
769e8174f4 | |
|
3ace59c450 | |
|
a51b6ea520 | |
|
187555a543 | |
|
750cee8853 | |
|
551bd12f5b | |
|
0a98bcfd59 | |
|
1692c8234a | |
|
9a612cc025 | |
|
903b7cfd18 | |
|
3aee1fdfc9 | |
|
26a6af2044 | |
|
0afaf1d195 | |
|
d7ed77934d | |
|
66720c5b8b | |
|
44e74de315 | |
|
82e7879969 | |
|
ceedf83385 | |
|
d612b6725a | |
|
54b9658075 |
|
@ -44,3 +44,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||||
SUPERSET_ADMIN_USERNAME=admin
|
SUPERSET_ADMIN_USERNAME=admin
|
||||||
SUPERSET_ADMIN_PASSWORD=admin
|
SUPERSET_ADMIN_PASSWORD=admin
|
||||||
|
|
||||||
|
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||||
|
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -41,3 +41,6 @@ GOOGLE_CALENDAR_ID="326464ac296874c7121825f5ef2e2799baa90b51da240f0045aae22beec1
|
||||||
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
SUPERSET_URL=https://dashboard.weplayground.eigen.co.id
|
||||||
SUPERSET_ADMIN_USERNAME=admin
|
SUPERSET_ADMIN_USERNAME=admin
|
||||||
SUPERSET_ADMIN_PASSWORD=admin
|
SUPERSET_ADMIN_PASSWORD=admin
|
||||||
|
|
||||||
|
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID=604883366037548
|
||||||
|
WHATSAPP_BUSINESS_ACCESS_TOKEN=EAAINOvRRiEEBO9yQsYDnYtjHZB7q1nZCwbBpRcxIGMDWajKZBtmWxNRKvPYkS95KQZBsZBOvSFyjiEg5CcCZBZBtaSZApxyV8fiA3cEyVwf7iVZBQP2YCTPRQZArMFeeXbO0uq5TGygmjsIz3M4YxcUHxPzKO4pKxIyxnzcoUZCqCSo1NqQSLVf3a0JyZAwgDXGL55dV
|
|
@ -49,6 +49,7 @@
|
||||||
"exceljs": "^4.4.0",
|
"exceljs": "^4.4.0",
|
||||||
"fs-extra": "^11.2.0",
|
"fs-extra": "^11.2.0",
|
||||||
"googleapis": "^140.0.0",
|
"googleapis": "^140.0.0",
|
||||||
|
"gtts": "^0.2.1",
|
||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"mathjs": "^13.0.2",
|
"mathjs": "^13.0.2",
|
||||||
"midtrans-client": "^1.3.1",
|
"midtrans-client": "^1.3.1",
|
||||||
|
|
|
@ -5,7 +5,7 @@ export class AddEstimationToItem1723801180604 implements MigrationInterface {
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "items" ADD "play_estimation" integer`,
|
`ALTER TABLE "items" ADD "play_estimation" numeric`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddNotificationConfigToItemQueue1734717058658
|
||||||
|
implements MigrationInterface
|
||||||
|
{
|
||||||
|
name = 'AddNotificationConfigToItemQueue1734717058658';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" ADD "use_notification" boolean NOT NULL DEFAULT true`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" ADD "requiring_notification" boolean NOT NULL DEFAULT false`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" DROP COLUMN "requiring_notification"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "item_queues" DROP COLUMN "use_notification"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddLastNotificationToQueue1734718462106
|
||||||
|
implements MigrationInterface
|
||||||
|
{
|
||||||
|
name = 'AddLastNotificationToQueue1734718462106';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "queues" ADD "last_notification" bigint NULL`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "queues" DROP COLUMN "last_notification"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -73,13 +73,14 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
||||||
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||||
error: 'Unauthorized',
|
error: 'Unauthorized',
|
||||||
});
|
});
|
||||||
} else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
|
||||||
throw new UnauthorizedException({
|
|
||||||
statusCode: HttpStatus.UNAUTHORIZED,
|
|
||||||
message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
|
||||||
error: 'Unauthorized',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// else if (itemLogin && itemLogin.user_id !== this.userLogin.id) {
|
||||||
|
// throw new UnauthorizedException({
|
||||||
|
// statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
// message: `"${userLoginItem.name}" masih login sebagai admin antrian `,
|
||||||
|
// error: 'Unauthorized',
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
// * Disini untuk isi token
|
// * Disini untuk isi token
|
||||||
const tokenData = {
|
const tokenData = {
|
||||||
|
|
|
@ -19,6 +19,7 @@ export class CouchService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
|
// return;
|
||||||
const nano = this.nanoInstance;
|
const nano = this.nanoInstance;
|
||||||
for (const database of DatabaseListen) {
|
for (const database of DatabaseListen) {
|
||||||
const db = nano.db.use(database);
|
const db = nano.db.use(database);
|
||||||
|
@ -95,4 +96,41 @@ export class CouchService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUnixTimestampLast7Days() {
|
||||||
|
const date = new Date();
|
||||||
|
date.setDate(date.getDate() - 4);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async clearTransactions() {
|
||||||
|
const nano = this.nanoInstance;
|
||||||
|
const transaction = nano.use('transaction');
|
||||||
|
|
||||||
|
const expiredDate = this.getUnixTimestampLast7Days();
|
||||||
|
|
||||||
|
const selectorPayment = {
|
||||||
|
created_at: {
|
||||||
|
$lt: expiredDate,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const transactions = await transaction.find({
|
||||||
|
selector: selectorPayment,
|
||||||
|
fields: ['_id', '_rev'],
|
||||||
|
limit: 100000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { docs } = transactions;
|
||||||
|
console.log(docs.length);
|
||||||
|
const deletedDocs = {
|
||||||
|
docs: docs.map((doc) => ({
|
||||||
|
_id: doc._id,
|
||||||
|
_rev: doc._rev,
|
||||||
|
_deleted: true,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
await transaction.bulk(deletedDocs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@ import { Public } from 'src/core/guards';
|
||||||
import * as Nano from 'nano';
|
import * as Nano from 'nano';
|
||||||
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { CouchService } from '../data/services/couch.service';
|
||||||
|
|
||||||
@ApiTags(`couch`)
|
@ApiTags(`couch`)
|
||||||
@Controller('v1/couch')
|
@Controller('v1/couch')
|
||||||
@Public()
|
@Public()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CouchDataController {
|
export class CouchDataController {
|
||||||
constructor(private configService: ConfigService) {}
|
constructor(
|
||||||
|
private configService: ConfigService,
|
||||||
|
private couchService: CouchService,
|
||||||
|
) {}
|
||||||
|
|
||||||
get nanoInstance() {
|
get nanoInstance() {
|
||||||
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
||||||
|
@ -64,4 +68,11 @@ export class CouchDataController {
|
||||||
// return people.get();
|
// return people.get();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public(true)
|
||||||
|
@Get('clear-transactions')
|
||||||
|
async clearTransactions(): Promise<string> {
|
||||||
|
await this.couchService.clearTransactions();
|
||||||
|
return 'OK';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,10 @@ export class ItemQueueModel
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
})
|
})
|
||||||
items: ItemModel[];
|
items: ItemModel[];
|
||||||
|
|
||||||
|
@Column('boolean', { default: true })
|
||||||
|
use_notification: boolean;
|
||||||
|
|
||||||
|
@Column('boolean', { default: false })
|
||||||
|
requiring_notification: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,4 +9,6 @@ export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
max_peak_level: number;
|
max_peak_level: number;
|
||||||
call_preparation: number;
|
call_preparation: number;
|
||||||
items: ItemEntity[];
|
items: ItemEntity[];
|
||||||
|
use_notification?: boolean;
|
||||||
|
requiring_notification?: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.editor_name`,
|
`${this.tableName}.editor_name`,
|
||||||
`${this.tableName}.max_peak_level`,
|
`${this.tableName}.max_peak_level`,
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
|
`${this.tableName}.use_notification`,
|
||||||
|
`${this.tableName}.requiring_notification`,
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
|
|
@ -41,6 +41,8 @@ export class IndexItemQueueManager extends BaseIndexManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.editor_name`,
|
`${this.tableName}.editor_name`,
|
||||||
`${this.tableName}.max_peak_level`,
|
`${this.tableName}.max_peak_level`,
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
|
`${this.tableName}.use_notification`,
|
||||||
|
`${this.tableName}.requiring_notification`,
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Param,
|
||||||
|
Query,
|
||||||
|
UnauthorizedException,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { FilterItemQueueDto } from './dto/filter-item-queue.dto';
|
import { FilterItemQueueDto } from './dto/filter-item-queue.dto';
|
||||||
import { Pagination } from 'src/core/response';
|
import { Pagination } from 'src/core/response';
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
@ -7,6 +13,7 @@ import { ItemQueueReadOrchestrator } from '../domain/usecases/item-queue-read.or
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
import { validate as isValidUUID } from 'uuid';
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
@ApiTags(`${MODULE_NAME.ITEM_QUEUE.split('-').join(' ')} - read`)
|
||||||
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.ITEM_QUEUE}`)
|
||||||
|
@ -44,6 +51,7 @@ export class ItemQueueReadController {
|
||||||
@Get('display/:id')
|
@Get('display/:id')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
|
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
||||||
return await this.orchestrator.detail(id);
|
return await this.orchestrator.detail(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class ItemModel
|
||||||
@Column('bigint', { name: 'base_price', nullable: true })
|
@Column('bigint', { name: 'base_price', nullable: true })
|
||||||
base_price: number;
|
base_price: number;
|
||||||
|
|
||||||
@Column('int', { name: 'play_estimation', nullable: true })
|
@Column('decimal', { name: 'play_estimation', nullable: true })
|
||||||
play_estimation: number;
|
play_estimation: number;
|
||||||
|
|
||||||
@Column('boolean', { name: 'use_queue', default: false })
|
@Column('boolean', { name: 'use_queue', default: false })
|
||||||
|
|
|
@ -115,6 +115,9 @@ export class QueueModel extends BaseModel<Queue> implements Queue {
|
||||||
@Column({ type: 'bigint' })
|
@Column({ type: 'bigint' })
|
||||||
time: number;
|
time: number;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint', nullable: true })
|
||||||
|
last_notification: number;
|
||||||
|
|
||||||
@Column({ type: 'bigint' })
|
@Column({ type: 'bigint' })
|
||||||
call_time: number;
|
call_time: number;
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,15 @@ export class QueueService extends BaseDataService<QueueModel> {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async queueTicket(queueId: string) {
|
||||||
|
return this.repo.findOne({
|
||||||
|
relations: ['item', 'item.ticket'],
|
||||||
|
where: {
|
||||||
|
id: queueId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async queues(ids: string[]) {
|
async queues(ids: string[]) {
|
||||||
const start = moment().startOf('day').valueOf();
|
const start = moment().startOf('day').valueOf();
|
||||||
const end = moment().endOf('day').valueOf();
|
const end = moment().endOf('day').valueOf();
|
||||||
|
@ -225,6 +234,11 @@ export class QueueService extends BaseDataService<QueueModel> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateLastNotification(queue_id: string, time: number) {
|
||||||
|
const query = `UPDATE queues SET last_notification = ${time} WHERE id = '${queue_id}'`;
|
||||||
|
this.dataSource.query(query);
|
||||||
|
}
|
||||||
|
|
||||||
async updateItemQty(item_id: string, qty: number): Promise<void> {
|
async updateItemQty(item_id: string, qty: number): Promise<void> {
|
||||||
const query = `UPDATE queue_items SET qty = qty - ${qty} WHERE id = '${item_id}'`;
|
const query = `UPDATE queue_items SET qty = qty - ${qty} WHERE id = '${item_id}'`;
|
||||||
this.dataSource.query(query);
|
this.dataSource.query(query);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
} from '../models/queue.model';
|
} from '../models/queue.model';
|
||||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TicketDataService extends BaseDataService<QueueTicket> {
|
export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
@ -23,6 +24,9 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
|
||||||
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
private item: Repository<QueueItemModel>,
|
private item: Repository<QueueItemModel>,
|
||||||
|
|
||||||
|
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||||
|
private transaction: Repository<TransactionModel>,
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
@ -36,13 +40,37 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginQueue(id: string): Promise<QueueOrder> {
|
async loginQueue(id: string): Promise<QueueOrder> {
|
||||||
return this.order.findOneOrFail({
|
const order = await this.order.findOne({
|
||||||
relations: ['tickets'],
|
relations: ['tickets'],
|
||||||
where: [
|
where: [
|
||||||
{ transaction_id: id },
|
{ transaction_id: id },
|
||||||
{ code: id, transaction_id: Not(IsNull()) },
|
{ code: id, transaction_id: Not(IsNull()) },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!order) {
|
||||||
|
const { customer_name, customer_phone } =
|
||||||
|
await this.transaction.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const start = moment().startOf('day').valueOf();
|
||||||
|
const end = moment().endOf('day').valueOf();
|
||||||
|
const order = this.order.findOneOrFail({
|
||||||
|
relations: ['tickets'],
|
||||||
|
where: {
|
||||||
|
customer: customer_name,
|
||||||
|
phone: customer_phone,
|
||||||
|
date: Between(start, end),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
async ticketByCode(code: string): Promise<QueueTicketModel[]> {
|
async ticketByCode(code: string): Promise<QueueTicketModel[]> {
|
||||||
|
|
|
@ -9,3 +9,15 @@ export function toTime(timestamp: number): string {
|
||||||
minutes < 10 ? '0' : ''
|
minutes < 10 ? '0' : ''
|
||||||
}${minutes}`;
|
}${minutes}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function phoneNumberOnly(phone: string): string {
|
||||||
|
return phone.replace(/[^0-9]/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function timeIsBefore(
|
||||||
|
currentTime: number,
|
||||||
|
time: number,
|
||||||
|
diffInMilliseconds: number,
|
||||||
|
): boolean {
|
||||||
|
return time < currentTime + diffInMilliseconds;
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,11 @@ import {
|
||||||
ORDER_TYPE,
|
ORDER_TYPE,
|
||||||
QUEUE_STATUS,
|
QUEUE_STATUS,
|
||||||
} from 'src/core/strings/constants/base.constants';
|
} from 'src/core/strings/constants/base.constants';
|
||||||
|
import { QueueTimeFormula } from './usecases/formula/queue-time.formula';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { timeIsBefore } from './helpers/time.helper';
|
||||||
|
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||||
|
import { WhatsappQueue } from 'src/services/whatsapp/entity/whatsapp-queue.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueAdminOrchestrator {
|
export class QueueAdminOrchestrator {
|
||||||
|
@ -21,6 +26,7 @@ export class QueueAdminOrchestrator {
|
||||||
private indexManager: IndexQueueManager,
|
private indexManager: IndexQueueManager,
|
||||||
private callManager: CallQueueManager,
|
private callManager: CallQueueManager,
|
||||||
private doneManager: DoneQueueManager,
|
private doneManager: DoneQueueManager,
|
||||||
|
private readonly queueTimeFormula: QueueTimeFormula,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async index(params): Promise<PaginationResponse<Queue>> {
|
async index(params): Promise<PaginationResponse<Queue>> {
|
||||||
|
@ -43,4 +49,53 @@ export class QueueAdminOrchestrator {
|
||||||
await this.doneManager.execute();
|
await this.doneManager.execute();
|
||||||
return this.doneManager.getResult();
|
return this.doneManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async job(): Promise<void> {
|
||||||
|
const notification = new WhatsappService();
|
||||||
|
const itemMasters = await this.dataService.allQueue();
|
||||||
|
const currentTime = moment().valueOf();
|
||||||
|
|
||||||
|
for (const queueItem of itemMasters) {
|
||||||
|
const queueTimes = await this.queueTimeFormula.items(queueItem.id);
|
||||||
|
const call_preparation = queueItem.call_preparation * 60 * 1000;
|
||||||
|
if (!queueItem.use_notification) continue;
|
||||||
|
|
||||||
|
for (const queueId in queueTimes) {
|
||||||
|
const callTime = queueTimes[queueId];
|
||||||
|
|
||||||
|
const queueTicket = await this.service.queueTicket(queueId);
|
||||||
|
if (
|
||||||
|
queueItem.requiring_notification ||
|
||||||
|
(timeIsBefore(currentTime, callTime, call_preparation) &&
|
||||||
|
queueTicket.time > currentTime)
|
||||||
|
) {
|
||||||
|
const payload: WhatsappQueue = {
|
||||||
|
id: queueId,
|
||||||
|
phone: queueTicket.item.ticket.phone,
|
||||||
|
code: queueTicket.code,
|
||||||
|
name: queueTicket.item.ticket.customer,
|
||||||
|
item_name: queueItem.name,
|
||||||
|
time: callTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
// console.table([
|
||||||
|
// {
|
||||||
|
// code: queueTicket.code,
|
||||||
|
// currentTime: toTime(currentTime),
|
||||||
|
// callTime: toTime(callTime),
|
||||||
|
// lastNotification: toTime(queueTicket.last_notification),
|
||||||
|
// },
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
if (
|
||||||
|
queueTicket.item.ticket.phone != null &&
|
||||||
|
queueTicket.last_notification < currentTime - call_preparation
|
||||||
|
) {
|
||||||
|
await notification.queueProcess(payload);
|
||||||
|
this.service.updateLastNotification(queueId, currentTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,13 @@ 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';
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
import { CustomerQueuePosItemManager } from './usecases/queue/customer-queue-pos-item.manager';
|
import { CustomerQueuePosItemManager } from './usecases/queue/customer-queue-pos-item.manager';
|
||||||
import { QueueOrderModel, QueueTicketModel } from '../data/models/queue.model';
|
import {
|
||||||
|
QueueModel,
|
||||||
|
QueueOrderModel,
|
||||||
|
QueueTicketModel,
|
||||||
|
} from '../data/models/queue.model';
|
||||||
import { CustomerQueueRecommendManager } from './usecases/queue/customer-queue-recommend.manager';
|
import { CustomerQueueRecommendManager } from './usecases/queue/customer-queue-recommend.manager';
|
||||||
|
import { GenerateQueueManager } from './usecases/generate-queue.manager';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueOrchestrator {
|
export class QueueOrchestrator {
|
||||||
|
@ -35,8 +40,13 @@ export class QueueOrchestrator {
|
||||||
private readonly registerQueueManager: RegisterQueueManager,
|
private readonly registerQueueManager: RegisterQueueManager,
|
||||||
private readonly splitQueueManager: SplitQueueManager,
|
private readonly splitQueueManager: SplitQueueManager,
|
||||||
private readonly queueDataService: QueueDataService,
|
private readonly queueDataService: QueueDataService,
|
||||||
|
private readonly generateQueueManager: GenerateQueueManager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async generate(data: any): Promise<QueueModel[]> {
|
||||||
|
return await this.generateQueueManager.generate(data);
|
||||||
|
}
|
||||||
|
|
||||||
async loginCustomer(id: string): Promise<QueueOrder> {
|
async loginCustomer(id: string): Promise<QueueOrder> {
|
||||||
try {
|
try {
|
||||||
const order = await this.dataService.loginQueue(id);
|
const order = await this.dataService.loginQueue(id);
|
||||||
|
|
|
@ -31,7 +31,7 @@ export class QueueTimeFormula {
|
||||||
|
|
||||||
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
||||||
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
||||||
this.average = average;
|
this.average = Math.floor(average);
|
||||||
|
|
||||||
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,161 @@
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { TransactionUserType } from 'src/modules/transaction/transaction/constants';
|
||||||
|
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
|
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
||||||
|
import { QueueService } from '../../data/services/queue.service';
|
||||||
|
import { TicketDataService } from '../../data/services/ticket.service';
|
||||||
|
import { RegisterQueueDto } from '../../infrastructure/controllers/dto/register-queue.dto';
|
||||||
|
import { QueueOrder } from '../entities/order.entity';
|
||||||
|
import { QueueItem } from '../entities/queue-item.entity';
|
||||||
|
import { QueueTicket } from '../entities/ticket.entity';
|
||||||
|
import { QueueTimeFormula } from './formula/queue-time.formula';
|
||||||
|
import { RegisterQueueManager } from './register-queue.manager';
|
||||||
|
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
||||||
|
import { QueueModel } from '../../data/models/queue.model';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class GenerateQueueManager {
|
||||||
|
constructor(
|
||||||
|
private readonly ticketService: TicketDataService,
|
||||||
|
private readonly queueService: QueueService,
|
||||||
|
private readonly bucketService: QueueBucketReadService,
|
||||||
|
private readonly queueTimeFormula: QueueTimeFormula,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async generate(transaction: TransactionModel) {
|
||||||
|
const date = transaction.booking_date ?? transaction.invoice_date;
|
||||||
|
const queue_date = moment(date, 'YYYY-MM-DD').unix();
|
||||||
|
|
||||||
|
const { id, customer_name, customer_phone, invoice_code } = transaction;
|
||||||
|
|
||||||
|
const customerOrder = {
|
||||||
|
code: invoice_code,
|
||||||
|
customer: customer_name,
|
||||||
|
phone: customer_phone,
|
||||||
|
date: queue_date * 1000,
|
||||||
|
transaction_id: id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const items = this.generateItems(transaction.items);
|
||||||
|
|
||||||
|
const existTicket = await this.ticketService.ticketByUser(
|
||||||
|
customer_name,
|
||||||
|
customer_phone,
|
||||||
|
);
|
||||||
|
|
||||||
|
const insertTickets: QueueTicket[] = [];
|
||||||
|
if (customer_name && customer_phone && existTicket) {
|
||||||
|
existTicket.items.push(...items);
|
||||||
|
await this.ticketService.updateQueueTicket(existTicket);
|
||||||
|
|
||||||
|
existTicket.items = items;
|
||||||
|
insertTickets.push(existTicket);
|
||||||
|
} else {
|
||||||
|
const ticket: QueueTicket = { ...customerOrder, items };
|
||||||
|
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
||||||
|
|
||||||
|
const queueOrder = await this.ticketService.createQueueOrder(order);
|
||||||
|
insertTickets.push(...queueOrder.tickets);
|
||||||
|
}
|
||||||
|
|
||||||
|
const results: QueueModel[] = [];
|
||||||
|
const vipCustomer =
|
||||||
|
transaction.customer_category?.has_vip_pass ||
|
||||||
|
transaction.customer_type === TransactionUserType.VIP;
|
||||||
|
if (vipCustomer || transaction.creator_counter_no != null) {
|
||||||
|
for (const ticket of insertTickets) {
|
||||||
|
const ticket_id = ticket.id;
|
||||||
|
const items = {};
|
||||||
|
|
||||||
|
ticket.items.forEach((item) => {
|
||||||
|
const item_id = item['item_queue_id'];
|
||||||
|
const currentItem = items[item_id];
|
||||||
|
|
||||||
|
if (currentItem) {
|
||||||
|
currentItem.qty += item.qty;
|
||||||
|
}
|
||||||
|
items[item_id] = currentItem
|
||||||
|
? currentItem
|
||||||
|
: {
|
||||||
|
item_id,
|
||||||
|
ticket_id,
|
||||||
|
qty: item.qty,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const payload of Object.values(items)) {
|
||||||
|
const isVip = vipCustomer || transaction.creator_counter_no == null;
|
||||||
|
const result = await this.create(payload as any, isVip);
|
||||||
|
results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateItems(items: TransactionItemModel[]): QueueItem[] {
|
||||||
|
const transactionItems = [];
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (item.item.use_queue) {
|
||||||
|
transactionItems.push({
|
||||||
|
item_queue_id: item.item.item_queue_id,
|
||||||
|
item_id: item.item_id,
|
||||||
|
qty: item.qty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.item.bundling_items.length > 0) {
|
||||||
|
item.item.bundling_items.forEach((bundling_item) => {
|
||||||
|
if (bundling_item.use_queue) {
|
||||||
|
transactionItems.push({
|
||||||
|
item_queue_id: bundling_item.item_queue_id,
|
||||||
|
item_id: bundling_item.id,
|
||||||
|
qty: item.qty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.mergeQueueItems(transactionItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeQueueItems(arr) {
|
||||||
|
const result = {};
|
||||||
|
arr.forEach((item) => {
|
||||||
|
if (result[item.item_id]) {
|
||||||
|
result[item.item_id].qty += item.qty;
|
||||||
|
} else {
|
||||||
|
result[item.item_id] = { ...item };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Object.values<QueueItem>(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: RegisterQueueDto, isVip = false): Promise<QueueModel> {
|
||||||
|
const queue = await this.queueService.getTicketItems(
|
||||||
|
data.ticket_id,
|
||||||
|
data.item_id,
|
||||||
|
);
|
||||||
|
const queueRequest: any = {
|
||||||
|
qty: data.qty,
|
||||||
|
item_id: queue.id,
|
||||||
|
vip: isVip,
|
||||||
|
};
|
||||||
|
const registerQueueManager = new RegisterQueueManager(
|
||||||
|
this.bucketService,
|
||||||
|
this.queueTimeFormula,
|
||||||
|
);
|
||||||
|
registerQueueManager.setData(queueRequest);
|
||||||
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
|
await registerQueueManager.execute();
|
||||||
|
|
||||||
|
const result = await registerQueueManager.getResult();
|
||||||
|
result.time = null;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,10 +89,13 @@ export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
|
|
||||||
console.log({ start, end, item_queue_id: this.filterParam.queue_id });
|
console.log({ start, end, item_queue_id: this.filterParam.queue_id });
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.time BETWEEN :start AND :end`, {
|
queryBuilder.andWhere(
|
||||||
|
`${this.tableName}.created_at BETWEEN :start AND :end`,
|
||||||
|
{
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.item_queue_id = :item_queue_id`, {
|
queryBuilder.andWhere(`${this.tableName}.item_queue_id = :item_queue_id`, {
|
||||||
item_queue_id: this.filterParam.queue_id,
|
item_queue_id: this.filterParam.queue_id,
|
||||||
|
|
|
@ -11,6 +11,8 @@ import { padCode } from 'src/modules/transaction/vip-code/domain/usecases/manage
|
||||||
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
import { QueueTimeFormula } from './formula/queue-time.formula';
|
import { QueueTimeFormula } from './formula/queue-time.formula';
|
||||||
|
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||||
|
import { WhatsappQueue } from 'src/services/whatsapp/entity/whatsapp-queue.entity';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -22,6 +24,8 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private currentItemMaster: ItemModel;
|
||||||
|
|
||||||
async averageTime(): Promise<number> {
|
async averageTime(): Promise<number> {
|
||||||
const item = await this.getItemMaster();
|
const item = await this.getItemMaster();
|
||||||
return item.play_estimation;
|
return item.play_estimation;
|
||||||
|
@ -34,12 +38,13 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
const first = queues[0];
|
const first = queues[0];
|
||||||
const last = queues[queues.length - 1] ?? moment().valueOf();
|
const last = queues[queues.length - 1] ?? moment().valueOf();
|
||||||
const average = this.queueTimeFormula.average;
|
const average = this.queueTimeFormula.average;
|
||||||
return [first, last + average];
|
return [Math.floor(first), Math.floor(last + average)];
|
||||||
}
|
}
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
const vip = this.data.vip ?? false;
|
const vip = this.data.vip ?? false;
|
||||||
const item = await this.getItemMaster();
|
const item = await this.getItemMaster();
|
||||||
|
this.currentItemMaster = item;
|
||||||
const [, end] = await this.queueTime(item.item_queue_id);
|
const [, end] = await this.queueTime(item.item_queue_id);
|
||||||
|
|
||||||
const queueNumber = await this.bucketService.getQueue(
|
const queueNumber = await this.bucketService.getQueue(
|
||||||
|
@ -61,7 +66,7 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
|
|
||||||
async getItemMaster(): Promise<ItemModel> {
|
async getItemMaster(): Promise<ItemModel> {
|
||||||
const queueItem: QueueItemModel = await this.dataService.item.findOne({
|
const queueItem: QueueItemModel = await this.dataService.item.findOne({
|
||||||
relations: ['item'],
|
relations: ['item', 'item.item_queue'],
|
||||||
where: {
|
where: {
|
||||||
id: this.data.item_id,
|
id: this.data.item_id,
|
||||||
},
|
},
|
||||||
|
@ -71,6 +76,27 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
|
const notificationService = new WhatsappService();
|
||||||
|
const item = this.currentItemMaster ?? (await this.getItemMaster());
|
||||||
|
|
||||||
|
if (!item.item_queue.use_notification) return;
|
||||||
|
|
||||||
|
const queueTicket = await this.dataService.queueTicket(this.result.id);
|
||||||
|
|
||||||
|
const payload: WhatsappQueue = {
|
||||||
|
id: this.result.id,
|
||||||
|
phone: queueTicket.item.ticket.phone,
|
||||||
|
code: this.result.code,
|
||||||
|
name: queueTicket.item.ticket.customer,
|
||||||
|
item_name: item.name,
|
||||||
|
time: this.result.time,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (payload.phone) {
|
||||||
|
notificationService.queueRegister(payload);
|
||||||
|
const currentTime = moment().valueOf();
|
||||||
|
this.dataService.updateLastNotification(this.result.id, currentTime);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { Controller, Logger, Post } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
import { QueueAdminOrchestrator } from '../../domain/queue-admin.orchestrator';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
// import { Cron } from '@nestjs/schedule';
|
||||||
|
|
||||||
|
@ApiTags(`Queue Admin`)
|
||||||
|
@Controller(`v1/${MODULE_NAME.QUEUE}-job`)
|
||||||
|
@ApiBearerAuth('JWT')
|
||||||
|
@Public(true)
|
||||||
|
export class QueueJobController {
|
||||||
|
constructor(private orchestrator: QueueAdminOrchestrator) {}
|
||||||
|
|
||||||
|
// @Cron('*/1 * * * *')
|
||||||
|
@Post('queues/notification')
|
||||||
|
async call() {
|
||||||
|
Logger.log('call preparation');
|
||||||
|
return this.orchestrator.job();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Post, Query, Res } from '@nestjs/common';
|
||||||
|
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
@ -11,6 +11,12 @@ 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';
|
import { LoginReceiptDto } from './dto/login-receipt.dto';
|
||||||
|
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||||
|
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||||
|
import { QueueModel } from '../../data/models/queue.model';
|
||||||
|
|
||||||
|
import * as Gtts from 'gtts';
|
||||||
|
import { Response } from 'express';
|
||||||
|
|
||||||
@ApiTags(`Queue`)
|
@ApiTags(`Queue`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||||
|
@ -19,6 +25,12 @@ import { LoginReceiptDto } from './dto/login-receipt.dto';
|
||||||
export class QueueController {
|
export class QueueController {
|
||||||
constructor(private orchestrator: QueueOrchestrator) {}
|
constructor(private orchestrator: QueueOrchestrator) {}
|
||||||
|
|
||||||
|
@Post('generate')
|
||||||
|
async generateQueue(@Body() data: any): Promise<QueueModel[]> {
|
||||||
|
mappingRevertTransaction(data, TransactionType.COUNTER);
|
||||||
|
return await this.orchestrator.generate(data);
|
||||||
|
}
|
||||||
|
|
||||||
@Post('register')
|
@Post('register')
|
||||||
async registerQueue(@Body() data: RegisterQueueDto): Promise<Queue> {
|
async registerQueue(@Body() data: RegisterQueueDto): Promise<Queue> {
|
||||||
return await this.orchestrator.create(data);
|
return await this.orchestrator.create(data);
|
||||||
|
@ -96,6 +108,15 @@ export class QueueController {
|
||||||
return await this.orchestrator.queueOrderItems(id);
|
return await this.orchestrator.queueOrderItems(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('speech')
|
||||||
|
async speech(
|
||||||
|
@Query('text') text: string,
|
||||||
|
@Res() response: Response,
|
||||||
|
): Promise<void> {
|
||||||
|
const gtts = new Gtts(text, 'id');
|
||||||
|
gtts.stream().pipe(response);
|
||||||
|
}
|
||||||
|
|
||||||
@Get(':id/items/:item_id')
|
@Get(':id/items/:item_id')
|
||||||
async queueItemTickets(
|
async queueItemTickets(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|
|
@ -4,19 +4,7 @@ import {
|
||||||
TransactionChangeStatusEvent,
|
TransactionChangeStatusEvent,
|
||||||
TransactionCreateQueueEvent,
|
TransactionCreateQueueEvent,
|
||||||
} from 'src/modules/transaction/transaction/domain/entities/event/transaction-change-status.event';
|
} from 'src/modules/transaction/transaction/domain/entities/event/transaction-change-status.event';
|
||||||
import { TicketDataService } from '../../data/services/ticket.service';
|
import { GenerateQueueManager } from '../../domain/usecases/generate-queue.manager';
|
||||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
|
||||||
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
|
||||||
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
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';
|
|
||||||
import { QueueTimeFormula } from '../../domain/usecases/formula/queue-time.formula';
|
|
||||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
|
||||||
|
|
||||||
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
||||||
export class QueueTransactionHandler
|
export class QueueTransactionHandler
|
||||||
|
@ -24,10 +12,7 @@ export class QueueTransactionHandler
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
private readonly dataService: TransactionDataService,
|
private readonly dataService: TransactionDataService,
|
||||||
private readonly ticketService: TicketDataService,
|
private readonly queueGenerateManager: GenerateQueueManager,
|
||||||
private readonly queueService: QueueService,
|
|
||||||
private readonly bucketService: QueueBucketReadService,
|
|
||||||
private readonly queueTimeFormula: QueueTimeFormula,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
async handle(event: TransactionChangeStatusEvent) {
|
||||||
|
@ -36,7 +21,8 @@ export class QueueTransactionHandler
|
||||||
/**
|
/**
|
||||||
* If data still in process (not settled) then don't create the queue order
|
* If data still in process (not settled) then don't create the queue order
|
||||||
*/
|
*/
|
||||||
if (process_data?.status != 'settled') return;
|
if (process_data?.status != 'settled' || process_data?.pos_number != null)
|
||||||
|
return;
|
||||||
|
|
||||||
const transaction = await this.dataService.getOneByOptions({
|
const transaction = await this.dataService.getOneByOptions({
|
||||||
where: {
|
where: {
|
||||||
|
@ -50,127 +36,6 @@ export class QueueTransactionHandler
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const date = transaction.booking_date ?? transaction.invoice_date;
|
await this.queueGenerateManager.generate(transaction);
|
||||||
const queue_date = moment(date, 'YYYY-MM-DD').unix();
|
|
||||||
|
|
||||||
const { id, customer_name, customer_phone, invoice_code } = transaction;
|
|
||||||
|
|
||||||
const customerOrder = {
|
|
||||||
code: invoice_code,
|
|
||||||
customer: customer_name,
|
|
||||||
phone: customer_phone,
|
|
||||||
date: queue_date * 1000,
|
|
||||||
transaction_id: id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const items = this.generateItems(transaction.items);
|
|
||||||
|
|
||||||
const existTicket = await this.ticketService.ticketByUser(
|
|
||||||
customer_name,
|
|
||||||
customer_phone,
|
|
||||||
);
|
|
||||||
|
|
||||||
const insertTickets: QueueTicket[] = [];
|
|
||||||
if (customer_name && customer_phone && existTicket) {
|
|
||||||
existTicket.items.push(...items);
|
|
||||||
await this.ticketService.updateQueueTicket(existTicket);
|
|
||||||
|
|
||||||
existTicket.items = items;
|
|
||||||
insertTickets.push(existTicket);
|
|
||||||
} else {
|
|
||||||
const ticket: QueueTicket = { ...customerOrder, items };
|
|
||||||
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
|
||||||
|
|
||||||
const queueOrder = await this.ticketService.createQueueOrder(order);
|
|
||||||
insertTickets.push(...queueOrder.tickets);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
transaction.customer_category?.has_vip_pass ||
|
|
||||||
transaction.customer_type === TransactionUserType.VIP
|
|
||||||
) {
|
|
||||||
insertTickets.forEach((ticket) => {
|
|
||||||
const ticket_id = ticket.id;
|
|
||||||
const items = {};
|
|
||||||
ticket.items.forEach((item) => {
|
|
||||||
const item_id = item['item_queue_id'];
|
|
||||||
const currentItem = items[item_id];
|
|
||||||
|
|
||||||
if (currentItem) {
|
|
||||||
currentItem.qty += item.qty;
|
|
||||||
}
|
|
||||||
items[item_id] = currentItem
|
|
||||||
? currentItem
|
|
||||||
: {
|
|
||||||
item_id,
|
|
||||||
ticket_id,
|
|
||||||
qty: item.qty,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
Object.values(items).forEach((payload: any) => {
|
|
||||||
this.create(payload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
generateItems(items: TransactionItemModel[]): QueueItem[] {
|
|
||||||
const transactionItems = [];
|
|
||||||
|
|
||||||
items.forEach((item) => {
|
|
||||||
if (item.item.use_queue) {
|
|
||||||
transactionItems.push({
|
|
||||||
item_queue_id: item.item.item_queue_id,
|
|
||||||
item_id: item.item_id,
|
|
||||||
qty: item.qty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.item.bundling_items.length > 0) {
|
|
||||||
item.item.bundling_items.forEach((bundling_item) => {
|
|
||||||
if (bundling_item.use_queue) {
|
|
||||||
transactionItems.push({
|
|
||||||
item_queue_id: bundling_item.item_queue_id,
|
|
||||||
item_id: bundling_item.id,
|
|
||||||
qty: item.qty,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.mergeQueueItems(transactionItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeQueueItems(arr) {
|
|
||||||
const result = {};
|
|
||||||
arr.forEach((item) => {
|
|
||||||
if (result[item.item_id]) {
|
|
||||||
result[item.item_id].qty += item.qty;
|
|
||||||
} else {
|
|
||||||
result[item.item_id] = { ...item };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Object.values<QueueItem>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
vip: true,
|
|
||||||
};
|
|
||||||
const registerQueueManager = new RegisterQueueManager(
|
|
||||||
this.bucketService,
|
|
||||||
this.queueTimeFormula,
|
|
||||||
);
|
|
||||||
registerQueueManager.setData(queueRequest);
|
|
||||||
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
|
||||||
await registerQueueManager.execute();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ import { SplitQueueManager } from './domain/usecases/split-queue.manager';
|
||||||
import { QueueTransactionCancelHandler } from './infrastructure/handlers/cancel-transaction.handler';
|
import { QueueTransactionCancelHandler } from './infrastructure/handlers/cancel-transaction.handler';
|
||||||
import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queue.model';
|
||||||
import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||||
|
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
||||||
|
import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -56,7 +58,7 @@ import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [QueueController, QueueAdminController],
|
controllers: [QueueController, QueueAdminController, QueueJobController],
|
||||||
providers: [
|
providers: [
|
||||||
QueueOrchestrator,
|
QueueOrchestrator,
|
||||||
QueueAdminOrchestrator,
|
QueueAdminOrchestrator,
|
||||||
|
@ -78,6 +80,7 @@ import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||||
SplitQueueManager,
|
SplitQueueManager,
|
||||||
|
|
||||||
QueueTimeFormula,
|
QueueTimeFormula,
|
||||||
|
GenerateQueueManager,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class QueueModule {}
|
export class QueueModule {}
|
||||||
|
|
|
@ -116,7 +116,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
id: data.booking_id ?? data._id,
|
id: data.booking_id ?? data._id ?? data.id,
|
||||||
creator_counter_no: Number(data.pos_number),
|
creator_counter_no: Number(data.pos_number),
|
||||||
creator_counter_name: data.pos_name,
|
creator_counter_name: data.pos_name,
|
||||||
settlement_date: new Date(data.created_at),
|
settlement_date: new Date(data.created_at),
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export interface WhatsappQueue {
|
||||||
|
id: string;
|
||||||
|
phone: string;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
item_name: string;
|
||||||
|
time: number;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
export const WHATSAPP_BUSINESS_API_URL =
|
||||||
|
process.env.WHATSAPP_BUSINESS_API_URL ?? 'https://graph.facebook.com/';
|
||||||
|
|
||||||
|
export const WHATSAPP_BUSINESS_VERSION =
|
||||||
|
process.env.WHATSAPP_BUSINESS_VERSION ?? 'v21.0';
|
||||||
|
|
||||||
|
export const WHATSAPP_BUSINESS_QUEUE_URL =
|
||||||
|
process.env.WHATSAPP_BUSINESS_QUEUE_URL ?? 'auth/login';
|
||||||
|
|
||||||
|
export const WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID =
|
||||||
|
process.env.WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID ?? '';
|
||||||
|
|
||||||
|
export const WHATSAPP_BUSINESS_ACCESS_TOKEN =
|
||||||
|
process.env.WHATSAPP_BUSINESS_ACCESS_TOKEN ?? '';
|
|
@ -0,0 +1,62 @@
|
||||||
|
export function getTextMessageInput(recipient, text) {
|
||||||
|
return JSON.stringify({
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
preview_url: false,
|
||||||
|
recipient_type: 'individual',
|
||||||
|
to: recipient,
|
||||||
|
type: 'text',
|
||||||
|
text: {
|
||||||
|
body: text,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTemplatedMessageInput(recipient, movie, seats) {
|
||||||
|
return JSON.stringify({
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: recipient,
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'sample_movie_ticket_confirmation',
|
||||||
|
language: {
|
||||||
|
code: 'en_US',
|
||||||
|
},
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: 'header',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'image',
|
||||||
|
image: {
|
||||||
|
link: movie.thumbnail,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'body',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: movie.title,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'date_time',
|
||||||
|
date_time: {
|
||||||
|
fallback_value: movie.time,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: movie.venue,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: seats,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,169 @@
|
||||||
|
import {
|
||||||
|
phoneNumberOnly,
|
||||||
|
toTime,
|
||||||
|
} from 'src/modules/queue/domain/helpers/time.helper';
|
||||||
|
import { WhatsappQueue } from './entity/whatsapp-queue.entity';
|
||||||
|
import {
|
||||||
|
WHATSAPP_BUSINESS_ACCESS_TOKEN,
|
||||||
|
WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID,
|
||||||
|
WHATSAPP_BUSINESS_API_URL,
|
||||||
|
WHATSAPP_BUSINESS_QUEUE_URL,
|
||||||
|
WHATSAPP_BUSINESS_VERSION,
|
||||||
|
} from './whatsapp.constant';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { apm } from 'src/core/apm';
|
||||||
|
|
||||||
|
export class WhatsappService {
|
||||||
|
async sendMessage(data) {
|
||||||
|
const config = {
|
||||||
|
method: 'post',
|
||||||
|
url: `${WHATSAPP_BUSINESS_API_URL}/${WHATSAPP_BUSINESS_VERSION}/${WHATSAPP_BUSINESS_ACCOUNT_NUMBER_ID}/messages`,
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${WHATSAPP_BUSINESS_ACCESS_TOKEN}`,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios(config);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error(error);
|
||||||
|
apm?.captureError(error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueRegister(data: WhatsappQueue) {
|
||||||
|
const queueUrl = `${WHATSAPP_BUSINESS_QUEUE_URL}?id=${data.id}`;
|
||||||
|
const payload = {
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: phoneNumberOnly(data.phone), // recipient's phone number
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'queue_created',
|
||||||
|
language: {
|
||||||
|
code: 'id', // language code
|
||||||
|
},
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: 'header',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_code',
|
||||||
|
type: 'text',
|
||||||
|
text: data.code, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'body',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
parameter_name: 'name',
|
||||||
|
type: 'text',
|
||||||
|
text: data.name, // replace with name variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter_name: 'item_name',
|
||||||
|
type: 'text',
|
||||||
|
text: data.item_name, // replace with item_name variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_code',
|
||||||
|
type: 'text',
|
||||||
|
text: data.code, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_time',
|
||||||
|
type: 'text',
|
||||||
|
text: toTime(data.time), // replace with queue_time variable
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
sub_type: 'url',
|
||||||
|
index: '0',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: queueUrl, // replace with dynamic URL
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
|
Logger.log(
|
||||||
|
`Notification register for ${data.code} send to ${data.phone}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async queueProcess(data: WhatsappQueue) {
|
||||||
|
const queueUrl = `${WHATSAPP_BUSINESS_QUEUE_URL}?id=${data.id}`;
|
||||||
|
const payload = {
|
||||||
|
messaging_product: 'whatsapp',
|
||||||
|
to: data.phone, // recipient's phone number
|
||||||
|
type: 'template',
|
||||||
|
template: {
|
||||||
|
name: 'queue_process',
|
||||||
|
language: {
|
||||||
|
code: 'id', // language code
|
||||||
|
},
|
||||||
|
components: [
|
||||||
|
{
|
||||||
|
type: 'header',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_code',
|
||||||
|
type: 'text',
|
||||||
|
text: data.item_name, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'body',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
parameter_name: 'name',
|
||||||
|
type: 'text',
|
||||||
|
text: data.name, // replace with name variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_code',
|
||||||
|
type: 'text',
|
||||||
|
text: data.code, // replace with queue_code variable
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter_name: 'queue_time',
|
||||||
|
type: 'text',
|
||||||
|
text: toTime(data.time), // replace with queue_time variable
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'button',
|
||||||
|
sub_type: 'url',
|
||||||
|
index: '0',
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: queueUrl, // replace with dynamic URL
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await this.sendMessage(payload);
|
||||||
|
if (response)
|
||||||
|
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue