Compare commits
No commits in common. "production" and "1.4.0-production.4" have entirely different histories.
production
...
1.4.0-prod
|
@ -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",
|
||||||
|
|
|
@ -33,10 +33,7 @@ import { SeasonTypeModel } from './modules/season-related/season-type/data/model
|
||||||
import { TaxModule } from './modules/transaction/tax/tax.module';
|
import { TaxModule } from './modules/transaction/tax/tax.module';
|
||||||
import { TaxModel } from './modules/transaction/tax/data/models/tax.model';
|
import { TaxModel } from './modules/transaction/tax/data/models/tax.model';
|
||||||
import { SalesPriceFormulaModule } from './modules/transaction/sales-price-formula/sales-price-formula.module';
|
import { SalesPriceFormulaModule } from './modules/transaction/sales-price-formula/sales-price-formula.module';
|
||||||
import {
|
import { SalesPriceFormulaModel } from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
|
|
||||||
import { ProfitShareFormulaModule } from './modules/transaction/profit-share-formula/profit-share-formula.module';
|
import { ProfitShareFormulaModule } from './modules/transaction/profit-share-formula/profit-share-formula.module';
|
||||||
import { PaymentMethodModule } from './modules/transaction/payment-method/payment-method.module';
|
import { PaymentMethodModule } from './modules/transaction/payment-method/payment-method.module';
|
||||||
import { PaymentMethodModel } from './modules/transaction/payment-method/data/models/payment-method.model';
|
import { PaymentMethodModel } from './modules/transaction/payment-method/data/models/payment-method.model';
|
||||||
|
@ -140,7 +137,6 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
||||||
TransactionItemBreakdownModel,
|
TransactionItemBreakdownModel,
|
||||||
TransactionItemTaxModel,
|
TransactionItemTaxModel,
|
||||||
TransactionBreakdownTaxModel,
|
TransactionBreakdownTaxModel,
|
||||||
TransactionSettingModel,
|
|
||||||
UserModel,
|
UserModel,
|
||||||
UserLoginModel,
|
UserLoginModel,
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ export enum TABLE_NAME {
|
||||||
NEWS = 'news',
|
NEWS = 'news',
|
||||||
PAYMENT_METHOD = 'payment_methods',
|
PAYMENT_METHOD = 'payment_methods',
|
||||||
PRICE_FORMULA = 'price_formulas',
|
PRICE_FORMULA = 'price_formulas',
|
||||||
TRANSACTION_SETTING = 'transaction_settings',
|
|
||||||
REFUND = 'refunds',
|
REFUND = 'refunds',
|
||||||
REFUND_ITEM = 'refund_items',
|
REFUND_ITEM = 'refund_items',
|
||||||
SEASON_TYPE = 'season_types',
|
SEASON_TYPE = 'season_types',
|
||||||
|
|
|
@ -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`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class TransactionSettingModel1745991391299
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'TransactionSettingModel1745991391299';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TABLE "transaction_settings" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "value" numeric NOT NULL DEFAULT '100', CONSTRAINT "PK_db7fb38a439358b499ebdee4761" PRIMARY KEY ("id"))`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`DROP TABLE "transaction_settings"`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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,75 +95,4 @@ export class CouchService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async totalTodayTransactions(database = 'transaction') {
|
|
||||||
try {
|
|
||||||
const nano = this.nanoInstance;
|
|
||||||
const db = nano.use<any>(database);
|
|
||||||
|
|
||||||
// Get today's start timestamp (midnight)
|
|
||||||
const today = new Date();
|
|
||||||
today.setHours(0, 0, 0, 0);
|
|
||||||
const todayTimestamp = today.getTime();
|
|
||||||
|
|
||||||
// Query for documents created today
|
|
||||||
const selector = {
|
|
||||||
created_at: {
|
|
||||||
$gte: todayTimestamp,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await db.find({
|
|
||||||
selector: selector,
|
|
||||||
fields: ['_id', 'payment_total_pay'],
|
|
||||||
limit: 10000,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.docs.reduce(
|
|
||||||
(sum, doc) => sum + (doc.payment_total_pay || 0),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
apm.captureError(error);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getUnixTimestampLast7Days() {
|
|
||||||
const date = new Date();
|
|
||||||
date.setDate(date.getDate() - 4);
|
|
||||||
date.setHours(0, 0, 0, 0);
|
|
||||||
return date.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async clearTransactions() {
|
|
||||||
const nano = this.nanoInstance;
|
|
||||||
const transaction = nano.use('transaction');
|
|
||||||
|
|
||||||
const expiredDate = this.getUnixTimestampLast7Days();
|
|
||||||
|
|
||||||
const selectorPayment = {
|
|
||||||
created_at: {
|
|
||||||
$lt: expiredDate,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const transactions = await transaction.find({
|
|
||||||
selector: selectorPayment,
|
|
||||||
fields: ['_id', '_rev'],
|
|
||||||
limit: 100000,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { docs } = transactions;
|
|
||||||
console.log(docs.length);
|
|
||||||
const deletedDocs = {
|
|
||||||
docs: docs.map((doc) => ({
|
|
||||||
_id: doc._id,
|
|
||||||
_rev: doc._rev,
|
|
||||||
_deleted: true,
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
await transaction.bulk(deletedDocs);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}`)
|
||||||
|
@ -51,7 +44,6 @@ export class ItemQueueReadController {
|
||||||
@Get('display/:id')
|
@Get('display/:id')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
async detailPublic(@Param('id') id: string): Promise<ItemQueueEntity> {
|
||||||
if (!isValidUUID(id)) throw new UnauthorizedException('id is required');
|
|
||||||
return await this.orchestrator.detail(id);
|
return await this.orchestrator.detail(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class ItemModel
|
||||||
@Column('bigint', { name: 'base_price', nullable: true })
|
@Column('bigint', { name: 'base_price', nullable: true })
|
||||||
base_price: number;
|
base_price: number;
|
||||||
|
|
||||||
@Column('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 })
|
||||||
|
|
|
@ -17,7 +17,8 @@ export function phoneNumberOnly(phone: string): string {
|
||||||
export function timeIsBefore(
|
export function timeIsBefore(
|
||||||
currentTime: number,
|
currentTime: number,
|
||||||
time: number,
|
time: number,
|
||||||
diffInMilliseconds: number,
|
diff = 15,
|
||||||
): boolean {
|
): boolean {
|
||||||
|
const diffInMilliseconds = diff * 60 * 1000;
|
||||||
return time < currentTime + diffInMilliseconds;
|
return time < currentTime + diffInMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
} from 'src/core/strings/constants/base.constants';
|
} from 'src/core/strings/constants/base.constants';
|
||||||
import { QueueTimeFormula } from './usecases/formula/queue-time.formula';
|
import { QueueTimeFormula } from './usecases/formula/queue-time.formula';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { timeIsBefore } from './helpers/time.helper';
|
import { timeIsBefore, toTime } from './helpers/time.helper';
|
||||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
||||||
import { WhatsappQueue } from 'src/services/whatsapp/entity/whatsapp-queue.entity';
|
import { WhatsappQueue } from 'src/services/whatsapp/entity/whatsapp-queue.entity';
|
||||||
|
|
||||||
|
@ -63,12 +63,11 @@ export class QueueAdminOrchestrator {
|
||||||
for (const queueId in queueTimes) {
|
for (const queueId in queueTimes) {
|
||||||
const callTime = queueTimes[queueId];
|
const callTime = queueTimes[queueId];
|
||||||
|
|
||||||
const queueTicket = await this.service.queueTicket(queueId);
|
|
||||||
if (
|
if (
|
||||||
queueItem.requiring_notification ||
|
queueItem.requiring_notification ||
|
||||||
(timeIsBefore(currentTime, callTime, call_preparation) &&
|
timeIsBefore(currentTime, callTime, queueItem.call_preparation)
|
||||||
queueTicket.time > currentTime)
|
|
||||||
) {
|
) {
|
||||||
|
const queueTicket = await this.service.queueTicket(queueId);
|
||||||
const payload: WhatsappQueue = {
|
const payload: WhatsappQueue = {
|
||||||
id: queueId,
|
id: queueId,
|
||||||
phone: queueTicket.item.ticket.phone,
|
phone: queueTicket.item.ticket.phone,
|
||||||
|
@ -87,10 +86,7 @@ export class QueueAdminOrchestrator {
|
||||||
// },
|
// },
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
if (
|
if (queueTicket.last_notification < currentTime - call_preparation) {
|
||||||
queueTicket.item.ticket.phone != null &&
|
|
||||||
queueTicket.last_notification < currentTime - call_preparation
|
|
||||||
) {
|
|
||||||
await notification.queueProcess(payload);
|
await notification.queueProcess(payload);
|
||||||
this.service.updateLastNotification(queueId, currentTime);
|
this.service.updateLastNotification(queueId, currentTime);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,8 @@ import * as moment from 'moment';
|
||||||
import { CustomerQueueTicketSummaryManager } from './usecases/queue/customer-queue-ticket.manager';
|
import { CustomerQueueTicketSummaryManager } from './usecases/queue/customer-queue-ticket.manager';
|
||||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
||||||
import { CustomerQueuePosItemManager } from './usecases/queue/customer-queue-pos-item.manager';
|
import { CustomerQueuePosItemManager } from './usecases/queue/customer-queue-pos-item.manager';
|
||||||
import {
|
import { QueueOrderModel, QueueTicketModel } from '../data/models/queue.model';
|
||||||
QueueModel,
|
|
||||||
QueueOrderModel,
|
|
||||||
QueueTicketModel,
|
|
||||||
} from '../data/models/queue.model';
|
|
||||||
import { CustomerQueueRecommendManager } from './usecases/queue/customer-queue-recommend.manager';
|
import { CustomerQueueRecommendManager } from './usecases/queue/customer-queue-recommend.manager';
|
||||||
import { GenerateQueueManager } from './usecases/generate-queue.manager';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class QueueOrchestrator {
|
export class QueueOrchestrator {
|
||||||
|
@ -40,13 +35,8 @@ export class QueueOrchestrator {
|
||||||
private readonly registerQueueManager: RegisterQueueManager,
|
private readonly registerQueueManager: RegisterQueueManager,
|
||||||
private readonly splitQueueManager: SplitQueueManager,
|
private readonly splitQueueManager: SplitQueueManager,
|
||||||
private readonly queueDataService: QueueDataService,
|
private readonly queueDataService: QueueDataService,
|
||||||
private readonly generateQueueManager: GenerateQueueManager,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async generate(data: any): Promise<QueueModel[]> {
|
|
||||||
return await this.generateQueueManager.generate(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
async loginCustomer(id: string): Promise<QueueOrder> {
|
async loginCustomer(id: string): Promise<QueueOrder> {
|
||||||
try {
|
try {
|
||||||
const order = await this.dataService.loginQueue(id);
|
const order = await this.dataService.loginQueue(id);
|
||||||
|
|
|
@ -31,7 +31,7 @@ export class QueueTimeFormula {
|
||||||
|
|
||||||
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
const times = itemQueue.items.map((item) => item.play_estimation ?? 0);
|
||||||
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
const average = times.length > 0 ? math.mean(times) * 60 * 1000 : 0; // change average minute to milliseconds
|
||||||
this.average = Math.floor(average);
|
this.average = average;
|
||||||
|
|
||||||
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
const calledQueue = await this.queueDataService.lastQueue(item_queue_id);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -38,7 +38,7 @@ export class RegisterQueueManager extends BaseCreateManager<QueueModel> {
|
||||||
const first = queues[0];
|
const first = queues[0];
|
||||||
const last = queues[queues.length - 1] ?? moment().valueOf();
|
const last = queues[queues.length - 1] ?? moment().valueOf();
|
||||||
const average = this.queueTimeFormula.average;
|
const average = this.queueTimeFormula.average;
|
||||||
return [Math.floor(first), Math.floor(last + average)];
|
return [first, last + average];
|
||||||
}
|
}
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
|
|
|
@ -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';
|
||||||
|
@ -11,12 +11,6 @@ import { RegisterQueueDto } from './dto/register-queue.dto';
|
||||||
import { SplitQueueDto } from './dto/split-queue.dto';
|
import { SplitQueueDto } from './dto/split-queue.dto';
|
||||||
import { LoginQueueDto } from './dto/login-queue.dto';
|
import { LoginQueueDto } from './dto/login-queue.dto';
|
||||||
import { LoginReceiptDto } from './dto/login-receipt.dto';
|
import { LoginReceiptDto } from './dto/login-receipt.dto';
|
||||||
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
|
||||||
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
|
||||||
import { QueueModel } from '../../data/models/queue.model';
|
|
||||||
|
|
||||||
import * as Gtts from 'gtts';
|
|
||||||
import { Response } from 'express';
|
|
||||||
|
|
||||||
@ApiTags(`Queue`)
|
@ApiTags(`Queue`)
|
||||||
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
@Controller(`v1/${MODULE_NAME.QUEUE}`)
|
||||||
|
@ -25,12 +19,6 @@ 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);
|
||||||
|
@ -108,15 +96,6 @@ export class QueueController {
|
||||||
return await this.orchestrator.queueOrderItems(id);
|
return await this.orchestrator.queueOrderItems(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('speech')
|
|
||||||
async speech(
|
|
||||||
@Query('text') text: string,
|
|
||||||
@Res() response: Response,
|
|
||||||
): Promise<void> {
|
|
||||||
const gtts = new Gtts(text, 'id');
|
|
||||||
gtts.stream().pipe(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/items/:item_id')
|
@Get(':id/items/:item_id')
|
||||||
async queueItemTickets(
|
async queueItemTickets(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|
|
@ -4,7 +4,19 @@ 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';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { TransactionUserType } from 'src/modules/transaction/transaction/constants';
|
||||||
|
import { RegisterQueueManager } from '../../domain/usecases/register-queue.manager';
|
||||||
|
import { RegisterQueueDto } from '../controllers/dto/register-queue.dto';
|
||||||
|
import { QueueService } from '../../data/services/queue.service';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { QueueBucketReadService } from '../../data/services/queue-bucket';
|
||||||
|
import { QueueTimeFormula } from '../../domain/usecases/formula/queue-time.formula';
|
||||||
|
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||||
|
|
||||||
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
@EventsHandler(TransactionChangeStatusEvent, TransactionCreateQueueEvent)
|
||||||
export class QueueTransactionHandler
|
export class QueueTransactionHandler
|
||||||
|
@ -12,7 +24,10 @@ export class QueueTransactionHandler
|
||||||
{
|
{
|
||||||
constructor(
|
constructor(
|
||||||
private readonly dataService: TransactionDataService,
|
private readonly dataService: TransactionDataService,
|
||||||
private readonly queueGenerateManager: GenerateQueueManager,
|
private readonly ticketService: TicketDataService,
|
||||||
|
private readonly queueService: QueueService,
|
||||||
|
private readonly bucketService: QueueBucketReadService,
|
||||||
|
private readonly queueTimeFormula: QueueTimeFormula,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: TransactionChangeStatusEvent) {
|
async handle(event: TransactionChangeStatusEvent) {
|
||||||
|
@ -21,8 +36,7 @@ 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: {
|
||||||
|
@ -36,6 +50,127 @@ export class QueueTransactionHandler
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.queueGenerateManager.generate(transaction);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
transaction.customer_category?.has_vip_pass ||
|
||||||
|
transaction.customer_type === TransactionUserType.VIP
|
||||||
|
) {
|
||||||
|
insertTickets.forEach((ticket) => {
|
||||||
|
const ticket_id = ticket.id;
|
||||||
|
const items = {};
|
||||||
|
ticket.items.forEach((item) => {
|
||||||
|
const item_id = item['item_queue_id'];
|
||||||
|
const currentItem = items[item_id];
|
||||||
|
|
||||||
|
if (currentItem) {
|
||||||
|
currentItem.qty += item.qty;
|
||||||
|
}
|
||||||
|
items[item_id] = currentItem
|
||||||
|
? currentItem
|
||||||
|
: {
|
||||||
|
item_id,
|
||||||
|
ticket_id,
|
||||||
|
qty: item.qty,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(items).forEach((payload: any) => {
|
||||||
|
this.create(payload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
generateItems(items: TransactionItemModel[]): QueueItem[] {
|
||||||
|
const transactionItems = [];
|
||||||
|
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (item.item.use_queue) {
|
||||||
|
transactionItems.push({
|
||||||
|
item_queue_id: item.item.item_queue_id,
|
||||||
|
item_id: item.item_id,
|
||||||
|
qty: item.qty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.item.bundling_items.length > 0) {
|
||||||
|
item.item.bundling_items.forEach((bundling_item) => {
|
||||||
|
if (bundling_item.use_queue) {
|
||||||
|
transactionItems.push({
|
||||||
|
item_queue_id: bundling_item.item_queue_id,
|
||||||
|
item_id: bundling_item.id,
|
||||||
|
qty: item.qty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.mergeQueueItems(transactionItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeQueueItems(arr) {
|
||||||
|
const result = {};
|
||||||
|
arr.forEach((item) => {
|
||||||
|
if (result[item.item_id]) {
|
||||||
|
result[item.item_id].qty += item.qty;
|
||||||
|
} else {
|
||||||
|
result[item.item_id] = { ...item };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Object.values<QueueItem>(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: RegisterQueueDto): Promise<void> {
|
||||||
|
const queue = await this.queueService.getTicketItems(
|
||||||
|
data.ticket_id,
|
||||||
|
data.item_id,
|
||||||
|
);
|
||||||
|
const queueRequest: any = {
|
||||||
|
qty: data.qty,
|
||||||
|
item_id: queue.id,
|
||||||
|
vip: true,
|
||||||
|
};
|
||||||
|
const registerQueueManager = new RegisterQueueManager(
|
||||||
|
this.bucketService,
|
||||||
|
this.queueTimeFormula,
|
||||||
|
);
|
||||||
|
registerQueueManager.setData(queueRequest);
|
||||||
|
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||||
|
await registerQueueManager.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import { QueueTransactionCancelHandler } from './infrastructure/handlers/cancel-
|
||||||
import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queue.model';
|
||||||
import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||||
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
||||||
import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -80,7 +79,6 @@ import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
||||||
SplitQueueManager,
|
SplitQueueManager,
|
||||||
|
|
||||||
QueueTimeFormula,
|
QueueTimeFormula,
|
||||||
GenerateQueueManager,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class QueueModule {}
|
export class QueueModule {}
|
||||||
|
|
|
@ -42,16 +42,9 @@ export default <ReportConfigEntity>{
|
||||||
},
|
},
|
||||||
|
|
||||||
column_configs: [
|
column_configs: [
|
||||||
// {
|
|
||||||
// column: 'main__payment_date',
|
|
||||||
// query: `to_char(main.payment_date, 'DD-MM-YYYY')`,
|
|
||||||
// label: 'Tgl. Pendapatan',
|
|
||||||
// type: DATA_TYPE.DIMENSION,
|
|
||||||
// format: DATA_FORMAT.TEXT,
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
column: 'main__payment_date',
|
column: 'main__payment_date',
|
||||||
query: `to_char(cast(to_timestamp(main.created_at/1000) as date),'DD-MM-YYYY')`,
|
query: `to_char(main.payment_date, 'DD-MM-YYYY')`,
|
||||||
label: 'Tgl. Pendapatan',
|
label: 'Tgl. Pendapatan',
|
||||||
type: DATA_TYPE.DIMENSION,
|
type: DATA_TYPE.DIMENSION,
|
||||||
format: DATA_FORMAT.TEXT,
|
format: DATA_FORMAT.TEXT,
|
||||||
|
@ -289,22 +282,15 @@ export default <ReportConfigEntity>{
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
filter_configs: [
|
filter_configs: [
|
||||||
// {
|
|
||||||
// filed_label: 'Tgl. Pembatalan',
|
|
||||||
// filter_column: 'main__payment_date',
|
|
||||||
// field_type: FILTER_FIELD_TYPE.date_range_picker,
|
|
||||||
// filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
|
|
||||||
// // date_format: 'DD-MM-YYYY',
|
|
||||||
// date_format: 'YYYY-MM-DD',
|
|
||||||
// },
|
|
||||||
|
|
||||||
{
|
{
|
||||||
filed_label: 'Tgl. Pembatalan',
|
filed_label: 'Tgl. Pembatalan',
|
||||||
filter_column: 'main__payment_date',
|
filter_column: 'main__payment_date',
|
||||||
field_type: FILTER_FIELD_TYPE.date_range_picker,
|
field_type: FILTER_FIELD_TYPE.date_range_picker,
|
||||||
filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
|
filter_type: FILTER_TYPE.DATE_IN_RANGE_TIMESTAMP,
|
||||||
date_format: 'DD-MM-YYYY',
|
// date_format: 'DD-MM-YYYY',
|
||||||
|
date_format: 'YYYY-MM-DD',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
filed_label: 'Sumber',
|
filed_label: 'Sumber',
|
||||||
filter_column: 'main__type',
|
filter_column: 'main__type',
|
||||||
|
@ -406,9 +392,8 @@ export default <ReportConfigEntity>{
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
customQueryColumn(column) {
|
customQueryColumn(column) {
|
||||||
// if (column === 'main__payment_date') return 'main.payment_date';
|
if (column === 'main__payment_date') return 'main.payment_date';
|
||||||
// else if (column === 'refund__refund_date') return 'refund.refund_date';
|
else if (column === 'refund__refund_date') return 'refund.refund_date';
|
||||||
if (column === 'refund__refund_date') return 'refund.refund_date';
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -255,14 +255,7 @@ export default <ReportConfigEntity>{
|
||||||
{
|
{
|
||||||
column: 'main__payment_card_information',
|
column: 'main__payment_card_information',
|
||||||
query: 'main.payment_card_information',
|
query: 'main.payment_card_information',
|
||||||
label: 'Card Information',
|
label: 'Information',
|
||||||
type: DATA_TYPE.DIMENSION,
|
|
||||||
format: DATA_FORMAT.TEXT,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
column: 'main__payment_code_reference',
|
|
||||||
query: 'main.payment_code_reference',
|
|
||||||
label: 'Payment Reference',
|
|
||||||
type: DATA_TYPE.DIMENSION,
|
type: DATA_TYPE.DIMENSION,
|
||||||
format: DATA_FORMAT.TEXT,
|
format: DATA_FORMAT.TEXT,
|
||||||
},
|
},
|
||||||
|
@ -341,18 +334,6 @@ export default <ReportConfigEntity>{
|
||||||
field_type: FILTER_FIELD_TYPE.input_tag,
|
field_type: FILTER_FIELD_TYPE.input_tag,
|
||||||
filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
|
filter_type: FILTER_TYPE.TEXT_MULTIPLE_CONTAINS,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
filed_label: 'Card Information',
|
|
||||||
filter_column: 'main__payment_card_information',
|
|
||||||
field_type: FILTER_FIELD_TYPE.input_tag,
|
|
||||||
filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
filed_label: 'Payment Reference',
|
|
||||||
filter_column: 'main__payment_code_reference',
|
|
||||||
field_type: FILTER_FIELD_TYPE.input_tag,
|
|
||||||
filter_type: FILTER_TYPE.TEXT_IN_MEMBER,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
filed_label: 'Tgl. Pengembalian',
|
filed_label: 'Tgl. Pengembalian',
|
||||||
filter_column: 'refund__refund_date',
|
filter_column: 'refund__refund_date',
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import {
|
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||||
SalesPriceFormulaEntity,
|
|
||||||
TransactionSetting,
|
|
||||||
} from '../../domain/entities/sales-price-formula.entity';
|
|
||||||
import { Column, Entity } from 'typeorm';
|
import { Column, Entity } from 'typeorm';
|
||||||
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
||||||
import { FormulaType } from '../../constants';
|
import { FormulaType } from '../../constants';
|
||||||
|
@ -34,12 +31,3 @@ export class SalesPriceFormulaModel
|
||||||
@Column('numeric', { name: 'example_result', nullable: true })
|
@Column('numeric', { name: 'example_result', nullable: true })
|
||||||
example_result: number;
|
example_result: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(TABLE_NAME.TRANSACTION_SETTING)
|
|
||||||
export class TransactionSettingModel
|
|
||||||
extends BaseModel<TransactionSetting>
|
|
||||||
implements TransactionSetting
|
|
||||||
{
|
|
||||||
@Column('numeric', { default: 100 })
|
|
||||||
value: number;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,26 +1,13 @@
|
||||||
import {
|
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||||
Injectable,
|
|
||||||
Logger,
|
|
||||||
UnprocessableEntityException,
|
|
||||||
} 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 {
|
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||||
SalesPriceFormulaEntity,
|
|
||||||
TransactionSetting,
|
|
||||||
} from '../../domain/entities/sales-price-formula.entity';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import {
|
import { SalesPriceFormulaModel } from '../models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from '../models/sales-price-formula.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';
|
||||||
import { FormulaType } from '../../constants';
|
import { FormulaType } from '../../constants';
|
||||||
import { TaxModel } from 'src/modules/transaction/tax/data/models/tax.model';
|
import { TaxModel } from 'src/modules/transaction/tax/data/models/tax.model';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
|
||||||
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
|
||||||
import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceFormulaEntity> {
|
export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceFormulaEntity> {
|
||||||
|
@ -31,11 +18,6 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
||||||
private tax: Repository<TaxModel>,
|
private tax: Repository<TaxModel>,
|
||||||
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
||||||
private item: Repository<ItemModel>,
|
private item: Repository<ItemModel>,
|
||||||
@InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private transactionSetting: Repository<TransactionSettingModel>,
|
|
||||||
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private transaction: Repository<TransactionModel>,
|
|
||||||
private couchService: CouchService,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
@ -48,47 +30,6 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async sentToBlackHole() {
|
|
||||||
const transactionSettingData = await this.transactionSetting.findOne({
|
|
||||||
where: {},
|
|
||||||
});
|
|
||||||
const percentage = transactionSettingData?.value ?? 100;
|
|
||||||
|
|
||||||
// const transactionPercentage = Math.floor(Math.random() * 100) + 1;
|
|
||||||
const transactionPercentage = await this.dataSaveFactor();
|
|
||||||
|
|
||||||
Logger.log(`Factor ${transactionPercentage} from ${percentage}`);
|
|
||||||
|
|
||||||
return transactionPercentage > percentage;
|
|
||||||
}
|
|
||||||
|
|
||||||
async dataSaveFactor() {
|
|
||||||
const today = new Date();
|
|
||||||
today.setHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
const todayTimestamp = today.getTime();
|
|
||||||
|
|
||||||
const totalTransactions = parseInt(
|
|
||||||
await this.transaction
|
|
||||||
.createQueryBuilder('transaction')
|
|
||||||
.select('SUM(transaction.payment_total_pay)', 'sum')
|
|
||||||
.where('transaction.created_at > :timestamp', {
|
|
||||||
timestamp: todayTimestamp,
|
|
||||||
})
|
|
||||||
.andWhere('transaction.type = :type', { type: TransactionType.COUNTER })
|
|
||||||
.getRawOne()
|
|
||||||
.then((result) => result.sum || 0),
|
|
||||||
);
|
|
||||||
|
|
||||||
const couchTransaction = await this.couchService.totalTodayTransactions();
|
|
||||||
|
|
||||||
if (couchTransaction == 0) return 0;
|
|
||||||
|
|
||||||
const factor = (totalTransactions / couchTransaction) * 100;
|
|
||||||
|
|
||||||
return factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
async itemTax(id: string) {
|
async itemTax(id: string) {
|
||||||
const item = await this.item.findOne({
|
const item = await this.item.findOne({
|
||||||
relations: ['tenant'],
|
relations: ['tenant'],
|
||||||
|
@ -149,13 +90,3 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
||||||
return salesFormula;
|
return salesFormula;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class TransactionSettingDataService extends BaseDataService<TransactionSetting> {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private repo: Repository<TransactionSettingModel>,
|
|
||||||
) {
|
|
||||||
super(repo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import {
|
import { SalesPriceFormulaModel } from '../models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from '../models/sales-price-formula.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';
|
||||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||||
|
@ -14,25 +11,7 @@ export class SalesPriceFormulaReadService extends BaseReadService<SalesPriceForm
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(SalesPriceFormulaModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(SalesPriceFormulaModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<SalesPriceFormulaModel>,
|
private repo: Repository<SalesPriceFormulaModel>,
|
||||||
|
|
||||||
@InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
|
|
||||||
private transactionSetting: Repository<TransactionSettingModel>,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionSetting(): Promise<any> {
|
|
||||||
try {
|
|
||||||
const data = await this.transactionSetting.findOne({
|
|
||||||
where: {},
|
|
||||||
order: {
|
|
||||||
created_at: 'DESC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { BaseEntity } from 'src/core/modules/domain/entities/base.entity';
|
import { BaseEntity } from 'src/core/modules/domain/entities/base.entity';
|
||||||
import { FormulaType } from '../../constants';
|
import { FormulaType } from '../../constants';
|
||||||
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
|
||||||
|
|
||||||
export interface SalesPriceFormulaEntity extends BaseEntity {
|
export interface SalesPriceFormulaEntity extends BaseEntity {
|
||||||
formula_render: any; // json type
|
formula_render: any; // json type
|
||||||
|
@ -17,7 +16,3 @@ export interface AdditionalFormula {
|
||||||
formula_string: string;
|
formula_string: string;
|
||||||
value_for: string;
|
value_for: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionSetting extends BaseCoreEntity {
|
|
||||||
value: number;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { BaseUpdateManager } from 'src/core/modules/domain/usecase/managers/base-update.manager';
|
|
||||||
import { TransactionSetting } from '../../entities/sales-price-formula.entity';
|
|
||||||
import { TransactionSettingModel } from '../../../data/models/sales-price-formula.model';
|
|
||||||
import {
|
|
||||||
EventTopics,
|
|
||||||
columnUniques,
|
|
||||||
validateRelations,
|
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class UpdateTransactionSettingManager extends BaseUpdateManager<TransactionSetting> {
|
|
||||||
async validateProcess(): Promise<void> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get uniqueColumns(): columnUniques[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get entityTarget(): any {
|
|
||||||
return TransactionSettingModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
get eventTopics(): EventTopics[] {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +1,10 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import {
|
import { SalesPriceFormulaDataService } from '../../data/services/sales-price-formula-data.service';
|
||||||
SalesPriceFormulaDataService,
|
import { SalesPriceFormulaEntity } from '../entities/sales-price-formula.entity';
|
||||||
TransactionSettingDataService,
|
|
||||||
} from '../../data/services/sales-price-formula-data.service';
|
|
||||||
import {
|
|
||||||
SalesPriceFormulaEntity,
|
|
||||||
TransactionSetting,
|
|
||||||
} from '../entities/sales-price-formula.entity';
|
|
||||||
import { UpdateSalesPriceFormulaManager } from './managers/update-sales-price-formula.manager';
|
import { UpdateSalesPriceFormulaManager } from './managers/update-sales-price-formula.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { FormulaType } from '../../constants';
|
import { FormulaType } from '../../constants';
|
||||||
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
|
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
|
||||||
import { UpdateTransactionSettingManager } from './managers/update-transaction-setting.manager';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesPriceFormulaDataOrchestrator {
|
export class SalesPriceFormulaDataOrchestrator {
|
||||||
|
@ -19,8 +12,6 @@ export class SalesPriceFormulaDataOrchestrator {
|
||||||
private updateManager: UpdateSalesPriceFormulaManager,
|
private updateManager: UpdateSalesPriceFormulaManager,
|
||||||
private serviceData: SalesPriceFormulaDataService,
|
private serviceData: SalesPriceFormulaDataService,
|
||||||
private taxService: TaxDataService,
|
private taxService: TaxDataService,
|
||||||
private transactionSettingService: TransactionSettingDataService,
|
|
||||||
private transactionSettingManager: UpdateTransactionSettingManager,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async update(data): Promise<SalesPriceFormulaEntity> {
|
async update(data): Promise<SalesPriceFormulaEntity> {
|
||||||
|
@ -39,14 +30,4 @@ export class SalesPriceFormulaDataOrchestrator {
|
||||||
await this.updateManager.execute();
|
await this.updateManager.execute();
|
||||||
return this.updateManager.getResult();
|
return this.updateManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateTransactionSetting(data): Promise<TransactionSetting> {
|
|
||||||
this.transactionSettingManager.setData(data.id, data);
|
|
||||||
this.transactionSettingManager.setService(
|
|
||||||
this.transactionSettingService,
|
|
||||||
TABLE_NAME.TRANSACTION_SETTING,
|
|
||||||
);
|
|
||||||
await this.transactionSettingManager.execute();
|
|
||||||
return this.transactionSettingManager.getResult();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,4 @@ export class SalesPriceFormulaReadOrchestrator {
|
||||||
await this.detailManager.execute();
|
await this.detailManager.execute();
|
||||||
return this.detailManager.getResult();
|
return this.detailManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionSetting(): Promise<any> {
|
|
||||||
try {
|
|
||||||
return await this.serviceData.getTransactionSetting();
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';
|
||||||
import {
|
import {
|
||||||
AdditionalFormula,
|
AdditionalFormula,
|
||||||
SalesPriceFormulaEntity,
|
SalesPriceFormulaEntity,
|
||||||
TransactionSetting,
|
|
||||||
} from '../../domain/entities/sales-price-formula.entity';
|
} from '../../domain/entities/sales-price-formula.entity';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { ValidateIf, ValidateNested } from 'class-validator';
|
import { ValidateIf, ValidateNested } from 'class-validator';
|
||||||
|
@ -33,21 +32,6 @@ export class AdditionalFormulaDto implements AdditionalFormula {
|
||||||
value_for: string;
|
value_for: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TransactionSettingDto implements TransactionSetting {
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
@ValidateIf((body) => body.id)
|
|
||||||
id?: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Number,
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
value: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SalesPriceFormulaDto
|
export class SalesPriceFormulaDto
|
||||||
extends BaseDto
|
extends BaseDto
|
||||||
implements SalesPriceFormulaEntity
|
implements SalesPriceFormulaEntity
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
import { Body, Controller, Post, Put } from '@nestjs/common';
|
import { Body, Controller, Post } from '@nestjs/common';
|
||||||
import { SalesPriceFormulaDataOrchestrator } from '../domain/usecases/sales-price-formula-data.orchestrator';
|
import { SalesPriceFormulaDataOrchestrator } from '../domain/usecases/sales-price-formula-data.orchestrator';
|
||||||
import {
|
import { SalesPriceFormulaDto } from './dto/sales-price-formula.dto';
|
||||||
SalesPriceFormulaDto,
|
|
||||||
TransactionSettingDto,
|
|
||||||
} from './dto/sales-price-formula.dto';
|
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import {
|
import { SalesPriceFormulaEntity } from '../domain/entities/sales-price-formula.entity';
|
||||||
SalesPriceFormulaEntity,
|
|
||||||
TransactionSetting,
|
|
||||||
} from '../domain/entities/sales-price-formula.entity';
|
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
@ApiTags(`sales price formulas - data`)
|
@ApiTags(`sales price formulas - data`)
|
||||||
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
@Controller('v1/sales-price-formula')
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class SalesPriceFormulaDataController {
|
export class SalesPriceFormulaDataController {
|
||||||
|
@ -24,12 +18,4 @@ export class SalesPriceFormulaDataController {
|
||||||
): Promise<SalesPriceFormulaEntity> {
|
): Promise<SalesPriceFormulaEntity> {
|
||||||
return await this.orchestrator.update(data);
|
return await this.orchestrator.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public(true)
|
|
||||||
@Put()
|
|
||||||
async updateTransactionSetting(
|
|
||||||
@Body() data: TransactionSettingDto,
|
|
||||||
): Promise<TransactionSetting> {
|
|
||||||
return await this.orchestrator.updateTransactionSetting(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
@ApiTags(`sales price formulas - read`)
|
@ApiTags(`sales price formulas - read`)
|
||||||
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
@Controller('v1/sales-price-formula')
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class SalesPriceFormulaReadController {
|
export class SalesPriceFormulaReadController {
|
||||||
|
@ -15,10 +15,4 @@ export class SalesPriceFormulaReadController {
|
||||||
async detail(): Promise<SalesPriceFormulaEntity> {
|
async detail(): Promise<SalesPriceFormulaEntity> {
|
||||||
return await this.orchestrator.detail();
|
return await this.orchestrator.detail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public(true)
|
|
||||||
@Get('detail')
|
|
||||||
async getTransactionSetting(): Promise<any> {
|
|
||||||
return await this.orchestrator.getTransactionSetting();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,7 @@ import { Global, Module } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
import {
|
import { SalesPriceFormulaDataService } from './data/services/sales-price-formula-data.service';
|
||||||
SalesPriceFormulaDataService,
|
|
||||||
TransactionSettingDataService,
|
|
||||||
} from './data/services/sales-price-formula-data.service';
|
|
||||||
import { SalesPriceFormulaReadService } from './data/services/sales-price-formula-read.service';
|
import { SalesPriceFormulaReadService } from './data/services/sales-price-formula-read.service';
|
||||||
import { SalesPriceFormulaReadController } from './infrastructure/sales-price-formula-read.controller';
|
import { SalesPriceFormulaReadController } from './infrastructure/sales-price-formula-read.controller';
|
||||||
import { SalesPriceFormulaReadOrchestrator } from './domain/usecases/sales-price-formula-read.orchestrator';
|
import { SalesPriceFormulaReadOrchestrator } from './domain/usecases/sales-price-formula-read.orchestrator';
|
||||||
|
@ -14,33 +11,20 @@ import { SalesPriceFormulaDataOrchestrator } from './domain/usecases/sales-price
|
||||||
import { CqrsModule } from '@nestjs/cqrs';
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
import { UpdateSalesPriceFormulaManager } from './domain/usecases/managers/update-sales-price-formula.manager';
|
import { UpdateSalesPriceFormulaManager } from './domain/usecases/managers/update-sales-price-formula.manager';
|
||||||
import { DetailSalesPriceFormulaManager } from './domain/usecases/managers/detail-sales-price-formula.manager';
|
import { DetailSalesPriceFormulaManager } from './domain/usecases/managers/detail-sales-price-formula.manager';
|
||||||
import {
|
import { SalesPriceFormulaModel } from './data/models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from './data/models/sales-price-formula.model';
|
|
||||||
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
||||||
import { TaxModel } from '../tax/data/models/tax.model';
|
import { TaxModel } from '../tax/data/models/tax.model';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
import { UpdateTransactionSettingManager } from './domain/usecases/managers/update-transaction-setting.manager';
|
|
||||||
import { TransactionModel } from '../transaction/data/models/transaction.model';
|
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[
|
[SalesPriceFormulaModel, TaxModel, ItemModel],
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
TransactionModel,
|
|
||||||
TaxModel,
|
|
||||||
ItemModel,
|
|
||||||
],
|
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
SalesPriceFormulaDataController,
|
SalesPriceFormulaDataController,
|
||||||
|
@ -49,12 +33,10 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
providers: [
|
providers: [
|
||||||
DetailSalesPriceFormulaManager,
|
DetailSalesPriceFormulaManager,
|
||||||
UpdateSalesPriceFormulaManager,
|
UpdateSalesPriceFormulaManager,
|
||||||
UpdateTransactionSettingManager,
|
|
||||||
|
|
||||||
TaxDataService,
|
TaxDataService,
|
||||||
SalesPriceFormulaDataService,
|
SalesPriceFormulaDataService,
|
||||||
SalesPriceFormulaReadService,
|
SalesPriceFormulaReadService,
|
||||||
TransactionSettingDataService,
|
|
||||||
|
|
||||||
SalesPriceFormulaDataOrchestrator,
|
SalesPriceFormulaDataOrchestrator,
|
||||||
SalesPriceFormulaReadOrchestrator,
|
SalesPriceFormulaReadOrchestrator,
|
||||||
|
|
|
@ -23,17 +23,14 @@ import { BatchConfirmTaxManager } from './domain/usecases/managers/batch-confirm
|
||||||
import { BatchInactiveTaxManager } from './domain/usecases/managers/batch-inactive-tax.manager';
|
import { BatchInactiveTaxManager } from './domain/usecases/managers/batch-inactive-tax.manager';
|
||||||
import { TaxModel } from './data/models/tax.model';
|
import { TaxModel } from './data/models/tax.model';
|
||||||
import { SalesPriceFormulaReadService } from '../sales-price-formula/data/services/sales-price-formula-read.service';
|
import { SalesPriceFormulaReadService } from '../sales-price-formula/data/services/sales-price-formula-read.service';
|
||||||
import {
|
import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from '../sales-price-formula/data/models/sales-price-formula.model';
|
|
||||||
import { IndexTaxFormulaManager } from './domain/usecases/managers/index-tax-formula.manager';
|
import { IndexTaxFormulaManager } from './domain/usecases/managers/index-tax-formula.manager';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[TaxModel, SalesPriceFormulaModel, TransactionSettingModel],
|
[TaxModel, SalesPriceFormulaModel],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
|
|
@ -31,9 +31,6 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(event: ChangeDocEvent) {
|
async handle(event: ChangeDocEvent) {
|
||||||
const envSkipTransaction = process.env.SKIP_TRANSACTION_FEATURE ?? 'false';
|
|
||||||
const activeSkipTransaction = envSkipTransaction == 'true';
|
|
||||||
|
|
||||||
const apmTransactions = apm.startTransaction(
|
const apmTransactions = apm.startTransaction(
|
||||||
`ChangeDocEvent ${event?.data?.database}`,
|
`ChangeDocEvent ${event?.data?.database}`,
|
||||||
'handler',
|
'handler',
|
||||||
|
@ -107,17 +104,7 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
apmTransactions.setLabel('Code', data?.code);
|
apmTransactions.setLabel('Code', data?.code);
|
||||||
apmTransactions.setLabel('Status', data?.status);
|
apmTransactions.setLabel('Status', data?.status);
|
||||||
|
|
||||||
// Check if this transaction should be sent to the "black hole" (not saved)
|
await this.dataService.create(queryRunner, TransactionModel, data);
|
||||||
// This is only applicable for SETTLED transactions
|
|
||||||
const shouldSkipSaving =
|
|
||||||
activeSkipTransaction &&
|
|
||||||
data.status === STATUS.SETTLED &&
|
|
||||||
(await this.formulaService.sentToBlackHole());
|
|
||||||
|
|
||||||
// If we shouldn't skip saving, then save the transaction
|
|
||||||
if (!shouldSkipSaving) {
|
|
||||||
await this.dataService.create(queryRunner, TransactionModel, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When transaction is cancel, set booking to Pending
|
* When transaction is cancel, set booking to Pending
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -32,10 +32,7 @@ import { BatchConfirmDataTransactionManager } from './domain/usecases/managers/b
|
||||||
import { PosTransactionHandler } from './domain/usecases/handlers/pos-transaction.handler';
|
import { PosTransactionHandler } from './domain/usecases/handlers/pos-transaction.handler';
|
||||||
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
||||||
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
|
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
|
||||||
import {
|
import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
} from '../sales-price-formula/data/models/sales-price-formula.model';
|
|
||||||
import { TaxModel } from '../tax/data/models/tax.model';
|
import { TaxModel } from '../tax/data/models/tax.model';
|
||||||
import { SettledTransactionHandler } from './domain/usecases/handlers/settled-transaction.handler';
|
import { SettledTransactionHandler } from './domain/usecases/handlers/settled-transaction.handler';
|
||||||
import { RefundUpdatedHandler } from './domain/usecases/handlers/refund-update.handler';
|
import { RefundUpdatedHandler } from './domain/usecases/handlers/refund-update.handler';
|
||||||
|
@ -46,7 +43,6 @@ import { PaymentMethodModel } from '../payment-method/data/models/payment-method
|
||||||
import { TransactionDemographyModel } from './data/models/transaction-demography.model';
|
import { TransactionDemographyModel } from './data/models/transaction-demography.model';
|
||||||
import { PriceCalculator } from './domain/usecases/calculator/price.calculator';
|
import { PriceCalculator } from './domain/usecases/calculator/price.calculator';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
exports: [TransactionReadService],
|
exports: [TransactionReadService],
|
||||||
|
@ -61,7 +57,6 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
TransactionItemTaxModel,
|
TransactionItemTaxModel,
|
||||||
TransactionBreakdownTaxModel,
|
TransactionBreakdownTaxModel,
|
||||||
TransactionSettingModel,
|
|
||||||
TaxModel,
|
TaxModel,
|
||||||
SalesPriceFormulaModel,
|
SalesPriceFormulaModel,
|
||||||
PaymentMethodModel,
|
PaymentMethodModel,
|
||||||
|
@ -70,7 +65,6 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [TransactionDataController, TransactionReadController],
|
controllers: [TransactionDataController, TransactionReadController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
} from './whatsapp.constant';
|
} from './whatsapp.constant';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { apm } from 'src/core/apm';
|
|
||||||
|
|
||||||
export class WhatsappService {
|
export class WhatsappService {
|
||||||
async sendMessage(data) {
|
async sendMessage(data) {
|
||||||
|
@ -26,14 +25,8 @@ export class WhatsappService {
|
||||||
data: data,
|
data: data,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const response = await axios(config);
|
||||||
const response = await axios(config);
|
return response.data;
|
||||||
return response.data;
|
|
||||||
} catch (error) {
|
|
||||||
Logger.error(error);
|
|
||||||
apm?.captureError(error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueRegister(data: WhatsappQueue) {
|
async queueRegister(data: WhatsappQueue) {
|
||||||
|
@ -98,11 +91,8 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
await this.sendMessage(payload);
|
||||||
if (response)
|
Logger.log(`Notification register for ${data.code} send to ${data.phone}`);
|
||||||
Logger.log(
|
|
||||||
`Notification register for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async queueProcess(data: WhatsappQueue) {
|
async queueProcess(data: WhatsappQueue) {
|
||||||
|
@ -162,8 +152,7 @@ export class WhatsappService {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
await this.sendMessage(payload);
|
||||||
if (response)
|
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||||
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue