Compare commits
No commits in common. "6882314a9ee730e97e58f4f808156156c42bbd0f" and "064112e73132a47c8fd06ba40277239cde1a7e9b" have entirely different histories.
6882314a9e
...
064112e731
|
@ -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',
|
||||||
|
|
|
@ -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"`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -97,36 +97,6 @@ export class CouchService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async totalTodayTransactions(database = 'transaction') {
|
|
||||||
try {
|
|
||||||
const nano = this.nanoInstance;
|
|
||||||
const db = nano.use(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'],
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.docs.length;
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
apm.captureError(error);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getUnixTimestampLast7Days() {
|
getUnixTimestampLast7Days() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
date.setDate(date.getDate() - 4);
|
date.setDate(date.getDate() - 4);
|
||||||
|
|
|
@ -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,25 +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 { MoreThan, 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';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceFormulaEntity> {
|
export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceFormulaEntity> {
|
||||||
|
@ -30,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);
|
||||||
}
|
}
|
||||||
|
@ -47,41 +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 = await this.transaction.count({
|
|
||||||
where: {
|
|
||||||
created_at: MoreThan(todayTimestamp),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
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'],
|
||||||
|
@ -142,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,29 +11,17 @@ 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 { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
|
||||||
|
|
||||||
@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,
|
||||||
|
@ -48,16 +33,13 @@ import { CouchService } from 'src/modules/configuration/couch/data/services/couc
|
||||||
providers: [
|
providers: [
|
||||||
DetailSalesPriceFormulaManager,
|
DetailSalesPriceFormulaManager,
|
||||||
UpdateSalesPriceFormulaManager,
|
UpdateSalesPriceFormulaManager,
|
||||||
UpdateTransactionSettingManager,
|
|
||||||
|
|
||||||
TaxDataService,
|
TaxDataService,
|
||||||
SalesPriceFormulaDataService,
|
SalesPriceFormulaDataService,
|
||||||
SalesPriceFormulaReadService,
|
SalesPriceFormulaReadService,
|
||||||
TransactionSettingDataService,
|
|
||||||
|
|
||||||
SalesPriceFormulaDataOrchestrator,
|
SalesPriceFormulaDataOrchestrator,
|
||||||
SalesPriceFormulaReadOrchestrator,
|
SalesPriceFormulaReadOrchestrator,
|
||||||
CouchService,
|
|
||||||
],
|
],
|
||||||
exports: [SalesPriceFormulaDataService, SalesPriceFormulaReadService],
|
exports: [SalesPriceFormulaDataService, SalesPriceFormulaReadService],
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
exports: [TransactionReadService],
|
exports: [TransactionReadService],
|
||||||
|
@ -61,7 +57,6 @@ import { CouchService } from 'src/modules/configuration/couch/data/services/couc
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
TransactionItemTaxModel,
|
TransactionItemTaxModel,
|
||||||
TransactionBreakdownTaxModel,
|
TransactionBreakdownTaxModel,
|
||||||
TransactionSettingModel,
|
|
||||||
TaxModel,
|
TaxModel,
|
||||||
SalesPriceFormulaModel,
|
SalesPriceFormulaModel,
|
||||||
PaymentMethodModel,
|
PaymentMethodModel,
|
||||||
|
@ -101,8 +96,6 @@ import { CouchService } from 'src/modules/configuration/couch/data/services/couc
|
||||||
|
|
||||||
TransactionDataOrchestrator,
|
TransactionDataOrchestrator,
|
||||||
TransactionReadOrchestrator,
|
TransactionReadOrchestrator,
|
||||||
|
|
||||||
CouchService,
|
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class TransactionModule {}
|
export class TransactionModule {}
|
||||||
|
|
Loading…
Reference in New Issue