Compare commits
No commits in common. "development" and "20.2.3-alpha.2" have entirely different histories.
developmen
...
20.2.3-alp
38
.drone.yml
38
.drone.yml
|
@ -2,37 +2,29 @@ kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: server
|
name: server
|
||||||
steps:
|
steps:
|
||||||
# - name: build
|
- name: build
|
||||||
# image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
# settings:
|
|
||||||
# host:
|
|
||||||
# - 172.10.10.10
|
|
||||||
# username: eigen
|
|
||||||
# key:
|
|
||||||
# from_secret: DEVOPS_SSH_PRIVATE_OPEN
|
|
||||||
# port: 22
|
|
||||||
# script:
|
|
||||||
# - cd /home/eigen/PROJECT/POS/POS.DEV/BE
|
|
||||||
# - sh build.sh
|
|
||||||
# when:
|
|
||||||
# ref:
|
|
||||||
# - refs/tags/devel_*
|
|
||||||
# - refs/tags/*-alpha.*
|
|
||||||
- name: build-testing
|
|
||||||
image: plugins/docker
|
|
||||||
settings:
|
settings:
|
||||||
registry: registry.eigen.co.id
|
host:
|
||||||
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
- 172.10.10.10
|
||||||
tags: ${DRONE_TAG}
|
username: eigen
|
||||||
custom_dns: 172.10.10.16
|
key:
|
||||||
|
from_secret: DEVOPS_SSH_PRIVATE_OPEN
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- cd /home/eigen/PROJECT/POS/POS.DEV/BE
|
||||||
|
- sh build.sh
|
||||||
when:
|
when:
|
||||||
ref:
|
ref:
|
||||||
|
- refs/tags/devel_*
|
||||||
- refs/tags/*-alpha.*
|
- refs/tags/*-alpha.*
|
||||||
- name: build-production
|
- name: build-production
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
registry: registry.eigen.co.id
|
registry: registry.eigen.co.id
|
||||||
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
repo: registry.eigen.co.id/eigen/${DRONE_REPO_NAME}
|
||||||
|
build_args:
|
||||||
|
- env_target=env.production
|
||||||
tags: ${DRONE_TAG}
|
tags: ${DRONE_TAG}
|
||||||
custom_dns: 172.10.10.16
|
custom_dns: 172.10.10.16
|
||||||
when:
|
when:
|
||||||
|
@ -106,4 +98,4 @@ trigger:
|
||||||
include:
|
include:
|
||||||
- refs/tags/*-alpha.*
|
- refs/tags/*-alpha.*
|
||||||
depends_on:
|
depends_on:
|
||||||
- server
|
- build
|
|
@ -5,11 +5,11 @@ COPY . .
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
FROM node:18.17-alpine
|
FROM node:18.17-alpine
|
||||||
# ARG env_target
|
ARG env_target
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# RUN echo ${env_target}
|
RUN echo ${env_target}
|
||||||
# COPY env/$env_target /app/.env
|
COPY env/$env_target /app/.env
|
||||||
# COPY --from=builder /app/env/$env_target .env
|
COPY --from=builder /app/env/$env_target .env
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/assets ./assets
|
COPY --from=builder /app/assets ./assets
|
||||||
|
|
|
@ -44,6 +44,3 @@ 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,6 +41,3 @@ 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,7 +49,6 @@
|
||||||
"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",
|
||||||
|
|
|
@ -92,7 +92,6 @@ import {
|
||||||
} from './modules/queue/data/models/queue.model';
|
} from './modules/queue/data/models/queue.model';
|
||||||
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
|
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
|
||||||
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -152,7 +151,6 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
||||||
QueueTicketModel,
|
QueueTicketModel,
|
||||||
QueueItemModel,
|
QueueItemModel,
|
||||||
QueueModel,
|
QueueModel,
|
||||||
QueueBucketModel,
|
|
||||||
],
|
],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -32,7 +32,7 @@ export abstract class BaseManager {
|
||||||
|
|
||||||
setUser() {
|
setUser() {
|
||||||
try {
|
try {
|
||||||
this.user = this.userProvider?.user ?? BLANK_USER;
|
this.user = this.userProvider?.user;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.user = BLANK_USER;
|
this.user = BLANK_USER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ export abstract class BaseCreateManager<Entity> extends BaseManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
async publishEvents() {
|
async publishEvents() {
|
||||||
this.eventBus?.publish(
|
this.eventBus.publish(
|
||||||
new RecordLog({
|
new RecordLog({
|
||||||
id: this.result['id'],
|
id: this.result['id'],
|
||||||
old: null,
|
old: null,
|
||||||
|
|
|
@ -23,7 +23,6 @@ export class BaseFilterDto implements BaseFilterEntity {
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
limit = 10;
|
limit = 10;
|
||||||
|
|
||||||
@ApiProperty({ type: String, required: false })
|
|
||||||
q: string;
|
q: string;
|
||||||
|
|
||||||
@ApiProperty({ type: ['string'], required: false })
|
@ApiProperty({ type: ['string'], required: false })
|
||||||
|
|
|
@ -6,6 +6,5 @@ export interface UsersSession {
|
||||||
name: string;
|
name: string;
|
||||||
role: UserRole;
|
role: UserRole;
|
||||||
source?: AppSource;
|
source?: AppSource;
|
||||||
item_id?: string;
|
|
||||||
user_privilege_id: string;
|
user_privilege_id: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,5 +41,4 @@ export enum TABLE_NAME {
|
||||||
QUEUE_ORDER = 'queue_orders',
|
QUEUE_ORDER = 'queue_orders',
|
||||||
QUEUE_TICKET = 'queue_tickets',
|
QUEUE_TICKET = 'queue_tickets',
|
||||||
QUEUE_ITEM = 'queue_items',
|
QUEUE_ITEM = 'queue_items',
|
||||||
QUEUE_BUCKET = 'queue_bucket',
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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" numeric`,
|
`ALTER TABLE "items" ADD "play_estimation" integer`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class QueueTable1729151429165 implements MigrationInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "queue_tickets" ADD CONSTRAINT "FK_0e9823b8b7ca9523b3be73878e5" FOREIGN KEY ("order_id") REFERENCES "queue_orders"("id") ON DELETE SET NULL ON UPDATE CASCADE`,
|
`ALTER TABLE "queue_tickets" ADD CONSTRAINT "FK_0e9823b8b7ca9523b3be73878e5" FOREIGN KEY ("order_id") REFERENCES "queue_orders"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
);
|
);
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`ALTER TABLE "queue_items" ADD CONSTRAINT "FK_25352739034765f6917757df74b" FOREIGN KEY ("ticket_id") REFERENCES "queue_tickets"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
`ALTER TABLE "queue_items" ADD CONSTRAINT "FK_25352739034765f6917757df74b" FOREIGN KEY ("ticket_id") REFERENCES "queue_tickets"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddQueueBucket1730859187883 implements MigrationInterface {
|
|
||||||
name = 'AddQueueBucket1730859187883';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TABLE "queue_bucket" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "queue_item_id" character varying NOT NULL, "date" bigint NOT NULL, "regular" integer NOT NULL, "vip" integer NOT NULL, CONSTRAINT "PK_cdd58b0d9e93e4be922da9d8bd6" PRIMARY KEY ("id"))`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`DROP TABLE "queue_bucket"`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddTransactionAndItemRelation1731383726542
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'AddTransactionAndItemRelation1731383726542';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" ADD "item_id" uuid`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" ADD "customer_category_id" uuid`,
|
|
||||||
);
|
|
||||||
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" ADD CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" ADD CONSTRAINT "FK_08dc8138714894a66e94820766d" FOREIGN KEY ("customer_category_id") REFERENCES "vip_categories"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" DROP CONSTRAINT "FK_08dc8138714894a66e94820766d"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" DROP CONSTRAINT "FK_edb934ab033f847e3f7ed4fc0fc"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" DROP COLUMN "customer_category_id"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" ADD "customer_category_id" character varying`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" DROP COLUMN "item_id"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transaction_items" ADD "item_id" character varying`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddItemQueueToQueue1731498661938 implements MigrationInterface {
|
|
||||||
name = 'AddItemQueueToQueue1731498661938';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "queues" ADD "item_queue_id" character varying`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`ALTER TABLE "queues" DROP COLUMN "item_queue_id"`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddInformationToItemQueue1731570311609
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'AddInformationToItemQueue1731570311609';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" ADD "information" character varying`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" DROP COLUMN "information"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class ItemQueueAddTimeAndPeakLevel1733199330134
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'ItemQueueAddTimeAndPeakLevel1733199330134';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" ADD "max_peak_level" integer NOT NULL DEFAULT '100'`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" ADD "call_preparation" integer NOT NULL DEFAULT '5'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" DROP COLUMN "call_preparation"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" DROP COLUMN "max_peak_level"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
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"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
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,14 +73,13 @@ 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,7 +19,6 @@ 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);
|
||||||
|
@ -96,41 +95,4 @@ 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,9 @@ export class ChangeStatusBookingHandler
|
||||||
},
|
},
|
||||||
relations: ['items', 'items.bundling_items'],
|
relations: ['items', 'items.bundling_items'],
|
||||||
});
|
});
|
||||||
|
console.log('change status', { dataID, couchData, booking });
|
||||||
mappingTransaction(booking);
|
mappingTransaction(booking);
|
||||||
|
console.log('after mapping');
|
||||||
|
|
||||||
if (!couchData) {
|
if (!couchData) {
|
||||||
console.log('save data to couch');
|
console.log('save data to couch');
|
||||||
|
|
|
@ -5,17 +5,13 @@ 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(
|
constructor(private configService: ConfigService) {}
|
||||||
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');
|
||||||
|
@ -68,11 +64,4 @@ 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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,3 @@ export interface GateScanEntity {
|
||||||
type: string;
|
type: string;
|
||||||
uuid: string;
|
uuid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GateLogEntity {
|
|
||||||
gate_id: string;
|
|
||||||
code: string;
|
|
||||||
error: any;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
import { IsNotEmpty, IsString } from 'class-validator';
|
|
||||||
import { GateLogEntity } from '../../domain/entity/gate-request.entity';
|
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
export class GateLogDto implements GateLogEntity {
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsString()
|
|
||||||
gate_id: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsString()
|
|
||||||
code: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
error: any;
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
GateResponseEntity,
|
GateResponseEntity,
|
||||||
} from '../domain/entity/gate-response.entity';
|
} from '../domain/entity/gate-response.entity';
|
||||||
import { Gate } from 'src/core/response';
|
import { Gate } from 'src/core/response';
|
||||||
import { GateLogDto } from './dto/logs.dto';
|
|
||||||
|
|
||||||
const masterGates = [
|
const masterGates = [
|
||||||
'319b6d3e-b661-4d19-8695-0dd6fb76465e',
|
'319b6d3e-b661-4d19-8695-0dd6fb76465e',
|
||||||
|
@ -73,13 +72,6 @@ export class GateController {
|
||||||
return responseValue;
|
return responseValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('logs')
|
|
||||||
async logs(@Body() data: GateLogDto): Promise<GateResponseEntity> {
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
return { code: 1, message: 'success' };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/master')
|
@Get(':id/master')
|
||||||
async detail(@Param('id') id: string): Promise<GateMasterEntity> {
|
async detail(@Param('id') id: string): Promise<GateMasterEntity> {
|
||||||
if (id == '1') return { codes: masterGates };
|
if (id == '1') return { codes: masterGates };
|
||||||
|
|
|
@ -10,18 +10,9 @@ export class ItemQueueModel
|
||||||
extends BaseStatusModel<ItemQueueEntity>
|
extends BaseStatusModel<ItemQueueEntity>
|
||||||
implements ItemQueueEntity
|
implements ItemQueueEntity
|
||||||
{
|
{
|
||||||
@Column('int', { default: 100 })
|
|
||||||
max_peak_level: number;
|
|
||||||
|
|
||||||
@Column('int', { default: 5 })
|
|
||||||
call_preparation: number;
|
|
||||||
|
|
||||||
@Column('varchar', { name: 'name' })
|
@Column('varchar', { name: 'name' })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column('varchar', { name: 'information', nullable: true })
|
|
||||||
information: string;
|
|
||||||
|
|
||||||
@Column('enum', {
|
@Column('enum', {
|
||||||
name: 'item_type',
|
name: 'item_type',
|
||||||
enum: ItemType,
|
enum: ItemType,
|
||||||
|
@ -33,10 +24,4 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,5 @@ import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.e
|
||||||
export interface ItemQueueEntity extends BaseStatusEntity {
|
export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
name: string;
|
name: string;
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
information?: string;
|
|
||||||
max_peak_level: number;
|
|
||||||
call_preparation: number;
|
|
||||||
items: ItemEntity[];
|
items: ItemEntity[];
|
||||||
use_notification?: boolean;
|
|
||||||
requiring_notification?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,16 +30,11 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.id`,
|
`${this.tableName}.id`,
|
||||||
`${this.tableName}.status`,
|
`${this.tableName}.status`,
|
||||||
`${this.tableName}.name`,
|
`${this.tableName}.name`,
|
||||||
`${this.tableName}.information`,
|
|
||||||
`${this.tableName}.item_type`,
|
`${this.tableName}.item_type`,
|
||||||
`${this.tableName}.created_at`,
|
`${this.tableName}.created_at`,
|
||||||
`${this.tableName}.creator_name`,
|
`${this.tableName}.creator_name`,
|
||||||
`${this.tableName}.updated_at`,
|
`${this.tableName}.updated_at`,
|
||||||
`${this.tableName}.editor_name`,
|
`${this.tableName}.editor_name`,
|
||||||
`${this.tableName}.max_peak_level`,
|
|
||||||
`${this.tableName}.call_preparation`,
|
|
||||||
`${this.tableName}.use_notification`,
|
|
||||||
`${this.tableName}.requiring_notification`,
|
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
@ -52,7 +47,6 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
`items.base_price`,
|
`items.base_price`,
|
||||||
`items.share_profit`,
|
`items.share_profit`,
|
||||||
`items.play_estimation`,
|
`items.play_estimation`,
|
||||||
`items.video_url`,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +55,4 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
id: this.dataId,
|
id: this.dataId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getResult(): ItemQueueEntity {
|
|
||||||
const videos = this.result.items.map((item) => {
|
|
||||||
return item.video_url ?? [];
|
|
||||||
});
|
|
||||||
this.result['videos'] = videos.flat();
|
|
||||||
return this.result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,6 @@ export class IndexItemQueueManager extends BaseIndexManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.creator_name`,
|
`${this.tableName}.creator_name`,
|
||||||
`${this.tableName}.updated_at`,
|
`${this.tableName}.updated_at`,
|
||||||
`${this.tableName}.editor_name`,
|
`${this.tableName}.editor_name`,
|
||||||
`${this.tableName}.max_peak_level`,
|
|
||||||
`${this.tableName}.call_preparation`,
|
|
||||||
`${this.tableName}.use_notification`,
|
|
||||||
`${this.tableName}.requiring_notification`,
|
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
|
|
@ -1,30 +1,12 @@
|
||||||
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
|
||||||
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
||||||
import { IsArray, IsNumber, IsString } from 'class-validator';
|
import { IsArray, IsString } from 'class-validator';
|
||||||
import { ItemType } from '../../constants';
|
import { ItemType } from '../../constants';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
import { Exclude, Transform } from 'class-transformer';
|
import { Exclude, Transform } from 'class-transformer';
|
||||||
|
|
||||||
export class ItemQueueDto extends BaseStatusDto implements ItemQueueEntity {
|
export class ItemQueueDto extends BaseStatusDto implements ItemQueueEntity {
|
||||||
@ApiProperty({
|
|
||||||
name: 'max_peak_level',
|
|
||||||
required: false,
|
|
||||||
example: 'Menentukan level peak maksimal penuhnya wahana',
|
|
||||||
default: 100,
|
|
||||||
})
|
|
||||||
@IsNumber()
|
|
||||||
max_peak_level: number;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
name: 'call_preparation',
|
|
||||||
required: false,
|
|
||||||
example: 'Waktu persiapan untuk memanggil antrian dalam menit',
|
|
||||||
default: 5,
|
|
||||||
})
|
|
||||||
@IsNumber()
|
|
||||||
call_preparation: number;
|
|
||||||
|
|
||||||
@Exclude()
|
@Exclude()
|
||||||
items: ItemEntity[];
|
items: ItemEntity[];
|
||||||
|
|
||||||
|
@ -32,14 +14,6 @@ export class ItemQueueDto extends BaseStatusDto implements ItemQueueEntity {
|
||||||
@IsString()
|
@IsString()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
name: 'information',
|
|
||||||
required: false,
|
|
||||||
example: 'Running text untuk display antrian',
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
information: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
|
|
|
@ -1,10 +1,4 @@
|
||||||
import {
|
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||||
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';
|
||||||
|
@ -13,7 +7,6 @@ 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}`)
|
||||||
|
@ -47,11 +40,4 @@ export class ItemQueueReadController {
|
||||||
async detail(@Param('id') id: string): Promise<ItemQueueEntity> {
|
async detail(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
return await this.orchestrator.detail(id);
|
return await this.orchestrator.detail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('display/:id')
|
|
||||||
@Public(true)
|
|
||||||
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
|
||||||
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
|
||||||
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('decimal', { name: 'play_estimation', nullable: true })
|
@Column('int', { 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 })
|
||||||
|
@ -93,9 +93,6 @@ export class ItemModel
|
||||||
@JoinColumn({ name: 'item_queue_id' })
|
@JoinColumn({ name: 'item_queue_id' })
|
||||||
item_queue: ItemQueueModel;
|
item_queue: ItemQueueModel;
|
||||||
|
|
||||||
@Column('varchar', { name: 'item_queue_id', nullable: true })
|
|
||||||
item_queue_id: string;
|
|
||||||
|
|
||||||
// relation ke tenant
|
// relation ke tenant
|
||||||
// ? karena item bisajadi merupakan item dari tenant
|
// ? karena item bisajadi merupakan item dari tenant
|
||||||
@Column('varchar', { name: 'tenant_id', nullable: true })
|
@Column('varchar', { name: 'tenant_id', nullable: true })
|
||||||
|
|
|
@ -84,12 +84,6 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
setQueryFilter(
|
setQueryFilter(
|
||||||
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
||||||
): SelectQueryBuilder<ItemEntity> {
|
): SelectQueryBuilder<ItemEntity> {
|
||||||
if (this.filterParam.q) {
|
|
||||||
queryBuilder.andWhere(
|
|
||||||
`${this.tableName}.name ILIKE '%${this.filterParam.q}%'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filterParam.tenant_ids?.length) {
|
if (this.filterParam.tenant_ids?.length) {
|
||||||
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
|
queryBuilder.andWhere(`${this.tableName}.tenant_id In (:...tenantIds)`, {
|
||||||
tenantIds: this.filterParam.tenant_ids,
|
tenantIds: this.filterParam.tenant_ids,
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
|
||||||
import { QueueBucket } from '../../domain/entities/queue-bucket.entity';
|
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
|
||||||
|
|
||||||
@Entity(TABLE_NAME.QUEUE_BUCKET)
|
|
||||||
export class QueueBucketModel implements QueueBucket {
|
|
||||||
@PrimaryGeneratedColumn('uuid')
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
@Column('varchar')
|
|
||||||
queue_item_id: string;
|
|
||||||
|
|
||||||
@Column({ type: 'bigint', nullable: false })
|
|
||||||
date: number;
|
|
||||||
|
|
||||||
@Column('int')
|
|
||||||
regular: number;
|
|
||||||
|
|
||||||
@Column('int')
|
|
||||||
vip: number;
|
|
||||||
}
|
|
|
@ -115,9 +115,6 @@ 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;
|
||||||
|
|
||||||
|
@ -134,12 +131,6 @@ export class QueueModel extends BaseModel<Queue> implements Queue {
|
||||||
@Column('varchar')
|
@Column('varchar')
|
||||||
item_id: string;
|
item_id: string;
|
||||||
|
|
||||||
@Column('varchar', { nullable: true })
|
|
||||||
item_queue_id: string;
|
|
||||||
|
|
||||||
@Column('int')
|
@Column('int')
|
||||||
qty: number;
|
qty: number;
|
||||||
|
|
||||||
average = 0;
|
|
||||||
peak_level = 100;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
|
||||||
import { Between, Repository } from 'typeorm';
|
|
||||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
|
||||||
import { QueueBucketModel } from '../models/queue-bucket.model';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
import { QueueItemModel } from '../models/queue.model';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class QueueBucketReadService extends BaseReadService<QueueBucketModel> {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(QueueBucketModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private repo: Repository<QueueBucketModel>,
|
|
||||||
|
|
||||||
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private item: Repository<QueueItemModel>,
|
|
||||||
) {
|
|
||||||
super(repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
async getQueue(item_id: string, vip = false): Promise<number> {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
|
|
||||||
const queue = await this.repo.findOne({
|
|
||||||
where: {
|
|
||||||
queue_item_id: item_id,
|
|
||||||
date: Between(start, end),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!queue) {
|
|
||||||
const regularNumber = vip ? 0 : 1;
|
|
||||||
const vipNumber = vip ? 1 : 0;
|
|
||||||
await this.repo.save({
|
|
||||||
queue_item_id: item_id,
|
|
||||||
date: start,
|
|
||||||
regular: regularNumber,
|
|
||||||
vip: vipNumber,
|
|
||||||
});
|
|
||||||
return Promise.resolve(1);
|
|
||||||
} else {
|
|
||||||
const field = vip ? 'vip' : 'regular';
|
|
||||||
const data = await this.repo
|
|
||||||
.createQueryBuilder('bucket')
|
|
||||||
.update(QueueBucketModel)
|
|
||||||
.set({
|
|
||||||
[field]: () => `${field} + 1`,
|
|
||||||
})
|
|
||||||
.where('id = :key', {
|
|
||||||
key: queue.id,
|
|
||||||
})
|
|
||||||
.returning(field)
|
|
||||||
.updateEntity(true)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
return data.raw[0]?.[field] ?? 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,150 +1,20 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { Between, DataSource, In, Not, Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import {
|
import { QueueItemModel, QueueModel } from '../models/queue.model';
|
||||||
QueueItemModel,
|
|
||||||
QueueModel,
|
|
||||||
QueueOrderModel,
|
|
||||||
} from '../models/queue.model';
|
|
||||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
import * as math from 'mathjs';
|
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueDataService extends BaseReadService<QueueModel> {
|
export class QueueDataService extends BaseReadService<QueueModel> {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(QueueModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(QueueModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<QueueModel>,
|
private repo: Repository<QueueModel>,
|
||||||
|
|
||||||
@InjectRepository(ItemQueueModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private itemQueueRepo: Repository<ItemQueueModel>,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitingQueue(item_queue_id: string) {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
return this.repo.find({
|
|
||||||
where: {
|
|
||||||
time: Between(start, end),
|
|
||||||
item_queue_id,
|
|
||||||
status: 'waiting',
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
time: 'ASC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async doneQueue(item_queue_id: string) {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
return this.repo.find({
|
|
||||||
where: {
|
|
||||||
time: Between(start, end),
|
|
||||||
item_queue_id,
|
|
||||||
status: In(['done', 'called']),
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
time: 'ASC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async exclude(item_queue_id: string[]) {
|
|
||||||
const queues = await this.itemQueueRepo.find({
|
|
||||||
relations: ['items'],
|
|
||||||
where: {
|
|
||||||
id: Not(In(item_queue_id)),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return queues.filter((q) => q.items.length > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
async allQueue() {
|
|
||||||
const queues = await this.itemQueueRepo.find({
|
|
||||||
relations: ['items'],
|
|
||||||
});
|
|
||||||
|
|
||||||
return queues.filter((q) => q.items.length > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
async lastQueue(item_queue_id: string) {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
return this.repo.findOne({
|
|
||||||
where: {
|
|
||||||
time: Between(start, end),
|
|
||||||
item_queue_id,
|
|
||||||
status: 'called',
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
call_time: 'DESC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* Change to QueueTimeFormula (queue-time.formula.ts)
|
|
||||||
* @param item_queue_id
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async queueTimes(item_queue_id: string): Promise<any> {
|
|
||||||
const queueTimes = {};
|
|
||||||
let now = moment().valueOf();
|
|
||||||
const itemQueue = await this.itemQueueRepo.findOne({
|
|
||||||
relations: ['items'],
|
|
||||||
where: {
|
|
||||||
id: item_queue_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
|
||||||
const average = math.mean(times) * 60 * 1000; // change average minute to milliseconds
|
|
||||||
const queues = await this.repo.find({
|
|
||||||
where: {
|
|
||||||
item_queue_id,
|
|
||||||
status: 'waiting',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
queueTimes[queues[0].id] = now; // first queue will be now
|
|
||||||
|
|
||||||
for (let i = 1; i < queues.length; i++) {
|
|
||||||
const queue = queues[i];
|
|
||||||
// duration will be total qty multiple by average
|
|
||||||
const duration = queue.qty * average;
|
|
||||||
|
|
||||||
// time to call will be now + duration
|
|
||||||
const time = now + duration;
|
|
||||||
queueTimes[queue.id] = time;
|
|
||||||
|
|
||||||
// update now to last call time
|
|
||||||
now = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
return queueTimes;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueItems(item_queue_id: string[]): Promise<QueueModel[]> {
|
|
||||||
return this.repo.find({
|
|
||||||
relations: ['item', 'item.item', 'item.item.item_queue'],
|
|
||||||
where: {
|
|
||||||
item: { item: { item_queue: { id: In(item_queue_id) } } },
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
time: 'DESC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ -155,102 +25,16 @@ export class QueueService extends BaseDataService<QueueModel> {
|
||||||
|
|
||||||
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(QueueItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
private item: Repository<QueueItemModel>,
|
private item: Repository<QueueItemModel>,
|
||||||
|
|
||||||
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private itemMaster: Repository<ItemModel>,
|
|
||||||
|
|
||||||
@InjectDataSource(CONNECTION_NAME.DEFAULT)
|
|
||||||
private dataSource: DataSource,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueTicket(queueId: string) {
|
|
||||||
return this.repo.findOne({
|
|
||||||
relations: ['item', 'item.ticket'],
|
|
||||||
where: {
|
|
||||||
id: queueId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async queues(ids: string[]) {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
const playEstimations = {};
|
|
||||||
const queuePeakLevel = {};
|
|
||||||
|
|
||||||
for (const id of ids) {
|
|
||||||
const est = await this.itemAverageTimeEstimation(id);
|
|
||||||
playEstimations[id] = est.average;
|
|
||||||
queuePeakLevel[id] = est.peakLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
const queues = await this.repo.find({
|
|
||||||
where: {
|
|
||||||
item_queue_id: In(ids),
|
|
||||||
time: Between(start, end),
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
time: 'ASC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
queues.forEach((queue) => {
|
|
||||||
queue.average = playEstimations[queue.item_queue_id];
|
|
||||||
queue.peak_level = queuePeakLevel[queue.item_queue_id];
|
|
||||||
});
|
|
||||||
|
|
||||||
return queues;
|
|
||||||
}
|
|
||||||
|
|
||||||
async itemAverageTimeEstimation(item_queue_id: string) {
|
|
||||||
const items = await this.itemMaster.find({
|
|
||||||
relations: ['item_queue'],
|
|
||||||
where: {
|
|
||||||
item_queue_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const times = items.map((item) => item.play_estimation ?? 0);
|
|
||||||
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
|
||||||
const peakLevel = items[0]?.item_queue?.max_peak_level ?? 100;
|
|
||||||
return { average, peakLevel };
|
|
||||||
}
|
|
||||||
|
|
||||||
async getTicketItems(ticket_id: string, item_id: string) {
|
async getTicketItems(ticket_id: string, item_id: string) {
|
||||||
return this.item.findOneOrFail({
|
return this.item.findOneOrFail({
|
||||||
relations: ['item'],
|
where: {
|
||||||
where: [
|
|
||||||
{
|
|
||||||
ticket_id,
|
ticket_id,
|
||||||
item_id,
|
item_id,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ticket_id,
|
|
||||||
item: { item_queue_id: item_id },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
|
||||||
const query = `UPDATE queue_items SET qty = qty - ${qty} WHERE id = '${item_id}'`;
|
|
||||||
this.dataSource.query(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class QueueOrderService extends BaseDataService<QueueOrderModel> {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(QueueOrderModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private repo: Repository<QueueOrderModel>,
|
|
||||||
) {
|
|
||||||
super(repo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { Between, In, IsNull, Like, Not, Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||||
import {
|
import {
|
||||||
QueueItemModel,
|
QueueItemModel,
|
||||||
|
@ -10,8 +10,6 @@ import {
|
||||||
QueueTicketModel,
|
QueueTicketModel,
|
||||||
} 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 { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TicketDataService extends BaseDataService<QueueTicket> {
|
export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
|
@ -24,9 +22,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -35,156 +30,16 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
return await this.order.save(order);
|
return await this.order.save(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateQueueTicket(ticket: QueueTicket): Promise<QueueTicketModel> {
|
|
||||||
return await this.repo.save(ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
async loginQueue(id: string): Promise<QueueOrder> {
|
async loginQueue(id: string): Promise<QueueOrder> {
|
||||||
const order = await this.order.findOne({
|
|
||||||
relations: ['tickets'],
|
|
||||||
where: [
|
|
||||||
{ transaction_id: id },
|
|
||||||
{ 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[]> {
|
|
||||||
return this.repo.find({
|
|
||||||
where: {
|
|
||||||
code: Like(`${code}%`),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async ticketByUser(user: string, phone: string): Promise<QueueTicket> {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
|
|
||||||
return this.repo.findOne({
|
|
||||||
relations: ['items'],
|
|
||||||
where: {
|
|
||||||
customer: user,
|
|
||||||
phone: phone,
|
|
||||||
date: Between(start, end),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async loginPhone(user: string, phone: string): Promise<QueueOrder> {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
|
|
||||||
return this.order.findOneOrFail({
|
return this.order.findOneOrFail({
|
||||||
relations: ['tickets'],
|
relations: ['tickets'],
|
||||||
where: {
|
where: {
|
||||||
customer: user,
|
transaction_id: id,
|
||||||
phone: `+${phone}`,
|
|
||||||
date: Between(start, end),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async orders(order_id: string): Promise<QueueOrderModel[]> {
|
async queueTickets(order_id: string): Promise<QueueTicketModel[]> {
|
||||||
const order = await this.order.findOneOrFail({
|
|
||||||
where: {
|
|
||||||
id: order_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (order.transaction_id != null) {
|
|
||||||
return this.order.find({
|
|
||||||
where: {
|
|
||||||
code: order.code,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return [order];
|
|
||||||
}
|
|
||||||
|
|
||||||
async transactions(transaction_id: string): Promise<QueueOrderModel[]> {
|
|
||||||
const order = await this.order.findOneOrFail({
|
|
||||||
where: {
|
|
||||||
transaction_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (order.transaction_id != null) {
|
|
||||||
return this.order.find({
|
|
||||||
where: {
|
|
||||||
code: order.code,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return [order];
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteQueue(transaction_id: string): Promise<void> {
|
|
||||||
try {
|
|
||||||
const transactions = await this.transactions(transaction_id);
|
|
||||||
await this.order.remove(transactions);
|
|
||||||
} catch (error) {
|
|
||||||
console.log('transaction not found');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async orderIds(order_id: string): Promise<string[]> {
|
|
||||||
const orders = await this.orders(order_id);
|
|
||||||
|
|
||||||
return orders.map((order) => order.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
async orderItems(
|
|
||||||
order_id: string,
|
|
||||||
item_ids: string[],
|
|
||||||
): Promise<QueueOrderModel> {
|
|
||||||
const order = await this.orderIds(order_id);
|
|
||||||
try {
|
|
||||||
const ticket = await this.order.findOneOrFail({
|
|
||||||
relations: ['tickets', 'tickets.items'],
|
|
||||||
where: {
|
|
||||||
tickets: {
|
|
||||||
order_id: In(order),
|
|
||||||
items: {
|
|
||||||
id: In(item_ids),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return ticket;
|
|
||||||
} catch (error) {
|
|
||||||
throw new UnprocessableEntityException('Ticket tidak dapat ditemukan');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async queuePosTickets(order_id: string): Promise<QueueTicketModel[]> {
|
|
||||||
return this.repo.find({
|
return this.repo.find({
|
||||||
relations: [
|
relations: [
|
||||||
'items',
|
'items',
|
||||||
|
@ -198,46 +53,10 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueTickets(order_id: string): Promise<QueueTicketModel[]> {
|
|
||||||
const order = await this.orderIds(order_id);
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
return this.repo.find({
|
|
||||||
relations: [
|
|
||||||
'items',
|
|
||||||
'items.queue',
|
|
||||||
'items.item',
|
|
||||||
'items.item.item_queue',
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
order_id: In(order),
|
|
||||||
date: Between(start, end),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueUniqueTickets(order_id: string): Promise<QueueTicketModel[]> {
|
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
return this.repo.find({
|
|
||||||
relations: [
|
|
||||||
'items',
|
|
||||||
'items.queue',
|
|
||||||
'items.item',
|
|
||||||
'items.item.item_queue',
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
order_id: order_id,
|
|
||||||
date: Between(start, end),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueTicketItems(
|
async queueTicketItems(
|
||||||
order_id: string,
|
order_id: string,
|
||||||
ticket_id: string,
|
ticket_id: string,
|
||||||
): Promise<QueueTicketModel[]> {
|
): Promise<QueueTicketModel[]> {
|
||||||
const order = await this.orderIds(order_id);
|
|
||||||
return this.repo.find({
|
return this.repo.find({
|
||||||
relations: [
|
relations: [
|
||||||
'items',
|
'items',
|
||||||
|
@ -246,36 +65,16 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
'items.item.item_queue',
|
'items.item.item_queue',
|
||||||
],
|
],
|
||||||
where: {
|
where: {
|
||||||
order_id: In(order),
|
order_id,
|
||||||
id: ticket_id,
|
id: ticket_id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueTicketActive(
|
|
||||||
order_id: string,
|
|
||||||
ticket_id: string,
|
|
||||||
): Promise<QueueTicketModel[]> {
|
|
||||||
// const order = await this.orderIds(order_id);
|
|
||||||
return this.repo.find({
|
|
||||||
relations: ['items', 'items.queue'],
|
|
||||||
where: {
|
|
||||||
// order_id: In(order),
|
|
||||||
id: ticket_id,
|
|
||||||
// items: {
|
|
||||||
// queue: {
|
|
||||||
// status: In(['waiting']),
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueItemTickets(
|
async queueItemTickets(
|
||||||
order_id: string,
|
order_id: string,
|
||||||
item_id: string,
|
item_id: string,
|
||||||
): Promise<QueueTicketModel[]> {
|
): Promise<QueueTicketModel[]> {
|
||||||
const order = await this.orderIds(order_id);
|
|
||||||
return this.repo.find({
|
return this.repo.find({
|
||||||
relations: [
|
relations: [
|
||||||
'items',
|
'items',
|
||||||
|
@ -284,19 +83,18 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
'items.item.item_queue',
|
'items.item.item_queue',
|
||||||
],
|
],
|
||||||
where: {
|
where: {
|
||||||
order_id: In(order),
|
order_id,
|
||||||
items: [{ item_id }, { item: { item_queue: { id: item_id } } }],
|
items: [{ item_id }, { item: { item_queue: { id: item_id } } }],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueItems(order_id: string): Promise<QueueItemModel[]> {
|
async queueItems(order_id: string): Promise<QueueItemModel[]> {
|
||||||
const order = await this.orderIds(order_id);
|
|
||||||
return this.item.find({
|
return this.item.find({
|
||||||
relations: ['queue', 'ticket'],
|
relations: ['queue', 'ticket'],
|
||||||
where: {
|
where: {
|
||||||
ticket: {
|
ticket: {
|
||||||
order_id: In(order),
|
order_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
export interface QueueBucket {
|
|
||||||
id: string;
|
|
||||||
queue_item_id: string;
|
|
||||||
date: number;
|
|
||||||
regular: number;
|
|
||||||
vip: number;
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
import { QueueTicket } from './ticket.entity';
|
import { QueueTicket } from './ticket.entity';
|
||||||
import { QueueModel } from '../../data/models/queue.model';
|
|
||||||
|
|
||||||
export interface QueueItem extends BaseCoreEntity {
|
export interface QueueItem extends BaseCoreEntity {
|
||||||
ticket?: QueueTicket;
|
ticket?: QueueTicket;
|
||||||
|
@ -9,13 +8,3 @@ export interface QueueItem extends BaseCoreEntity {
|
||||||
item_id: string;
|
item_id: string;
|
||||||
qty: number;
|
qty: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MergedItemQueue extends BaseCoreEntity {
|
|
||||||
id: string;
|
|
||||||
queue_item_id: string;
|
|
||||||
item_id: string;
|
|
||||||
title: string;
|
|
||||||
image_url: string;
|
|
||||||
qty: number;
|
|
||||||
queues: QueueModel[];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
export function toTime(timestamp: number): string {
|
|
||||||
const date = moment.unix(timestamp / 1000).add(7, 'hours');
|
|
||||||
|
|
||||||
const hours = date.hours();
|
|
||||||
const minutes = date.minutes();
|
|
||||||
return `${hours < 10 ? '0' : ''}${hours}:${
|
|
||||||
minutes < 10 ? '0' : ''
|
|
||||||
}${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;
|
|
||||||
}
|
|
|
@ -4,19 +4,8 @@ import { IndexQueueManager } from './usecases/index-queue.manager';
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { Queue } from './entities/queue.entity';
|
import { Queue } from './entities/queue.entity';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import {
|
import { CallQueueManager } from './usecases/call-queue.manager';
|
||||||
CallQueueManager,
|
import { QUEUE_STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
DoneQueueManager,
|
|
||||||
} from './usecases/call-queue.manager';
|
|
||||||
import {
|
|
||||||
ORDER_TYPE,
|
|
||||||
QUEUE_STATUS,
|
|
||||||
} 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 {
|
||||||
|
@ -25,12 +14,10 @@ export class QueueAdminOrchestrator {
|
||||||
private readonly service: QueueService,
|
private readonly service: QueueService,
|
||||||
private indexManager: IndexQueueManager,
|
private indexManager: IndexQueueManager,
|
||||||
private callManager: CallQueueManager,
|
private callManager: CallQueueManager,
|
||||||
private doneManager: DoneQueueManager,
|
|
||||||
private readonly queueTimeFormula: QueueTimeFormula,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async index(params): Promise<PaginationResponse<Queue>> {
|
async index(params): Promise<PaginationResponse<Queue>> {
|
||||||
this.indexManager.setFilterParam({ order_type: ORDER_TYPE.ASC, ...params });
|
this.indexManager.setFilterParam(params);
|
||||||
this.indexManager.setService(this.dataService, TABLE_NAME.QUEUE);
|
this.indexManager.setService(this.dataService, TABLE_NAME.QUEUE);
|
||||||
await this.indexManager.execute();
|
await this.indexManager.execute();
|
||||||
return this.indexManager.getResult();
|
return this.indexManager.getResult();
|
||||||
|
@ -42,60 +29,4 @@ export class QueueAdminOrchestrator {
|
||||||
await this.callManager.execute();
|
await this.callManager.execute();
|
||||||
return this.callManager.getResult();
|
return this.callManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async done(dataId): Promise<string> {
|
|
||||||
this.doneManager.setData(dataId, QUEUE_STATUS.DONE);
|
|
||||||
this.doneManager.setService(this.service, TABLE_NAME.QUEUE);
|
|
||||||
await this.doneManager.execute();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,7 @@ import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||||
import { TicketDataService } from '../data/services/ticket.service';
|
import { TicketDataService } from '../data/services/ticket.service';
|
||||||
import { QueueOrder } from './entities/order.entity';
|
import { QueueOrder } from './entities/order.entity';
|
||||||
import { Queue } from './entities/queue.entity';
|
import { Queue } from './entities/queue.entity';
|
||||||
import {
|
import { QueueService } from '../data/services/queue.service';
|
||||||
QueueDataService,
|
|
||||||
QueueOrderService,
|
|
||||||
QueueService,
|
|
||||||
} from '../data/services/queue.service';
|
|
||||||
import { RegisterQueueManager } from './usecases/register-queue.manager';
|
import { RegisterQueueManager } from './usecases/register-queue.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { RegisterQueueDto } from '../infrastructure/controllers/dto/register-queue.dto';
|
import { RegisterQueueDto } from '../infrastructure/controllers/dto/register-queue.dto';
|
||||||
|
@ -15,45 +11,18 @@ import { CustomerQueueDetailManager } from './usecases/queue/customer-queue-deta
|
||||||
import { CustomerQueueItemManager } from './usecases/queue/customer-queue-item.manager';
|
import { CustomerQueueItemManager } from './usecases/queue/customer-queue-item.manager';
|
||||||
import { CustomerQueueItemListManager } from './usecases/queue/customer-queue-item-list.manager';
|
import { CustomerQueueItemListManager } from './usecases/queue/customer-queue-item-list.manager';
|
||||||
import { CustomerQueueListManager } from './usecases/queue/customer-queue-list.manager';
|
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';
|
|
||||||
import { CustomerQueueTicketSummaryManager } from './usecases/queue/customer-queue-ticket.manager';
|
|
||||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
|
||||||
import { CustomerQueuePosItemManager } from './usecases/queue/customer-queue-pos-item.manager';
|
|
||||||
import {
|
|
||||||
QueueModel,
|
|
||||||
QueueOrderModel,
|
|
||||||
QueueTicketModel,
|
|
||||||
} from '../data/models/queue.model';
|
|
||||||
import { CustomerQueueRecommendManager } from './usecases/queue/customer-queue-recommend.manager';
|
|
||||||
import { GenerateQueueManager } from './usecases/generate-queue.manager';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueOrchestrator {
|
export class QueueOrchestrator {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly dataService: TicketDataService,
|
private readonly dataService: TicketDataService,
|
||||||
public readonly transactionService: TransactionDataService,
|
|
||||||
private readonly queueService: QueueService,
|
private readonly queueService: QueueService,
|
||||||
private readonly queueOrderService: QueueOrderService,
|
|
||||||
private readonly registerQueueManager: RegisterQueueManager,
|
private readonly registerQueueManager: RegisterQueueManager,
|
||||||
private readonly splitQueueManager: SplitQueueManager,
|
|
||||||
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);
|
return await this.dataService.loginQueue(id);
|
||||||
const code = order.tickets[0].code ?? order.code;
|
|
||||||
const tickets = await this.dataService.ticketByCode(code);
|
|
||||||
order.tickets = tickets;
|
|
||||||
return order;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new UnauthorizedException({
|
throw new UnauthorizedException({
|
||||||
message: 'Invoice tidak ditemukan',
|
message: 'Invoice tidak ditemukan',
|
||||||
|
@ -62,23 +31,6 @@ export class QueueOrchestrator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginPhone(login: LoginQueueDto): Promise<QueueOrder> {
|
|
||||||
const { name, phone } = login;
|
|
||||||
const now = moment().format('DD/MM/YYYY');
|
|
||||||
try {
|
|
||||||
const order = await this.dataService.loginPhone(name, phone);
|
|
||||||
const code = order.tickets[0].code ?? order.code;
|
|
||||||
const tickets = await this.dataService.ticketByCode(code);
|
|
||||||
order.tickets = tickets;
|
|
||||||
return order;
|
|
||||||
} 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> {
|
async create(data: RegisterQueueDto): Promise<Queue> {
|
||||||
const queue = await this.queueService.getTicketItems(
|
const queue = await this.queueService.getTicketItems(
|
||||||
data.ticket_id,
|
data.ticket_id,
|
||||||
|
@ -94,63 +46,6 @@ export class QueueOrchestrator {
|
||||||
return this.registerQueueManager.getResult();
|
return this.registerQueueManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
const existTicket = await this.dataService.ticketByUser(
|
|
||||||
data.name,
|
|
||||||
data.phone,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existTicket) {
|
|
||||||
const itemTickets = this.itemsFromOrder(queue);
|
|
||||||
|
|
||||||
const items = data.items.map((item) => {
|
|
||||||
const item_id = itemTickets[item.queue_item_id];
|
|
||||||
return {
|
|
||||||
item_queue_id: item_id,
|
|
||||||
item_id: item_id,
|
|
||||||
qty: item.qty,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
existTicket.items.push(...items);
|
|
||||||
await this.dataService.updateQueueTicket(existTicket);
|
|
||||||
|
|
||||||
data.items.forEach((item) => {
|
|
||||||
this.queueService.updateItemQty(item.queue_item_id, item.qty);
|
|
||||||
});
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.splitQueueManager.setRequestData(data);
|
|
||||||
this.splitQueueManager.setData(queue);
|
|
||||||
this.splitQueueManager.setService(
|
|
||||||
this.queueOrderService,
|
|
||||||
TABLE_NAME.QUEUE_ORDER,
|
|
||||||
);
|
|
||||||
await this.splitQueueManager.execute();
|
|
||||||
return this.splitQueueManager.getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
itemsFromOrder(order: QueueOrderModel) {
|
|
||||||
const itemTickets = {};
|
|
||||||
order.tickets.forEach((ticket) => {
|
|
||||||
ticket.items.forEach((item) => {
|
|
||||||
itemTickets[item.id] = item.item_id;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return itemTickets;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queuePOSTickets(order_id: string): Promise<any> {
|
|
||||||
const tickets = await this.dataService.queuePosTickets(order_id);
|
|
||||||
const manager = new CustomerQueuePosItemManager(tickets);
|
|
||||||
return manager.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueTickets(order_id: string): Promise<any> {
|
async queueTickets(order_id: string): Promise<any> {
|
||||||
const tickets = await this.dataService.queueTickets(order_id);
|
const tickets = await this.dataService.queueTickets(order_id);
|
||||||
const manager = new CustomerQueueSummaryManager(tickets);
|
const manager = new CustomerQueueSummaryManager(tickets);
|
||||||
|
@ -162,21 +57,7 @@ export class QueueOrchestrator {
|
||||||
order_id,
|
order_id,
|
||||||
ticket_id,
|
ticket_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
const queueItemIds = this.getQueueItemFromTickets(tickets);
|
|
||||||
const queues = await this.queueService.queues(queueItemIds);
|
|
||||||
const manager = new CustomerQueueDetailManager(tickets);
|
const manager = new CustomerQueueDetailManager(tickets);
|
||||||
manager.currentQueues(queues);
|
|
||||||
return manager.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueTicketSummary(order_id: string, ticket_id: string): Promise<any> {
|
|
||||||
const tickets = await this.dataService.queueTicketActive(
|
|
||||||
order_id,
|
|
||||||
ticket_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
const manager = new CustomerQueueTicketSummaryManager(tickets);
|
|
||||||
return manager.data;
|
return manager.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,41 +67,9 @@ export class QueueOrchestrator {
|
||||||
return manager.data;
|
return manager.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueItemRecommendation(order_id: string): Promise<any> {
|
|
||||||
const tickets = await this.dataService.queueTickets(order_id);
|
|
||||||
const queueItemIds = this.getQueueItemFromTickets(tickets);
|
|
||||||
const recommendItems = await this.queueDataService.exclude(queueItemIds);
|
|
||||||
const recommendIds = recommendItems.map((item) => item.id);
|
|
||||||
const queues = await this.queueService.queues(recommendIds);
|
|
||||||
const manager = new CustomerQueueRecommendManager(tickets);
|
|
||||||
manager.currentQueues(queues);
|
|
||||||
return manager.recommend(recommendItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueItemSummary(): Promise<any> {
|
|
||||||
const recommendItems = await this.queueDataService.allQueue();
|
|
||||||
const recommendIds = recommendItems.map((item) => item.id);
|
|
||||||
const queues = await this.queueService.queues(recommendIds);
|
|
||||||
const manager = new CustomerQueueRecommendManager(null);
|
|
||||||
manager.currentQueues(queues);
|
|
||||||
return manager.recommend(recommendItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueItems(order_id: string): Promise<any> {
|
async queueItems(order_id: string): Promise<any> {
|
||||||
const tickets = await this.dataService.queueTickets(order_id);
|
const tickets = await this.dataService.queueTickets(order_id);
|
||||||
const queueItemIds = this.getQueueItemFromTickets(tickets);
|
|
||||||
const queues = await this.queueService.queues(queueItemIds);
|
|
||||||
const manager = new CustomerQueueItemListManager(tickets);
|
const manager = new CustomerQueueItemListManager(tickets);
|
||||||
manager.currentQueues(queues);
|
|
||||||
return manager.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueUniqueItems(order_id: string): Promise<any> {
|
|
||||||
const tickets = await this.dataService.queueUniqueTickets(order_id);
|
|
||||||
const queueItemIds = this.getQueueItemFromTickets(tickets);
|
|
||||||
const queues = await this.queueService.queues(queueItemIds);
|
|
||||||
const manager = new CustomerQueueItemListManager(tickets);
|
|
||||||
manager.currentQueues(queues);
|
|
||||||
return manager.data;
|
return manager.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,14 +78,4 @@ export class QueueOrchestrator {
|
||||||
const manager = new CustomerQueueListManager(tickets);
|
const manager = new CustomerQueueListManager(tickets);
|
||||||
return manager.data;
|
return manager.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
getQueueItemFromTickets(tickets: QueueTicketModel[]) {
|
|
||||||
const queueItemIds = tickets.map((ticket) => {
|
|
||||||
return ticket.items.map((item) => {
|
|
||||||
return item.item.item_queue_id;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return queueItemIds.flat();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,3 @@ export class CallQueueManager extends BaseUpdateStatusManager<Queue> {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class DoneQueueManager extends CallQueueManager {
|
|
||||||
async beforeProcess(): Promise<void> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
import { QueueModel } from 'src/modules/queue/data/models/queue.model';
|
|
||||||
import { toTime } from '../../helpers/time.helper';
|
|
||||||
import * as math from 'mathjs';
|
|
||||||
import { QueueTimeFormula } from './queue-time.formula';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
export class QueueCondition {
|
|
||||||
private ticketItems = {};
|
|
||||||
constructor(readonly items: QueueModel[]) {
|
|
||||||
items.forEach((item) => {
|
|
||||||
const item_id = item.item_queue_id;
|
|
||||||
const currentItem = this.ticketItems[item_id];
|
|
||||||
this.ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
condition(item_id: string) {
|
|
||||||
const queues: QueueModel[] = this.ticketItems[item_id] ?? [];
|
|
||||||
const playEstimation = queues[0]?.average ?? 0;
|
|
||||||
const peakLevel = queues[0]?.peak_level ?? 100;
|
|
||||||
const [time, last] = this.queueTime(queues, playEstimation);
|
|
||||||
const nearest = time ? toTime(time) : 0;
|
|
||||||
const lastTime = last ? toTime(last + playEstimation) : 0;
|
|
||||||
|
|
||||||
const queuePeople = this.queuePeople(queues, peakLevel);
|
|
||||||
|
|
||||||
return {
|
|
||||||
available: queuePeople == 0,
|
|
||||||
average: this.averageTime(queues),
|
|
||||||
nearest: nearest,
|
|
||||||
crowded_level: queuePeople,
|
|
||||||
available_time: lastTime,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
queuePeople(queues: QueueModel[], peakLevel): number {
|
|
||||||
const queue = this.activeQueue(queues);
|
|
||||||
const level = peakLevel / 100;
|
|
||||||
const queuePeople = queue.reduce((acc, q) => {
|
|
||||||
return acc + q.qty;
|
|
||||||
}, 0);
|
|
||||||
return queuePeople * level;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeQueue(queues: QueueModel[]) {
|
|
||||||
return queues.filter((q) => q.status == 'waiting');
|
|
||||||
}
|
|
||||||
|
|
||||||
queueTime(queues: QueueModel[], average = 0): number[] {
|
|
||||||
const calledQueue = queues.filter((q) =>
|
|
||||||
['called', 'done'].includes(q.status),
|
|
||||||
);
|
|
||||||
const lastCalledQueue = calledQueue[calledQueue.length - 1];
|
|
||||||
const activeQueues = this.activeQueue(queues);
|
|
||||||
|
|
||||||
const queueTimes = QueueTimeFormula.queueTime(
|
|
||||||
activeQueues,
|
|
||||||
lastCalledQueue,
|
|
||||||
average,
|
|
||||||
);
|
|
||||||
|
|
||||||
const queueEstimation = Object.values<number>(queueTimes);
|
|
||||||
|
|
||||||
const first = queueEstimation[0] ?? moment().valueOf();
|
|
||||||
const last = queueEstimation[queueEstimation.length - 1] ?? 0;
|
|
||||||
return [first, last];
|
|
||||||
}
|
|
||||||
|
|
||||||
averageTime(queues: QueueModel[]) {
|
|
||||||
if (queues.length == 0) return 0;
|
|
||||||
const calledQueue = queues.filter((q) =>
|
|
||||||
['called', 'done'].includes(q.status),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (calledQueue.length < 1) return 0;
|
|
||||||
|
|
||||||
const times = calledQueue.map((queue) => {
|
|
||||||
return (queue.call_time - queue.time) / 1000;
|
|
||||||
});
|
|
||||||
|
|
||||||
const avg = Math.ceil(math.mean(times));
|
|
||||||
return Math.max(0, avg);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
|
||||||
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
|
||||||
import { QueueDataService } from 'src/modules/queue/data/services/queue.service';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
import * as math from 'mathjs';
|
|
||||||
import { QueueModel } from 'src/modules/queue/data/models/queue.model';
|
|
||||||
|
|
||||||
export class QueueTimeFormula {
|
|
||||||
constructor(
|
|
||||||
private readonly queueDataService: QueueDataService,
|
|
||||||
@InjectRepository(ItemQueueModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private itemQueueRepo: Repository<ItemQueueModel>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public average = 0;
|
|
||||||
|
|
||||||
async items(item_queue_id: string) {
|
|
||||||
const queues = await this.queueDataService.waitingQueue(item_queue_id);
|
|
||||||
if (queues.length == 0) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const itemQueue = await this.itemQueueRepo.findOne({
|
|
||||||
relations: ['items'],
|
|
||||||
where: {
|
|
||||||
id: item_queue_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
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
|
|
||||||
this.average = Math.floor(average);
|
|
||||||
|
|
||||||
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
|
||||||
|
|
||||||
return QueueTimeFormula.queueTime(queues, calledQueue, average);
|
|
||||||
}
|
|
||||||
|
|
||||||
static queueTime(
|
|
||||||
queues: QueueModel[],
|
|
||||||
lastQueue: QueueModel,
|
|
||||||
average: number,
|
|
||||||
) {
|
|
||||||
const queueTimes = {};
|
|
||||||
if (queues.length < 1) return queueTimes;
|
|
||||||
const timeNow = moment().valueOf();
|
|
||||||
const lastCall = lastQueue?.call_time ?? timeNow - average;
|
|
||||||
|
|
||||||
const callTime = +lastCall + average;
|
|
||||||
const currentQueueCallTime = timeNow > callTime ? timeNow : callTime;
|
|
||||||
|
|
||||||
queueTimes[queues[0].id] = currentQueueCallTime;
|
|
||||||
let now = currentQueueCallTime;
|
|
||||||
|
|
||||||
for (let i = 1; i < queues.length; i++) {
|
|
||||||
const before = queues[i - 1];
|
|
||||||
// duration will be total qty multiple by average from last queue
|
|
||||||
const duration = before.qty * average;
|
|
||||||
|
|
||||||
const queue = queues[i];
|
|
||||||
// time to call will be now + duration
|
|
||||||
const time = now + duration;
|
|
||||||
queueTimes[queue.id] = time;
|
|
||||||
|
|
||||||
// update now to last call time
|
|
||||||
now = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
return queueTimes;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,161 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,17 +6,9 @@ import {
|
||||||
RelationParam,
|
RelationParam,
|
||||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
import { Queue } from '../entities/queue.entity';
|
import { Queue } from '../entities/queue.entity';
|
||||||
import * as moment from 'moment';
|
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
|
||||||
import { QueueTimeFormula } from './formula/queue-time.formula';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexQueueManager extends BaseIndexManager<Queue> {
|
export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
constructor(private readonly queueTimeFormula: QueueTimeFormula) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
private queueTimes = {};
|
|
||||||
async prepareData(): Promise<void> {
|
async prepareData(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,9 +18,6 @@ export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
async afterProcess(): Promise<void> {
|
||||||
this.queueTimes = await this.queueTimeFormula.items(
|
|
||||||
this.filterParam.queue_id,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,20 +29,6 @@ export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getResult(): PaginationResponse<Queue> {
|
|
||||||
const result = this.result;
|
|
||||||
|
|
||||||
return {
|
|
||||||
total: result.total,
|
|
||||||
data: result.data.map((queue) => {
|
|
||||||
return {
|
|
||||||
...queue,
|
|
||||||
estimation: this.queueTimes[queue.id],
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get selects(): string[] {
|
get selects(): string[] {
|
||||||
return [
|
return [
|
||||||
`${this.tableName}.id`,
|
`${this.tableName}.id`,
|
||||||
|
@ -84,23 +59,6 @@ export class IndexQueueManager extends BaseIndexManager<Queue> {
|
||||||
setQueryFilter(
|
setQueryFilter(
|
||||||
queryBuilder: SelectQueryBuilder<Queue>,
|
queryBuilder: SelectQueryBuilder<Queue>,
|
||||||
): SelectQueryBuilder<Queue> {
|
): SelectQueryBuilder<Queue> {
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
|
|
||||||
console.log({ start, end, item_queue_id: this.filterParam.queue_id });
|
|
||||||
|
|
||||||
queryBuilder.andWhere(
|
|
||||||
`${this.tableName}.created_at BETWEEN :start AND :end`,
|
|
||||||
{
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.item_queue_id = :item_queue_id`, {
|
|
||||||
item_queue_id: this.filterParam.queue_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.filterParam.vip != null) {
|
if (this.filterParam.vip != null) {
|
||||||
queryBuilder.andWhere(`${this.tableName}.vip = :vip`, {
|
queryBuilder.andWhere(`${this.tableName}.vip = :vip`, {
|
||||||
vip: this.filterParam.vip,
|
vip: this.filterParam.vip,
|
||||||
|
|
|
@ -1,35 +1,32 @@
|
||||||
import { QueueModel } from 'src/modules/queue/data/models/queue.model';
|
|
||||||
import { CustomerQueueManager } from './customer-queue.manager';
|
import { CustomerQueueManager } from './customer-queue.manager';
|
||||||
import { QueueCondition } from '../formula/queue-condition.formula';
|
|
||||||
|
|
||||||
export class CustomerQueueDetailManager extends CustomerQueueManager {
|
export class CustomerQueueDetailManager extends CustomerQueueManager {
|
||||||
private queues: QueueModel[] = [];
|
|
||||||
currentQueues(queues: QueueModel[]) {
|
|
||||||
this.queues = queues;
|
|
||||||
}
|
|
||||||
get data() {
|
get data() {
|
||||||
const queueCondition = new QueueCondition(this.queues);
|
|
||||||
return this.tickets.map((ticket) => {
|
return this.tickets.map((ticket) => {
|
||||||
const queueItems = this.mergeQueueItems(ticket);
|
|
||||||
return {
|
return {
|
||||||
id: ticket.id,
|
id: ticket.id,
|
||||||
code: ticket.code,
|
code: ticket.code,
|
||||||
customer: ticket.customer,
|
customer: ticket.customer,
|
||||||
phone: ticket.phone,
|
phone: ticket.phone,
|
||||||
date: ticket.date,
|
date: ticket.date,
|
||||||
summary: this.summaryTicket(ticket),
|
summary: {
|
||||||
items: queueItems.map((item) => {
|
total_activities: this.totalActivities(ticket),
|
||||||
|
total_tickets: this.totalTickets(ticket),
|
||||||
|
total_used: this.totalUsedTickets(ticket),
|
||||||
|
total_queue: this.totalQueueTickets(ticket),
|
||||||
|
},
|
||||||
|
items: ticket.items.map((item) => {
|
||||||
return {
|
return {
|
||||||
id: item.id,
|
id: item.item_id,
|
||||||
item_queue_id: item.queue_item_id,
|
item_queue_id: item.id,
|
||||||
title: item.title,
|
title: item.item.item_queue?.name ?? item.item.name,
|
||||||
image_url: item.image_url,
|
image_url: item.item.image_url,
|
||||||
summary: {
|
summary: {
|
||||||
total_tickets: item.qty,
|
total_tickets: item.qty,
|
||||||
total_used: this.totalUsedItems(item.queues),
|
total_used: this.totalUsedItems(item),
|
||||||
total_queue: this.totalQueueItems(item.queues),
|
total_queue: this.totalQueueItems(item),
|
||||||
},
|
},
|
||||||
queue: item.queues
|
queue: item.queue
|
||||||
.sort((a, b) => b.time - a.time)
|
.sort((a, b) => b.time - a.time)
|
||||||
.map((q) => {
|
.map((q) => {
|
||||||
return {
|
return {
|
||||||
|
@ -39,7 +36,13 @@ export class CustomerQueueDetailManager extends CustomerQueueManager {
|
||||||
status: q.status,
|
status: q.status,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
queue_condition: queueCondition.condition(item.queue_item_id),
|
queue_condition: {
|
||||||
|
available: true,
|
||||||
|
average: 12,
|
||||||
|
nearest: '13:10',
|
||||||
|
crowded_level: 20,
|
||||||
|
available_time: '15:00',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,62 +1,42 @@
|
||||||
import {
|
import { QueueItemModel } from 'src/modules/queue/data/models/queue.model';
|
||||||
QueueItemModel,
|
|
||||||
QueueModel,
|
|
||||||
} from 'src/modules/queue/data/models/queue.model';
|
|
||||||
import { CustomerQueueManager } from './customer-queue.manager';
|
import { CustomerQueueManager } from './customer-queue.manager';
|
||||||
import { QueueCondition } from '../formula/queue-condition.formula';
|
|
||||||
|
|
||||||
export class CustomerQueueItemListManager extends CustomerQueueManager {
|
export class CustomerQueueItemListManager extends CustomerQueueManager {
|
||||||
protected queues: QueueModel[] = [];
|
|
||||||
currentQueues(queues: QueueModel[]) {
|
|
||||||
this.queues = queues;
|
|
||||||
}
|
|
||||||
get data() {
|
get data() {
|
||||||
const tickets = this.tickets;
|
const tickets = this.tickets;
|
||||||
const ticketCount = {};
|
|
||||||
const queueCondition = new QueueCondition(this.queues);
|
|
||||||
|
|
||||||
const ticketItems = {};
|
const ticketItems = {};
|
||||||
|
|
||||||
tickets.forEach((ticket) => {
|
tickets.forEach((ticket) => {
|
||||||
const itemsInTicket = [];
|
|
||||||
ticket.items.forEach((item) => {
|
ticket.items.forEach((item) => {
|
||||||
const item_id = item.item.item_queue?.id ?? item.item.id;
|
const item_id = item.item.item_queue?.id ?? item.item.id;
|
||||||
const currentItem = ticketItems[item_id];
|
const currentItem = ticketItems[item_id];
|
||||||
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
||||||
itemsInTicket.push(item_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
const uniqueTicket = Array.from(new Set(itemsInTicket));
|
|
||||||
|
|
||||||
uniqueTicket.forEach((item_id) => {
|
|
||||||
ticketCount[item_id] = ticketCount[item_id]
|
|
||||||
? ticketCount[item_id] + 1
|
|
||||||
: 1;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
|
return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
|
||||||
const item = items[0];
|
const item = items[0];
|
||||||
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
||||||
const queue_qty = this.queueItemQty(items);
|
|
||||||
const queueItem = item.item.item_queue ?? item.item;
|
|
||||||
return {
|
return {
|
||||||
id: queueItem.id,
|
id: item.item_id,
|
||||||
queue_item_id: item.id,
|
title: item.item.item_queue?.name ?? item.item.name,
|
||||||
title: queueItem.name,
|
|
||||||
image_url: item.item.image_url,
|
image_url: item.item.image_url,
|
||||||
qty: item_qty - queue_qty,
|
qty: item_qty,
|
||||||
ticket: ticketCount[queueItem.id],
|
|
||||||
|
|
||||||
queue_condition: queueCondition.condition(queueItem.id),
|
available: true,
|
||||||
...queueCondition.condition(queueItem.id),
|
average: 12,
|
||||||
|
nearest: '13:10',
|
||||||
|
crowded_level: 20,
|
||||||
|
available_time: '15:00',
|
||||||
|
|
||||||
|
queue_condition: {
|
||||||
|
available: true,
|
||||||
|
average: 12,
|
||||||
|
nearest: '13:10',
|
||||||
|
crowded_level: 20,
|
||||||
|
available_time: '15:00',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected queueItemQty(queues: QueueItemModel[]) {
|
|
||||||
return queues.reduce(
|
|
||||||
(acc, item) => acc + item.queue.reduce((acc, q) => acc + q.qty, 0),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@ import { CustomerQueueManager } from './customer-queue.manager';
|
||||||
export class CustomerQueueItemManager extends CustomerQueueManager {
|
export class CustomerQueueItemManager extends CustomerQueueManager {
|
||||||
get data() {
|
get data() {
|
||||||
return this.tickets.map((ticket) => {
|
return this.tickets.map((ticket) => {
|
||||||
const queueItems = this.mergeQueueItems(ticket);
|
|
||||||
const item = ticket.items[0];
|
const item = ticket.items[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: ticket.id,
|
id: ticket.id,
|
||||||
code: ticket.code,
|
code: ticket.code,
|
||||||
|
@ -13,8 +11,13 @@ export class CustomerQueueItemManager extends CustomerQueueManager {
|
||||||
phone: ticket.phone,
|
phone: ticket.phone,
|
||||||
date: ticket.date,
|
date: ticket.date,
|
||||||
image_url: item.item.image_url,
|
image_url: item.item.image_url,
|
||||||
summary: this.summaryTicket(ticket),
|
summary: {
|
||||||
queue: queueItems[0].queues
|
total_activities: this.totalActivities(ticket),
|
||||||
|
total_tickets: this.totalTickets(ticket),
|
||||||
|
total_used: this.totalUsedTickets(ticket),
|
||||||
|
total_queue: this.totalQueueTickets(ticket),
|
||||||
|
},
|
||||||
|
queue: item.queue
|
||||||
.sort((a, b) => b.time - a.time)
|
.sort((a, b) => b.time - a.time)
|
||||||
.map((q) => {
|
.map((q) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,22 +1,7 @@
|
||||||
import {
|
import { QueueItemModel } from 'src/modules/queue/data/models/queue.model';
|
||||||
QueueModel,
|
|
||||||
QueueTicketModel,
|
|
||||||
} from 'src/modules/queue/data/models/queue.model';
|
|
||||||
import { CustomerQueueManager } from './customer-queue.manager';
|
import { CustomerQueueManager } from './customer-queue.manager';
|
||||||
|
|
||||||
export class CustomerQueueListManager extends CustomerQueueManager {
|
export class CustomerQueueListManager extends CustomerQueueManager {
|
||||||
private ticketToQueues(tickets: QueueTicketModel[]): QueueModel[] {
|
|
||||||
const ticket = tickets.map((ticket) => {
|
|
||||||
const queue = ticket.items.map((item) => {
|
|
||||||
return item.queue;
|
|
||||||
});
|
|
||||||
|
|
||||||
return queue.flat();
|
|
||||||
});
|
|
||||||
|
|
||||||
return ticket.flat().sort((a, b) => b.time - a.time);
|
|
||||||
}
|
|
||||||
|
|
||||||
get data() {
|
get data() {
|
||||||
const tickets = this.tickets;
|
const tickets = this.tickets;
|
||||||
const ticketItems = {};
|
const ticketItems = {};
|
||||||
|
@ -25,56 +10,37 @@ export class CustomerQueueListManager extends CustomerQueueManager {
|
||||||
ticket.items.forEach((item) => {
|
ticket.items.forEach((item) => {
|
||||||
const item_id = item.item.item_queue?.id ?? item.item.id;
|
const item_id = item.item.item_queue?.id ?? item.item.id;
|
||||||
const currentItem = ticketItems[item_id];
|
const currentItem = ticketItems[item_id];
|
||||||
const ticketQueue = { ...ticket, items: [item] };
|
item.ticket = ticket;
|
||||||
|
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
||||||
ticketItems[item_id] = currentItem
|
|
||||||
? [...currentItem, ticketQueue]
|
|
||||||
: [ticketQueue];
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.keys(ticketItems)
|
return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
|
||||||
.map((item_id) => {
|
const item = items[0];
|
||||||
const tickets: QueueTicketModel[] = ticketItems[item_id];
|
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
||||||
const item = tickets[0].items[0];
|
return {
|
||||||
const uniqueTicket = tickets.filter(
|
id: item.item_id,
|
||||||
(obj1, i, arr) => arr.findIndex((obj2) => obj2.id === obj1.id) === i,
|
title: item.item.item_queue?.name ?? item.item.name,
|
||||||
);
|
image_url: item.item.image_url,
|
||||||
let totalQueue = 0;
|
qty: item_qty,
|
||||||
|
|
||||||
const currentTickets = uniqueTicket.map((ticket) => {
|
items: items.map((item) => {
|
||||||
const currentTicket = tickets.filter((t) => t.id === ticket.id);
|
return {
|
||||||
const queues = this.ticketToQueues(currentTicket);
|
code: item.ticket.code,
|
||||||
const currentQueues = queues.map((q) => {
|
customer: item.ticket.customer,
|
||||||
|
phone: item.ticket.phone,
|
||||||
|
id: item.ticket.id,
|
||||||
|
queue: item.queue.map((q) => {
|
||||||
return {
|
return {
|
||||||
code: q.code,
|
code: q.code,
|
||||||
qty: q.qty,
|
qty: q.qty,
|
||||||
time: this.toTime(q.time),
|
time: this.toTime(q.time),
|
||||||
status: q.status,
|
status: q.status,
|
||||||
};
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
totalQueue += currentQueues.length;
|
|
||||||
return currentQueues.length > 0
|
|
||||||
? {
|
|
||||||
code: ticket.code,
|
|
||||||
customer: ticket.customer,
|
|
||||||
phone: ticket.phone,
|
|
||||||
id: ticket.id,
|
|
||||||
queue: currentQueues,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
});
|
|
||||||
|
|
||||||
return currentTickets.filter(Boolean).length > 0
|
|
||||||
? {
|
|
||||||
id: item.item_id,
|
|
||||||
title: item.item.item_queue?.name ?? item.item.name,
|
|
||||||
image_url: item.item.image_url,
|
|
||||||
qty: totalQueue,
|
|
||||||
items: currentTickets.filter(Boolean),
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
})
|
|
||||||
.filter(Boolean);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
import { CustomerQueueManager } from './customer-queue.manager';
|
|
||||||
|
|
||||||
export class CustomerQueuePosItemManager extends CustomerQueueManager {
|
|
||||||
get data() {
|
|
||||||
const ticket = this.tickets[0];
|
|
||||||
const queueItems = this.mergeQueueItems(ticket);
|
|
||||||
return {
|
|
||||||
id: ticket.id,
|
|
||||||
code: ticket.code,
|
|
||||||
customer: ticket.customer,
|
|
||||||
phone: ticket.phone,
|
|
||||||
date: ticket.date,
|
|
||||||
summary: this.summaryTicket(ticket),
|
|
||||||
items: queueItems.map((item) => {
|
|
||||||
return {
|
|
||||||
id: item.id,
|
|
||||||
item_queue_id: item.item_id,
|
|
||||||
title: item.title,
|
|
||||||
image_url: item.image_url,
|
|
||||||
summary: {
|
|
||||||
total_tickets: item.qty,
|
|
||||||
total_used: this.totalUsedItems(item.queues),
|
|
||||||
total_queue: this.totalQueueItems(item.queues),
|
|
||||||
remaining: item.qty - this.totalQueueItems(item.queues),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { QueueCondition } from '../formula/queue-condition.formula';
|
|
||||||
import { CustomerQueueItemListManager } from './customer-queue-item-list.manager';
|
|
||||||
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
|
||||||
|
|
||||||
export class CustomerQueueRecommendManager extends CustomerQueueItemListManager {
|
|
||||||
recommend(items: ItemQueueModel[]) {
|
|
||||||
const queueCondition = new QueueCondition(this.queues);
|
|
||||||
|
|
||||||
return items.map((queueItem) => {
|
|
||||||
const item = queueItem.items[0];
|
|
||||||
return {
|
|
||||||
id: item.id,
|
|
||||||
queue_item_id: queueItem.id,
|
|
||||||
title: queueItem.name,
|
|
||||||
image_url: item.image_url,
|
|
||||||
|
|
||||||
queue_condition: queueCondition.condition(queueItem.id),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,12 @@ export class CustomerQueueSummaryManager extends CustomerQueueManager {
|
||||||
customer: ticket.customer,
|
customer: ticket.customer,
|
||||||
phone: ticket.phone,
|
phone: ticket.phone,
|
||||||
date: ticket.date,
|
date: ticket.date,
|
||||||
summary: this.summaryTicket(ticket),
|
summary: {
|
||||||
|
total_activities: this.totalActivities(ticket),
|
||||||
|
total_tickets: this.totalTickets(ticket),
|
||||||
|
total_used: this.totalUsedTickets(ticket),
|
||||||
|
total_queue: this.totalQueueTickets(ticket),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import { CustomerQueueManager } from './customer-queue.manager';
|
|
||||||
|
|
||||||
export class CustomerQueueTicketSummaryManager extends CustomerQueueManager {
|
|
||||||
get data() {
|
|
||||||
const tickets = this.tickets.map((ticket) => {
|
|
||||||
return {
|
|
||||||
id: ticket.id,
|
|
||||||
code: ticket.code,
|
|
||||||
customer: ticket.customer,
|
|
||||||
phone: ticket.phone,
|
|
||||||
date: ticket.date,
|
|
||||||
summary: this.summaryTicket(ticket),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return tickets[0];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,7 @@
|
||||||
import {
|
import {
|
||||||
QueueItemModel,
|
QueueItemModel,
|
||||||
QueueModel,
|
|
||||||
QueueTicketModel,
|
QueueTicketModel,
|
||||||
} from '../../../data/models/queue.model';
|
} from '../../../data/models/queue.model';
|
||||||
import { MergedItemQueue } from '../../entities/queue-item.entity';
|
|
||||||
import { toTime } from '../../helpers/time.helper';
|
|
||||||
|
|
||||||
export class CustomerQueueManager {
|
export class CustomerQueueManager {
|
||||||
constructor(protected readonly tickets: QueueTicketModel[]) {}
|
constructor(protected readonly tickets: QueueTicketModel[]) {}
|
||||||
|
@ -13,106 +10,49 @@ export class CustomerQueueManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
toTime(timestamp: number): string {
|
toTime(timestamp: number): string {
|
||||||
return toTime(timestamp);
|
// js function to convert timestamp (1729739455000) to time with format HH:mm
|
||||||
|
const date = new Date(timestamp / 1000);
|
||||||
|
const hours = date.getHours() + 7;
|
||||||
|
const minutes = date.getMinutes();
|
||||||
|
return `${hours < 10 ? '0' : ''}${hours}:${
|
||||||
|
minutes < 10 ? '0' : ''
|
||||||
|
}${minutes}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalActivities(ticket: QueueTicketModel): number {
|
totalActivities(ticket: QueueTicketModel): number {
|
||||||
const ticketItems = {};
|
return ticket.items.length;
|
||||||
ticket.items.forEach((item) => {
|
|
||||||
const item_id =
|
|
||||||
item.item?.item_queue?.id ?? item.item?.id ?? item.item_id;
|
|
||||||
const currentItem = ticketItems[item_id];
|
|
||||||
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
|
||||||
});
|
|
||||||
return Object.keys(ticketItems).length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
totalTickets(ticket: QueueTicketModel): number {
|
totalTickets(ticket: QueueTicketModel): number {
|
||||||
return ticket.items.reduce((acc, item) => acc + item.qty, 0);
|
return ticket.items.reduce((acc, item) => acc + item.qty, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalUsedItems(queues: QueueModel[]): number {
|
totalUsedItems(item: QueueItemModel): number {
|
||||||
return queues
|
return item.queue
|
||||||
.filter((q) => ['done', 'called'].includes(q.status))
|
.filter((q) => ['done', 'called'].includes(q.status))
|
||||||
.reduce((acc, item) => acc + item.qty, 0);
|
.reduce((acc, item) => acc + item.qty, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalUsedTickets(ticket: QueueTicketModel): number {
|
totalUsedTickets(ticket: QueueTicketModel): number {
|
||||||
const tickets = ticket.items.map((item) => {
|
const tickets = ticket.items.map((item) => {
|
||||||
return this.totalUsedItems(item.queue);
|
return this.totalUsedItems(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
||||||
return tickets.reduce(reducer, 0);
|
return tickets.reduce(reducer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalQueueItems(queues: QueueModel[]): number {
|
totalQueueItems(item: QueueItemModel): number {
|
||||||
return queues
|
return item.queue
|
||||||
.filter((q) => ['waiting'].includes(q.status))
|
.filter((q) => ['waiting'].includes(q.status))
|
||||||
.reduce((acc, item) => acc + item.qty, 0);
|
.reduce((acc, item) => acc + item.qty, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalQueueTickets(ticket: QueueTicketModel): number {
|
totalQueueTickets(ticket: QueueTicketModel): number {
|
||||||
const tickets = ticket.items.map((item) => {
|
const tickets = ticket.items.map((item) => {
|
||||||
return this.totalQueueItems(item.queue);
|
return this.totalQueueItems(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
const reducer = (accumulator, currentValue) => accumulator + currentValue;
|
||||||
return tickets.reduce(reducer, 0);
|
return tickets.reduce(reducer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
totalQueueItemTickets(ticket: QueueTicketModel): number {
|
|
||||||
const tickets = ticket.items
|
|
||||||
.map((item) => {
|
|
||||||
return this.totalQueueItems(item.queue);
|
|
||||||
})
|
|
||||||
.filter((item) => item > 0);
|
|
||||||
|
|
||||||
return tickets.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
summaryTicket(ticket: QueueTicketModel): any {
|
|
||||||
const total_tickets = this.totalTickets(ticket);
|
|
||||||
const total_used = this.totalUsedTickets(ticket);
|
|
||||||
const total_queue = this.totalQueueTickets(ticket);
|
|
||||||
const total_queue_item = this.totalQueueItemTickets(ticket);
|
|
||||||
return {
|
|
||||||
total_activities: this.totalActivities(ticket),
|
|
||||||
total_tickets,
|
|
||||||
total_used,
|
|
||||||
total_queue,
|
|
||||||
total_queue_item,
|
|
||||||
remaining: total_tickets - total_queue,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
mergeQueueItems(ticket: QueueTicketModel): MergedItemQueue[] {
|
|
||||||
const ticketItems = {};
|
|
||||||
ticket.items.forEach((item) => {
|
|
||||||
const item_id = item.item.item_queue?.id ?? item.item.id;
|
|
||||||
const currentItem = ticketItems[item_id];
|
|
||||||
ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
|
|
||||||
});
|
|
||||||
|
|
||||||
return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
|
|
||||||
const item = items[0];
|
|
||||||
const queues: QueueModel[] = [];
|
|
||||||
|
|
||||||
items.forEach((item) => {
|
|
||||||
queues.push(...item.queue);
|
|
||||||
});
|
|
||||||
|
|
||||||
const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
|
|
||||||
const queueItem = item.item.item_queue ?? item.item;
|
|
||||||
return {
|
|
||||||
id: item.item_id,
|
|
||||||
queue_item_id: queueItem.id,
|
|
||||||
item_id: item.id,
|
|
||||||
title: queueItem.name,
|
|
||||||
image_url: item.item.image_url,
|
|
||||||
qty: item_qty,
|
|
||||||
queues,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,98 +5,24 @@ import {
|
||||||
validateRelations,
|
validateRelations,
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
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 { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { QueueItemModel, QueueModel } from '../../data/models/queue.model';
|
import { QueueModel } from '../../data/models/queue.model';
|
||||||
import { padCode } from 'src/modules/transaction/vip-code/domain/usecases/managers/helpers/generate-random.helper';
|
import { generateRandom } from 'src/modules/transaction/vip-code/domain/usecases/managers/helpers/generate-random.helper';
|
||||||
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
|
||||||
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';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
constructor(
|
|
||||||
private readonly bucketService: QueueBucketReadService,
|
|
||||||
private readonly queueTimeFormula: QueueTimeFormula,
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
private currentItemMaster: ItemModel;
|
|
||||||
|
|
||||||
async averageTime(): Promise<number> {
|
|
||||||
const item = await this.getItemMaster();
|
|
||||||
return item.play_estimation;
|
|
||||||
}
|
|
||||||
|
|
||||||
async queueTime(queue_id: string): Promise<number[]> {
|
|
||||||
const queueTimes = await this.queueTimeFormula.items(queue_id);
|
|
||||||
const queues = Object.values<number>(queueTimes);
|
|
||||||
|
|
||||||
const first = queues[0];
|
|
||||||
const last = queues[queues.length - 1] ?? moment().valueOf();
|
|
||||||
const average = this.queueTimeFormula.average;
|
|
||||||
return [Math.floor(first), Math.floor(last + average)];
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
const vip = this.data.vip ?? false;
|
|
||||||
const item = await this.getItemMaster();
|
|
||||||
this.currentItemMaster = item;
|
|
||||||
const [, end] = await this.queueTime(item.item_queue_id);
|
|
||||||
|
|
||||||
const queueNumber = await this.bucketService.getQueue(
|
|
||||||
item.item_queue_id,
|
|
||||||
vip,
|
|
||||||
);
|
|
||||||
const prefix = vip ? 'B' : 'A';
|
|
||||||
const code = `${prefix}${padCode(queueNumber)}`;
|
|
||||||
|
|
||||||
Object.assign(this.data, {
|
Object.assign(this.data, {
|
||||||
status: STATUS.WAITING,
|
status: STATUS.WAITING,
|
||||||
time: end,
|
time: new Date().getTime(),
|
||||||
item_queue_id: item.item_queue_id,
|
vip: false,
|
||||||
vip,
|
code: `Q${generateRandom(4, true)}`,
|
||||||
code,
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getItemMaster(): Promise<ItemModel> {
|
|
||||||
const queueItem: QueueItemModel = await this.dataService.item.findOne({
|
|
||||||
relations: ['item', 'item.item_queue'],
|
|
||||||
where: {
|
|
||||||
id: this.data.item_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return queueItem.item;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
import {
|
|
||||||
HttpStatus,
|
|
||||||
Injectable,
|
|
||||||
UnprocessableEntityException,
|
|
||||||
} 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 { QueueOrderModel } from '../../data/models/queue.model';
|
|
||||||
import { SplitQueueDto } from '../../infrastructure/controllers/dto/split-queue.dto';
|
|
||||||
import { QueueService } from '../../data/services/queue.service';
|
|
||||||
import { TicketDataService } from '../../data/services/ticket.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class SplitQueueManager extends BaseCreateManager<QueueOrderModel> {
|
|
||||||
private dto: SplitQueueDto;
|
|
||||||
constructor(
|
|
||||||
private readonly queueService: QueueService,
|
|
||||||
private readonly ticketService: TicketDataService,
|
|
||||||
) {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
setRequestData(dto: SplitQueueDto): void {
|
|
||||||
this.dto = dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
async validateProcess(): Promise<void> {
|
|
||||||
await super.validateProcess();
|
|
||||||
const existTickets = await this.ticketService.ticketByUser(
|
|
||||||
this.dto.name,
|
|
||||||
this.dto.phone,
|
|
||||||
);
|
|
||||||
if (existTickets) {
|
|
||||||
throw new UnprocessableEntityException({
|
|
||||||
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
||||||
code: 20002,
|
|
||||||
message:
|
|
||||||
'Antrian dengan nama dan nomor telepon sudah terdaftar, silahkan gunakan nomor telepon atau nama lain',
|
|
||||||
error: 'QUEUE_ALREADY_EXIST',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async prepareData(): Promise<void> {
|
|
||||||
const existTickets = await this.ticketService.ticketByCode(this.data.code);
|
|
||||||
const { tickets, ...order } = this.data;
|
|
||||||
const ticket = tickets[0];
|
|
||||||
const items = tickets
|
|
||||||
.map((ticket) => {
|
|
||||||
return ticket.items;
|
|
||||||
})
|
|
||||||
.flat();
|
|
||||||
const postfix = existTickets.length;
|
|
||||||
this.data = {
|
|
||||||
code: order.code,
|
|
||||||
customer: this.dto.name,
|
|
||||||
phone: this.dto.phone,
|
|
||||||
date: order.date,
|
|
||||||
updated_at: new Date().getTime(),
|
|
||||||
tickets: [
|
|
||||||
{
|
|
||||||
code: `${order.code}-${postfix}`,
|
|
||||||
customer: this.dto.name,
|
|
||||||
phone: this.dto.phone,
|
|
||||||
date: ticket.date,
|
|
||||||
order_id: order.id,
|
|
||||||
items: items.map((item) => {
|
|
||||||
const itemQty = this.dto.items.find(
|
|
||||||
(i) => i.queue_item_id === item.id,
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
item_id: item.item_id,
|
|
||||||
qty: itemQty.qty,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
super.prepareData();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
|
||||||
this.dto.items.forEach((item) => {
|
|
||||||
this.queueService.updateItemQty(item.queue_item_id, item.qty);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get uniqueColumns(): columnUniques[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get eventTopics(): EventTopics[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get entityTarget(): any {
|
|
||||||
return QueueOrderModel;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { IsNotEmpty, IsString } from 'class-validator';
|
|
||||||
|
|
||||||
export class LoginReceiptDto {
|
|
||||||
@ApiProperty({ name: 'id', required: true })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
id: string;
|
|
||||||
}
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsBoolean, IsEnum, ValidateIf } from 'class-validator';
|
import { IsBoolean, ValidateIf } from 'class-validator';
|
||||||
import { Transform } from 'class-transformer';
|
import { Transform } from 'class-transformer';
|
||||||
import { FilterQueueEntity } from 'src/modules/queue/domain/entities/filter.entity';
|
import { FilterQueueEntity } from 'src/modules/queue/domain/entities/filter.entity';
|
||||||
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
|
||||||
|
|
||||||
export class QueueDto implements FilterQueueEntity {
|
export class QueueDto implements FilterQueueEntity {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
@ -22,20 +21,4 @@ export class QueueDto implements FilterQueueEntity {
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ValidateIf((body) => body.vip)
|
@ValidateIf((body) => body.vip)
|
||||||
vip: boolean;
|
vip: boolean;
|
||||||
|
|
||||||
@ApiProperty({ type: String, required: false })
|
|
||||||
order_by: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: 'string',
|
|
||||||
required: false,
|
|
||||||
description: `Select ("${ORDER_TYPE.ASC}", "${ORDER_TYPE.DESC}")`,
|
|
||||||
})
|
|
||||||
@ValidateIf((body) => body.order_type)
|
|
||||||
@IsEnum(ORDER_TYPE, {
|
|
||||||
message: `order_type must be a valid enum ${JSON.stringify(
|
|
||||||
Object.values(ORDER_TYPE),
|
|
||||||
)}`,
|
|
||||||
})
|
|
||||||
order_type: ORDER_TYPE;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import {
|
|
||||||
IsArray,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsNumber,
|
|
||||||
IsString,
|
|
||||||
Matches,
|
|
||||||
Min,
|
|
||||||
ValidateNested,
|
|
||||||
} from 'class-validator';
|
|
||||||
|
|
||||||
export class ItemSplitQueueDto {
|
|
||||||
@ApiProperty({ name: 'queue_item_id', required: true })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
queue_item_id: string;
|
|
||||||
@ApiProperty({
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
example: 1,
|
|
||||||
})
|
|
||||||
@IsNumber()
|
|
||||||
@Min(1)
|
|
||||||
@IsNotEmpty()
|
|
||||||
qty: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SplitQueueDto {
|
|
||||||
@ApiProperty({ name: 'order_id', required: true })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
order_id: string;
|
|
||||||
|
|
||||||
@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;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: [ItemSplitQueueDto],
|
|
||||||
required: false,
|
|
||||||
example: [
|
|
||||||
{
|
|
||||||
queue_item_id: 'string',
|
|
||||||
qty: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
@ValidateNested({ each: true })
|
|
||||||
@IsArray()
|
|
||||||
items: ItemSplitQueueDto[];
|
|
||||||
}
|
|
|
@ -1,11 +1,4 @@
|
||||||
import {
|
import { Controller, Get, Param, Post, Query } from '@nestjs/common';
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
Query,
|
|
||||||
UnauthorizedException,
|
|
||||||
} 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';
|
||||||
|
@ -15,51 +8,23 @@ import { PaginationResponse } from 'src/core/response/domain/ok-response.interfa
|
||||||
import { Queue } from '../../domain/entities/queue.entity';
|
import { Queue } from '../../domain/entities/queue.entity';
|
||||||
import { QueueDto } from './dto/queue.filter';
|
import { QueueDto } from './dto/queue.filter';
|
||||||
import { Pagination } from 'src/core/response';
|
import { Pagination } from 'src/core/response';
|
||||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { UserProvider } from 'src/core/sessions';
|
|
||||||
|
|
||||||
@ApiTags(`Queue Admin`)
|
@ApiTags(`Queue Admin`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}-admin`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}-admin`)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
@Public(false)
|
@Public(true)
|
||||||
@ExcludePrivilege()
|
|
||||||
export class QueueAdminController {
|
export class QueueAdminController {
|
||||||
constructor(
|
constructor(private orchestrator: QueueAdminOrchestrator) {}
|
||||||
private orchestrator: QueueAdminOrchestrator,
|
|
||||||
private readonly userProvider: UserProvider,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Get('queues')
|
@Get('queues')
|
||||||
@Pagination()
|
@Pagination()
|
||||||
async index(@Query() params: QueueDto): Promise<PaginationResponse<Queue>> {
|
async index(@Query() params: QueueDto): Promise<PaginationResponse<Queue>> {
|
||||||
const queue_id = this.userProvider.user.item_id;
|
return await this.orchestrator.index(params);
|
||||||
if (!queue_id) {
|
|
||||||
throw new UnauthorizedException({
|
|
||||||
error: 'USER_IS_NOT_ADMIN',
|
|
||||||
message: "Login user isn't admin, please login in admin account",
|
|
||||||
code: 20001,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return await this.orchestrator.index({ ...params, queue_id });
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('queues/:id')
|
|
||||||
@Public(true)
|
|
||||||
@Pagination()
|
|
||||||
async indexPublic(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@Query() params: QueueDto,
|
|
||||||
): Promise<PaginationResponse<Queue>> {
|
|
||||||
return await this.orchestrator.index({ ...params, queue_id: id });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('queues/:id/call')
|
@Post('queues/:id/call')
|
||||||
async call(@Param('id') id: string) {
|
async call(@Param('id') id: string) {
|
||||||
return await this.orchestrator.call(id);
|
return await this.orchestrator.call(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('queues/:id/done')
|
|
||||||
async done(@Param('id') id: string) {
|
|
||||||
return await this.orchestrator.done(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
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, Query, Res } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Post } 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';
|
||||||
|
@ -8,15 +8,6 @@ import { QueueOrchestrator } from '../../domain/queue.orchestrator';
|
||||||
import { QueueOrder } from '../../domain/entities/order.entity';
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
import { Queue } from '../../domain/entities/queue.entity';
|
import { Queue } from '../../domain/entities/queue.entity';
|
||||||
import { RegisterQueueDto } from './dto/register-queue.dto';
|
import { RegisterQueueDto } from './dto/register-queue.dto';
|
||||||
import { SplitQueueDto } from './dto/split-queue.dto';
|
|
||||||
import { LoginQueueDto } from './dto/login-queue.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}`)
|
||||||
|
@ -25,33 +16,11 @@ import { Response } from 'express';
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('split')
|
|
||||||
async splitQueue(@Body() data: SplitQueueDto): Promise<QueueOrder> {
|
|
||||||
return await this.orchestrator.split(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('login')
|
|
||||||
async loginQueue(@Body() data: LoginQueueDto): Promise<QueueOrder> {
|
|
||||||
return await this.orchestrator.loginPhone(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('login/receipt')
|
|
||||||
async loginReceipt(@Body() { id }: LoginReceiptDto): Promise<QueueOrder> {
|
|
||||||
console.log(id);
|
|
||||||
return await this.orchestrator.loginCustomer(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('login/:id')
|
@Get('login/:id')
|
||||||
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
async loginCustomer(@Param('id') id: string): Promise<QueueOrder> {
|
||||||
return await this.orchestrator.loginCustomer(id);
|
return await this.orchestrator.loginCustomer(id);
|
||||||
|
@ -70,53 +39,16 @@ export class QueueController {
|
||||||
return await this.orchestrator.queueTicketDetail(id, ticket_id);
|
return await this.orchestrator.queueTicketDetail(id, ticket_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/tickets/:ticket_id/summary')
|
|
||||||
async queueTicketActive(
|
|
||||||
@Param('id') id: string,
|
|
||||||
@Param('ticket_id') ticket_id: string,
|
|
||||||
): Promise<void> {
|
|
||||||
return await this.orchestrator.queueTicketSummary(id, ticket_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/recommendations')
|
|
||||||
async queueItemRecommends(@Param('id') id: string): Promise<void> {
|
|
||||||
return await this.orchestrator.queueItemRecommendation(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/queue-summary')
|
|
||||||
async queueItemSummary(): Promise<void> {
|
|
||||||
return await this.orchestrator.queueItemSummary();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/items')
|
@Get(':id/items')
|
||||||
async queueItems(@Param('id') id: string): Promise<void> {
|
async queueItems(@Param('id') id: string): Promise<void> {
|
||||||
return await this.orchestrator.queueItems(id);
|
return await this.orchestrator.queueItems(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/unique-items')
|
|
||||||
async queueUniqueItems(@Param('id') id: string): Promise<void> {
|
|
||||||
return await this.orchestrator.queueUniqueItems(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/pos-items')
|
|
||||||
async queuePosItems(@Param('id') id: string): Promise<void> {
|
|
||||||
return await this.orchestrator.queuePOSTickets(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/queue')
|
@Get(':id/queue')
|
||||||
async queueOrderItems(@Param('id') id: string): Promise<void> {
|
async queueOrderItems(@Param('id') id: string): Promise<void> {
|
||||||
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,
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
|
|
||||||
import { TransactionChangeStatusEvent } from 'src/modules/transaction/transaction/domain/entities/event/transaction-change-status.event';
|
|
||||||
import { TicketDataService } from '../../data/services/ticket.service';
|
|
||||||
|
|
||||||
@EventsHandler(TransactionChangeStatusEvent)
|
|
||||||
export class QueueTransactionCancelHandler
|
|
||||||
implements IEventHandler<TransactionChangeStatusEvent>
|
|
||||||
{
|
|
||||||
constructor(private queueService: TicketDataService) {}
|
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
|
||||||
const process_data = event.data.data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If data still in process (not settled) then don't create the queue order
|
|
||||||
*/
|
|
||||||
if (!['cancel', 'rejected'].includes(process_data?.status)) return;
|
|
||||||
|
|
||||||
this.queueService.deleteQueue(event.data.id);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,15 +4,18 @@ 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 { GenerateQueueManager } from '../../domain/usecases/generate-queue.manager';
|
import { TicketDataService } from '../../data/services/ticket.service';
|
||||||
|
import { QueueOrder } from '../../domain/entities/order.entity';
|
||||||
|
import { QueueTicket } from '../../domain/entities/ticket.entity';
|
||||||
|
import { QueueItem } from '../../domain/entities/queue-item.entity';
|
||||||
|
|
||||||
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
||||||
export class QueueTransactionHandler
|
export class QueueTransactionHandler
|
||||||
implements IEventHandler<TransactionChangeStatusEvent>
|
implements IEventHandler<TransactionChangeStatusEvent>
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
private readonly dataService: TransactionDataService,
|
private dataService: TransactionDataService,
|
||||||
private readonly queueGenerateManager: GenerateQueueManager,
|
private queueService: TicketDataService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
async handle(event: TransactionChangeStatusEvent) {
|
||||||
|
@ -21,21 +24,35 @@ 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' || process_data?.pos_number != null)
|
if (process_data?.status != 'settled') return;
|
||||||
return;
|
|
||||||
|
|
||||||
const transaction = await this.dataService.getOneByOptions({
|
const transaction = await this.dataService.getOneByOptions({
|
||||||
where: {
|
where: {
|
||||||
id: event.data.id,
|
id: event.data.id,
|
||||||
},
|
},
|
||||||
relations: [
|
relations: ['items'],
|
||||||
'customer_category',
|
|
||||||
'items',
|
|
||||||
'items.item',
|
|
||||||
'items.item.bundling_items',
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.queueGenerateManager.generate(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) => {
|
||||||
|
return {
|
||||||
|
item_id: item.item_id,
|
||||||
|
qty: item.qty,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const ticket: QueueTicket = { ...customerOrder, items };
|
||||||
|
const order: QueueOrder = { ...customerOrder, tickets: [ticket] };
|
||||||
|
|
||||||
|
this.queueService.createQueueOrder(order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,27 +18,12 @@ import { QueueTransactionHandler } from './infrastructure/handlers/transaction.h
|
||||||
import { TransactionDataService } from '../transaction/transaction/data/services/transaction-data.service';
|
import { TransactionDataService } from '../transaction/transaction/data/services/transaction-data.service';
|
||||||
import { TransactionModel } from '../transaction/transaction/data/models/transaction.model';
|
import { TransactionModel } from '../transaction/transaction/data/models/transaction.model';
|
||||||
import { TicketDataService } from './data/services/ticket.service';
|
import { TicketDataService } from './data/services/ticket.service';
|
||||||
import {
|
import { QueueDataService, QueueService } from './data/services/queue.service';
|
||||||
QueueDataService,
|
|
||||||
QueueOrderService,
|
|
||||||
QueueService,
|
|
||||||
} from './data/services/queue.service';
|
|
||||||
import { QueueAdminController } from './infrastructure/controllers/queue-admin.controller';
|
import { QueueAdminController } from './infrastructure/controllers/queue-admin.controller';
|
||||||
import { QueueAdminOrchestrator } from './domain/queue-admin.orchestrator';
|
import { QueueAdminOrchestrator } from './domain/queue-admin.orchestrator';
|
||||||
import { IndexQueueManager } from './domain/usecases/index-queue.manager';
|
import { IndexQueueManager } from './domain/usecases/index-queue.manager';
|
||||||
import {
|
import { CallQueueManager } from './domain/usecases/call-queue.manager';
|
||||||
CallQueueManager,
|
|
||||||
DoneQueueManager,
|
|
||||||
} from './domain/usecases/call-queue.manager';
|
|
||||||
import { RegisterQueueManager } from './domain/usecases/register-queue.manager';
|
import { RegisterQueueManager } from './domain/usecases/register-queue.manager';
|
||||||
import { QueueBucketModel } from './data/models/queue-bucket.model';
|
|
||||||
import { QueueBucketReadService } from './data/services/queue-bucket';
|
|
||||||
import { SplitQueueManager } from './domain/usecases/split-queue.manager';
|
|
||||||
import { QueueTransactionCancelHandler } from './infrastructure/handlers/cancel-transaction.handler';
|
|
||||||
import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queue.model';
|
|
||||||
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: [
|
||||||
|
@ -49,38 +34,28 @@ import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
||||||
QueueTicketModel,
|
QueueTicketModel,
|
||||||
QueueItemModel,
|
QueueItemModel,
|
||||||
QueueModel,
|
QueueModel,
|
||||||
QueueBucketModel,
|
|
||||||
ItemModel,
|
ItemModel,
|
||||||
ItemQueueModel,
|
|
||||||
TransactionModel,
|
TransactionModel,
|
||||||
],
|
],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [QueueController, QueueAdminController, QueueJobController],
|
controllers: [QueueController, QueueAdminController],
|
||||||
providers: [
|
providers: [
|
||||||
|
QueueTransactionHandler,
|
||||||
|
|
||||||
QueueOrchestrator,
|
QueueOrchestrator,
|
||||||
QueueAdminOrchestrator,
|
QueueAdminOrchestrator,
|
||||||
|
|
||||||
QueueTransactionHandler,
|
|
||||||
QueueTransactionCancelHandler,
|
|
||||||
|
|
||||||
TransactionDataService,
|
TransactionDataService,
|
||||||
TicketDataService,
|
TicketDataService,
|
||||||
QueueDataService,
|
QueueDataService,
|
||||||
QueueService,
|
QueueService,
|
||||||
QueueBucketReadService,
|
|
||||||
QueueOrderService,
|
|
||||||
|
|
||||||
IndexQueueManager,
|
IndexQueueManager,
|
||||||
CallQueueManager,
|
CallQueueManager,
|
||||||
DoneQueueManager,
|
|
||||||
RegisterQueueManager,
|
RegisterQueueManager,
|
||||||
SplitQueueManager,
|
|
||||||
|
|
||||||
QueueTimeFormula,
|
|
||||||
GenerateQueueManager,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class QueueModule {}
|
export class QueueModule {}
|
||||||
|
|
|
@ -27,11 +27,6 @@ export default <ReportConfigEntity>{
|
||||||
filter_type: FILTER_TYPE.TEXT_EQUAL,
|
filter_type: FILTER_TYPE.TEXT_EQUAL,
|
||||||
values: [false],
|
values: [false],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
column: 'main.type',
|
|
||||||
filter_type: FILTER_TYPE.TEXT_EQUAL,
|
|
||||||
values: ['counter'],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
defaultOrderBy: [],
|
defaultOrderBy: [],
|
||||||
lowLevelOrderBy: [],
|
lowLevelOrderBy: [],
|
||||||
|
@ -54,27 +49,6 @@ export default <ReportConfigEntity>{
|
||||||
type: DATA_TYPE.DIMENSION,
|
type: DATA_TYPE.DIMENSION,
|
||||||
format: DATA_FORMAT.TEXT,
|
format: DATA_FORMAT.TEXT,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
column: 'main__creator_counter_no',
|
|
||||||
query: 'main.creator_counter_no',
|
|
||||||
label: 'No.PoS',
|
|
||||||
type: DATA_TYPE.DIMENSION,
|
|
||||||
format: DATA_FORMAT.TEXT,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
column: 'main__creator_counter_name',
|
|
||||||
query: 'main.creator_counter_name',
|
|
||||||
label: 'Nama PoS',
|
|
||||||
type: DATA_TYPE.DIMENSION,
|
|
||||||
format: DATA_FORMAT.TEXT,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
column: 'main__creator_name',
|
|
||||||
query: 'main.creator_name',
|
|
||||||
label: 'Nama Kasir',
|
|
||||||
type: DATA_TYPE.DIMENSION,
|
|
||||||
format: DATA_FORMAT.TEXT,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
column: 'main__code',
|
column: 'main__code',
|
||||||
query: `CASE WHEN main.invoice_code is not null THEN main.invoice_code ELSE main.payment_code END`,
|
query: `CASE WHEN main.invoice_code is not null THEN main.invoice_code ELSE main.payment_code END`,
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
import { TransactionModel } from './transaction.model';
|
import { TransactionModel } from './transaction.model';
|
||||||
import { RefundItemModel } from 'src/modules/transaction/refund/data/models/refund-item.model';
|
import { RefundItemModel } from 'src/modules/transaction/refund/data/models/refund-item.model';
|
||||||
import { TransactionTaxEntity } from '../../domain/entities/transaction-tax.entity';
|
import { TransactionTaxEntity } from '../../domain/entities/transaction-tax.entity';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
|
||||||
|
|
||||||
@Entity(TABLE_NAME.TRANSACTION_ITEM)
|
@Entity(TABLE_NAME.TRANSACTION_ITEM)
|
||||||
export class TransactionItemModel
|
export class TransactionItemModel
|
||||||
|
@ -127,10 +126,6 @@ export class TransactionItemModel
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
})
|
})
|
||||||
item_taxes: TransactionItemTaxModel[];
|
item_taxes: TransactionItemTaxModel[];
|
||||||
|
|
||||||
@ManyToOne(() => ItemModel)
|
|
||||||
@JoinColumn({ name: 'item_id' })
|
|
||||||
item: ItemModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(TABLE_NAME.TRANSACTION_ITEM_BREAKDOWN)
|
@Entity(TABLE_NAME.TRANSACTION_ITEM_BREAKDOWN)
|
||||||
|
|
|
@ -1,25 +1,18 @@
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||||
import {
|
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
|
||||||
Column,
|
|
||||||
Entity,
|
|
||||||
JoinColumn,
|
|
||||||
ManyToOne,
|
|
||||||
OneToMany,
|
|
||||||
OneToOne,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
import {
|
import {
|
||||||
TransactionType,
|
TransactionType,
|
||||||
TransactionUserType,
|
TransactionUserType,
|
||||||
TransactionPaymentType,
|
TransactionPaymentType,
|
||||||
} from '../../constants';
|
} from '../../constants';
|
||||||
|
import { TransactionItemEntity } from '../../domain/entities/transaction-item.entity';
|
||||||
import { TransactionItemModel } from './transaction-item.model';
|
import { TransactionItemModel } from './transaction-item.model';
|
||||||
import { TransactionTaxModel } from './transaction-tax.model';
|
import { TransactionTaxModel } from './transaction-tax.model';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import { RefundModel } from 'src/modules/transaction/refund/data/models/refund.model';
|
import { RefundModel } from 'src/modules/transaction/refund/data/models/refund.model';
|
||||||
import { TransactionDemographyModel } from './transaction-demography.model';
|
import { TransactionDemographyModel } from './transaction-demography.model';
|
||||||
import { VipCategoryModel } from 'src/modules/transaction/vip-category/data/models/vip-category.model';
|
|
||||||
|
|
||||||
@Entity(TABLE_NAME.TRANSACTION)
|
@Entity(TABLE_NAME.TRANSACTION)
|
||||||
export class TransactionModel
|
export class TransactionModel
|
||||||
|
@ -59,10 +52,6 @@ export class TransactionModel
|
||||||
@Column('varchar', { name: 'season_period_type_name', nullable: true })
|
@Column('varchar', { name: 'season_period_type_name', nullable: true })
|
||||||
season_period_type_name: string;
|
season_period_type_name: string;
|
||||||
|
|
||||||
@ManyToOne(() => VipCategoryModel)
|
|
||||||
@JoinColumn({ name: 'customer_category_id' })
|
|
||||||
customer_category: VipCategoryModel;
|
|
||||||
|
|
||||||
// customer info
|
// customer info
|
||||||
@Column('enum', {
|
@Column('enum', {
|
||||||
name: 'customer_type',
|
name: 'customer_type',
|
||||||
|
@ -250,7 +239,7 @@ export class TransactionModel
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
})
|
})
|
||||||
items: TransactionItemModel[];
|
items: TransactionItemEntity[];
|
||||||
|
|
||||||
// relations to tax data
|
// relations to tax data
|
||||||
@OneToMany(() => TransactionTaxModel, (model) => model.transaction, {
|
@OneToMany(() => TransactionTaxModel, (model) => model.transaction, {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||||
|
import { TransactionEntity } from '../../domain/entities/transaction.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { TransactionModel } from '../models/transaction.model';
|
import { TransactionModel } from '../models/transaction.model';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionDataService extends BaseDataService<TransactionModel> {
|
export class TransactionDataService extends BaseDataService<TransactionEntity> {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<TransactionModel>,
|
private repo: Repository<TransactionModel>,
|
||||||
|
|
|
@ -133,7 +133,7 @@ export class PriceCalculator {
|
||||||
calledVariable = [];
|
calledVariable = [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
calledVariable.push(valueFor);
|
calledVariable.push(valueFor);
|
||||||
console.log(error.message);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
values[valueFor] = result;
|
values[valueFor] = result;
|
||||||
|
|
|
@ -116,7 +116,7 @@ export function mappingRevertTransaction(data, type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
id: data.booking_id ?? data._id ?? data.id,
|
id: data.booking_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),
|
||||||
|
|
|
@ -22,7 +22,3 @@ export function generateCodeDate() {
|
||||||
|
|
||||||
return `${month}${year}`;
|
return `${month}${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function padCode(number: number, pad = 4): string {
|
|
||||||
return String(number).padStart(pad, '0');
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
export interface WhatsappQueue {
|
|
||||||
id: string;
|
|
||||||
phone: string;
|
|
||||||
code: string;
|
|
||||||
name: string;
|
|
||||||
item_name: string;
|
|
||||||
time: number;
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
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 ?? '';
|
|
|
@ -1,62 +0,0 @@
|
||||||
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,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,169 +0,0 @@
|
||||||
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