Compare commits
26 Commits
1.4.4-prod
...
production
Author | SHA1 | Date |
---|---|---|
|
2201071c68 | |
|
027025935c | |
|
10cd1a711e | |
|
bad4b2ea56 | |
|
35919b91f7 | |
|
8afbe33c01 | |
|
f2d7ea80d2 | |
|
b18a834129 | |
|
928e2e7648 | |
|
9b1f945873 | |
|
6882314a9e | |
|
94baf956dd | |
|
e92f325807 | |
|
66d76634b7 | |
|
b91080906e | |
|
714b075e1d | |
|
da024606ff | |
|
0b482be669 | |
|
064112e731 | |
|
05473fce3d | |
|
d6a238a224 | |
|
a8b3f67d1b | |
|
dc5e938f75 | |
|
eb4da7ccc4 | |
|
bef9f99f13 | |
|
46caaba6bd |
|
@ -33,7 +33,10 @@ import { SeasonTypeModel } from './modules/season-related/season-type/data/model
|
|||
import { TaxModule } from './modules/transaction/tax/tax.module';
|
||||
import { TaxModel } from './modules/transaction/tax/data/models/tax.model';
|
||||
import { SalesPriceFormulaModule } from './modules/transaction/sales-price-formula/sales-price-formula.module';
|
||||
import { SalesPriceFormulaModel } from './modules/transaction/sales-price-formula/data/models/sales-price-formula.model';
|
||||
import {
|
||||
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 { PaymentMethodModule } from './modules/transaction/payment-method/payment-method.module';
|
||||
import { PaymentMethodModel } from './modules/transaction/payment-method/data/models/payment-method.model';
|
||||
|
@ -137,6 +140,7 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
|||
TransactionItemBreakdownModel,
|
||||
TransactionItemTaxModel,
|
||||
TransactionBreakdownTaxModel,
|
||||
TransactionSettingModel,
|
||||
UserModel,
|
||||
UserLoginModel,
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ export enum TABLE_NAME {
|
|||
NEWS = 'news',
|
||||
PAYMENT_METHOD = 'payment_methods',
|
||||
PRICE_FORMULA = 'price_formulas',
|
||||
TRANSACTION_SETTING = 'transaction_settings',
|
||||
REFUND = 'refunds',
|
||||
REFUND_ITEM = 'refund_items',
|
||||
SEASON_TYPE = 'season_types',
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
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,13 +73,14 @@ export class LoginAdminQueueManager extends BaseCustomManager<UserEntity> {
|
|||
message: `Akun anda sudah login di item "${hasLoginAsQueue?.item_name}"`,
|
||||
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
|
||||
const tokenData = {
|
||||
|
|
|
@ -19,6 +19,7 @@ export class CouchService {
|
|||
}
|
||||
|
||||
async onModuleInit() {
|
||||
// return;
|
||||
const nano = this.nanoInstance;
|
||||
for (const database of DatabaseListen) {
|
||||
const db = nano.db.use(database);
|
||||
|
@ -95,4 +96,75 @@ export class CouchService {
|
|||
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,13 +5,17 @@ import { Public } from 'src/core/guards';
|
|||
import * as Nano from 'nano';
|
||||
import { CreateUserPrivilegeDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/create-user-privilege.dto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { CouchService } from '../data/services/couch.service';
|
||||
|
||||
@ApiTags(`couch`)
|
||||
@Controller('v1/couch')
|
||||
@Public()
|
||||
@Injectable()
|
||||
export class CouchDataController {
|
||||
constructor(private configService: ConfigService) {}
|
||||
constructor(
|
||||
private configService: ConfigService,
|
||||
private couchService: CouchService,
|
||||
) {}
|
||||
|
||||
get nanoInstance() {
|
||||
const couchConfiguration = this.configService.get<string>('COUCHDB_CONFIG');
|
||||
|
@ -64,4 +68,11 @@ export class CouchDataController {
|
|||
// return people.get();
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
@Public(true)
|
||||
@Get('clear-transactions')
|
||||
async clearTransactions(): Promise<string> {
|
||||
await this.couchService.clearTransactions();
|
||||
return 'OK';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,9 @@ export class GenerateQueueManager {
|
|||
registerQueueManager.setService(this.queueService, TABLE_NAME.QUEUE);
|
||||
await registerQueueManager.execute();
|
||||
|
||||
return registerQueueManager.getResult();
|
||||
const result = await registerQueueManager.getResult();
|
||||
result.time = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,16 @@ export default <ReportConfigEntity>{
|
|||
},
|
||||
|
||||
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',
|
||||
query: `to_char(main.payment_date, 'DD-MM-YYYY')`,
|
||||
query: `to_char(cast(to_timestamp(main.created_at/1000) as date),'DD-MM-YYYY')`,
|
||||
label: 'Tgl. Pendapatan',
|
||||
type: DATA_TYPE.DIMENSION,
|
||||
format: DATA_FORMAT.TEXT,
|
||||
|
@ -282,15 +289,22 @@ export default <ReportConfigEntity>{
|
|||
},
|
||||
],
|
||||
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',
|
||||
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',
|
||||
date_format: 'DD-MM-YYYY',
|
||||
},
|
||||
|
||||
{
|
||||
filed_label: 'Sumber',
|
||||
filter_column: 'main__type',
|
||||
|
@ -392,8 +406,9 @@ export default <ReportConfigEntity>{
|
|||
},
|
||||
],
|
||||
customQueryColumn(column) {
|
||||
if (column === 'main__payment_date') return 'main.payment_date';
|
||||
else if (column === 'refund__refund_date') return 'refund.refund_date';
|
||||
// if (column === 'main__payment_date') return 'main.payment_date';
|
||||
// else if (column === 'refund__refund_date') return 'refund.refund_date';
|
||||
if (column === 'refund__refund_date') return 'refund.refund_date';
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -255,7 +255,14 @@ export default <ReportConfigEntity>{
|
|||
{
|
||||
column: 'main__payment_card_information',
|
||||
query: 'main.payment_card_information',
|
||||
label: 'Information',
|
||||
label: 'Card 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,
|
||||
format: DATA_FORMAT.TEXT,
|
||||
},
|
||||
|
@ -334,6 +341,18 @@ export default <ReportConfigEntity>{
|
|||
field_type: FILTER_FIELD_TYPE.input_tag,
|
||||
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',
|
||||
filter_column: 'refund__refund_date',
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||
import {
|
||||
SalesPriceFormulaEntity,
|
||||
TransactionSetting,
|
||||
} from '../../domain/entities/sales-price-formula.entity';
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { BaseModel } from 'src/core/modules/data/model/base.model';
|
||||
import { FormulaType } from '../../constants';
|
||||
|
@ -31,3 +34,12 @@ export class SalesPriceFormulaModel
|
|||
@Column('numeric', { name: 'example_result', nullable: true })
|
||||
example_result: number;
|
||||
}
|
||||
|
||||
@Entity(TABLE_NAME.TRANSACTION_SETTING)
|
||||
export class TransactionSettingModel
|
||||
extends BaseModel<TransactionSetting>
|
||||
implements TransactionSetting
|
||||
{
|
||||
@Column('numeric', { default: 100 })
|
||||
value: number;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||
import {
|
||||
Injectable,
|
||||
Logger,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { BaseDataService } from 'src/core/modules/data/service/base-data.service';
|
||||
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||
import {
|
||||
SalesPriceFormulaEntity,
|
||||
TransactionSetting,
|
||||
} from '../../domain/entities/sales-price-formula.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { SalesPriceFormulaModel } from '../models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from '../models/sales-price-formula.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { FormulaType } from '../../constants';
|
||||
import { TaxModel } from 'src/modules/transaction/tax/data/models/tax.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()
|
||||
export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceFormulaEntity> {
|
||||
|
@ -18,6 +31,11 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
|||
private tax: Repository<TaxModel>,
|
||||
@InjectRepository(ItemModel, CONNECTION_NAME.DEFAULT)
|
||||
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);
|
||||
}
|
||||
|
@ -30,6 +48,47 @@ 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) {
|
||||
const item = await this.item.findOne({
|
||||
relations: ['tenant'],
|
||||
|
@ -90,3 +149,13 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
|||
return salesFormula;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TransactionSettingDataService extends BaseDataService<TransactionSetting> {
|
||||
constructor(
|
||||
@InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<TransactionSettingModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { SalesPriceFormulaEntity } from '../../domain/entities/sales-price-formula.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { SalesPriceFormulaModel } from '../models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from '../models/sales-price-formula.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { BaseReadService } from 'src/core/modules/data/service/base-read.service';
|
||||
|
@ -11,7 +14,25 @@ export class SalesPriceFormulaReadService extends BaseReadService<SalesPriceForm
|
|||
constructor(
|
||||
@InjectRepository(SalesPriceFormulaModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<SalesPriceFormulaModel>,
|
||||
|
||||
@InjectRepository(TransactionSettingModel, CONNECTION_NAME.DEFAULT)
|
||||
private transactionSetting: Repository<TransactionSettingModel>,
|
||||
) {
|
||||
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,5 +1,6 @@
|
|||
import { BaseEntity } from 'src/core/modules/domain/entities/base.entity';
|
||||
import { FormulaType } from '../../constants';
|
||||
import { BaseCoreEntity } from 'src/core/modules/domain/entities/base-core.entity';
|
||||
|
||||
export interface SalesPriceFormulaEntity extends BaseEntity {
|
||||
formula_render: any; // json type
|
||||
|
@ -16,3 +17,7 @@ export interface AdditionalFormula {
|
|||
formula_string: string;
|
||||
value_for: string;
|
||||
}
|
||||
|
||||
export interface TransactionSetting extends BaseCoreEntity {
|
||||
value: number;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
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,10 +1,17 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { SalesPriceFormulaDataService } from '../../data/services/sales-price-formula-data.service';
|
||||
import { SalesPriceFormulaEntity } from '../entities/sales-price-formula.entity';
|
||||
import {
|
||||
SalesPriceFormulaDataService,
|
||||
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 { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { FormulaType } from '../../constants';
|
||||
import { TaxDataService } from 'src/modules/transaction/tax/data/services/tax-data.service';
|
||||
import { UpdateTransactionSettingManager } from './managers/update-transaction-setting.manager';
|
||||
|
||||
@Injectable()
|
||||
export class SalesPriceFormulaDataOrchestrator {
|
||||
|
@ -12,6 +19,8 @@ export class SalesPriceFormulaDataOrchestrator {
|
|||
private updateManager: UpdateSalesPriceFormulaManager,
|
||||
private serviceData: SalesPriceFormulaDataService,
|
||||
private taxService: TaxDataService,
|
||||
private transactionSettingService: TransactionSettingDataService,
|
||||
private transactionSettingManager: UpdateTransactionSettingManager,
|
||||
) {}
|
||||
|
||||
async update(data): Promise<SalesPriceFormulaEntity> {
|
||||
|
@ -30,4 +39,14 @@ export class SalesPriceFormulaDataOrchestrator {
|
|||
await this.updateManager.execute();
|
||||
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,4 +17,12 @@ export class SalesPriceFormulaReadOrchestrator {
|
|||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
|
||||
async getTransactionSetting(): Promise<any> {
|
||||
try {
|
||||
return await this.serviceData.getTransactionSetting();
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import { BaseDto } from 'src/core/modules/infrastructure/dto/base.dto';
|
|||
import {
|
||||
AdditionalFormula,
|
||||
SalesPriceFormulaEntity,
|
||||
TransactionSetting,
|
||||
} from '../../domain/entities/sales-price-formula.entity';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ValidateIf, ValidateNested } from 'class-validator';
|
||||
|
@ -32,6 +33,21 @@ export class AdditionalFormulaDto implements AdditionalFormula {
|
|||
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
|
||||
extends BaseDto
|
||||
implements SalesPriceFormulaEntity
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Post, Put } from '@nestjs/common';
|
||||
import { SalesPriceFormulaDataOrchestrator } from '../domain/usecases/sales-price-formula-data.orchestrator';
|
||||
import { SalesPriceFormulaDto } from './dto/sales-price-formula.dto';
|
||||
import {
|
||||
SalesPriceFormulaDto,
|
||||
TransactionSettingDto,
|
||||
} from './dto/sales-price-formula.dto';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { SalesPriceFormulaEntity } from '../domain/entities/sales-price-formula.entity';
|
||||
import {
|
||||
SalesPriceFormulaEntity,
|
||||
TransactionSetting,
|
||||
} from '../domain/entities/sales-price-formula.entity';
|
||||
import { Public } from 'src/core/guards';
|
||||
|
||||
@ApiTags(`sales price formulas - data`)
|
||||
@Controller('v1/sales-price-formula')
|
||||
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class SalesPriceFormulaDataController {
|
||||
|
@ -18,4 +24,12 @@ export class SalesPriceFormulaDataController {
|
|||
): Promise<SalesPriceFormulaEntity> {
|
||||
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';
|
||||
|
||||
@ApiTags(`sales price formulas - read`)
|
||||
@Controller('v1/sales-price-formula')
|
||||
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
||||
@Public(false)
|
||||
@ApiBearerAuth('JWT')
|
||||
export class SalesPriceFormulaReadController {
|
||||
|
@ -15,4 +15,10 @@ export class SalesPriceFormulaReadController {
|
|||
async detail(): Promise<SalesPriceFormulaEntity> {
|
||||
return await this.orchestrator.detail();
|
||||
}
|
||||
|
||||
@Public(true)
|
||||
@Get('detail')
|
||||
async getTransactionSetting(): Promise<any> {
|
||||
return await this.orchestrator.getTransactionSetting();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,10 @@ import { Global, Module } from '@nestjs/common';
|
|||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { SalesPriceFormulaDataService } from './data/services/sales-price-formula-data.service';
|
||||
import {
|
||||
SalesPriceFormulaDataService,
|
||||
TransactionSettingDataService,
|
||||
} from './data/services/sales-price-formula-data.service';
|
||||
import { SalesPriceFormulaReadService } from './data/services/sales-price-formula-read.service';
|
||||
import { SalesPriceFormulaReadController } from './infrastructure/sales-price-formula-read.controller';
|
||||
import { SalesPriceFormulaReadOrchestrator } from './domain/usecases/sales-price-formula-read.orchestrator';
|
||||
|
@ -11,20 +14,33 @@ import { SalesPriceFormulaDataOrchestrator } from './domain/usecases/sales-price
|
|||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { UpdateSalesPriceFormulaManager } from './domain/usecases/managers/update-sales-price-formula.manager';
|
||||
import { DetailSalesPriceFormulaManager } from './domain/usecases/managers/detail-sales-price-formula.manager';
|
||||
import { SalesPriceFormulaModel } from './data/models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from './data/models/sales-price-formula.model';
|
||||
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
||||
import { TaxModel } from '../tax/data/models/tax.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()
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature(
|
||||
[SalesPriceFormulaModel, TaxModel, ItemModel],
|
||||
[
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
TransactionModel,
|
||||
TaxModel,
|
||||
ItemModel,
|
||||
],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [
|
||||
SalesPriceFormulaDataController,
|
||||
|
@ -33,10 +49,12 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
|||
providers: [
|
||||
DetailSalesPriceFormulaManager,
|
||||
UpdateSalesPriceFormulaManager,
|
||||
UpdateTransactionSettingManager,
|
||||
|
||||
TaxDataService,
|
||||
SalesPriceFormulaDataService,
|
||||
SalesPriceFormulaReadService,
|
||||
TransactionSettingDataService,
|
||||
|
||||
SalesPriceFormulaDataOrchestrator,
|
||||
SalesPriceFormulaReadOrchestrator,
|
||||
|
|
|
@ -23,14 +23,17 @@ import { BatchConfirmTaxManager } from './domain/usecases/managers/batch-confirm
|
|||
import { BatchInactiveTaxManager } from './domain/usecases/managers/batch-inactive-tax.manager';
|
||||
import { TaxModel } from './data/models/tax.model';
|
||||
import { SalesPriceFormulaReadService } from '../sales-price-formula/data/services/sales-price-formula-read.service';
|
||||
import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||
import { IndexTaxFormulaManager } from './domain/usecases/managers/index-tax-formula.manager';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature(
|
||||
[TaxModel, SalesPriceFormulaModel],
|
||||
[TaxModel, SalesPriceFormulaModel, TransactionSettingModel],
|
||||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
|
|
|
@ -31,6 +31,9 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
|||
) {}
|
||||
|
||||
async handle(event: ChangeDocEvent) {
|
||||
const envSkipTransaction = process.env.SKIP_TRANSACTION_FEATURE ?? 'false';
|
||||
const activeSkipTransaction = envSkipTransaction == 'true';
|
||||
|
||||
const apmTransactions = apm.startTransaction(
|
||||
`ChangeDocEvent ${event?.data?.database}`,
|
||||
'handler',
|
||||
|
@ -104,7 +107,17 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
|||
apmTransactions.setLabel('Code', data?.code);
|
||||
apmTransactions.setLabel('Status', data?.status);
|
||||
|
||||
await this.dataService.create(queryRunner, TransactionModel, data);
|
||||
// Check if this transaction should be sent to the "black hole" (not saved)
|
||||
// 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
|
||||
|
|
|
@ -32,7 +32,10 @@ import { BatchConfirmDataTransactionManager } from './domain/usecases/managers/b
|
|||
import { PosTransactionHandler } from './domain/usecases/handlers/pos-transaction.handler';
|
||||
import { TaxDataService } from '../tax/data/services/tax-data.service';
|
||||
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
|
||||
import { SalesPriceFormulaModel } from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||
import {
|
||||
SalesPriceFormulaModel,
|
||||
TransactionSettingModel,
|
||||
} from '../sales-price-formula/data/models/sales-price-formula.model';
|
||||
import { TaxModel } from '../tax/data/models/tax.model';
|
||||
import { SettledTransactionHandler } from './domain/usecases/handlers/settled-transaction.handler';
|
||||
import { RefundUpdatedHandler } from './domain/usecases/handlers/refund-update.handler';
|
||||
|
@ -43,6 +46,7 @@ import { PaymentMethodModel } from '../payment-method/data/models/payment-method
|
|||
import { TransactionDemographyModel } from './data/models/transaction-demography.model';
|
||||
import { PriceCalculator } from './domain/usecases/calculator/price.calculator';
|
||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
|
||||
@Module({
|
||||
exports: [TransactionReadService],
|
||||
|
@ -57,6 +61,7 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
|||
TransactionTaxModel,
|
||||
TransactionItemTaxModel,
|
||||
TransactionBreakdownTaxModel,
|
||||
TransactionSettingModel,
|
||||
TaxModel,
|
||||
SalesPriceFormulaModel,
|
||||
PaymentMethodModel,
|
||||
|
@ -65,6 +70,7 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
|||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [TransactionDataController, TransactionReadController],
|
||||
providers: [
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
} from './whatsapp.constant';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { apm } from 'src/core/apm';
|
||||
|
||||
export class WhatsappService {
|
||||
async sendMessage(data) {
|
||||
|
@ -25,8 +26,14 @@ export class WhatsappService {
|
|||
data: data,
|
||||
};
|
||||
|
||||
const response = await axios(config);
|
||||
return response.data;
|
||||
try {
|
||||
const response = await axios(config);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
Logger.error(error);
|
||||
apm?.captureError(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async queueRegister(data: WhatsappQueue) {
|
||||
|
@ -91,8 +98,11 @@ export class WhatsappService {
|
|||
},
|
||||
};
|
||||
|
||||
await this.sendMessage(payload);
|
||||
Logger.log(`Notification register for ${data.code} send to ${data.phone}`);
|
||||
const response = await this.sendMessage(payload);
|
||||
if (response)
|
||||
Logger.log(
|
||||
`Notification register for ${data.code} send to ${data.phone}`,
|
||||
);
|
||||
}
|
||||
|
||||
async queueProcess(data: WhatsappQueue) {
|
||||
|
@ -152,7 +162,8 @@ export class WhatsappService {
|
|||
},
|
||||
};
|
||||
|
||||
await this.sendMessage(payload);
|
||||
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||
const response = await this.sendMessage(payload);
|
||||
if (response)
|
||||
Logger.log(`Notification process for ${data.code} send to ${data.phone}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue