Compare commits
No commits in common. "development-local" and "1.5.1-alpha.1" have entirely different histories.
developmen
...
1.5.1-alph
|
@ -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,4 @@
|
||||||
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,
|
SalesPriceFormulaEntity,
|
||||||
|
@ -14,12 +10,10 @@ import {
|
||||||
TransactionSettingModel,
|
TransactionSettingModel,
|
||||||
} from '../models/sales-price-formula.model';
|
} 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 +24,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,38 +37,11 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
||||||
}
|
}
|
||||||
|
|
||||||
async sentToBlackHole() {
|
async sentToBlackHole() {
|
||||||
const transactionSettingData = await this.transactionSetting.findOne({
|
const percentage = 80;
|
||||||
where: {},
|
|
||||||
});
|
|
||||||
const percentage = transactionSettingData?.value ?? 100;
|
|
||||||
|
|
||||||
// const transactionPercentage = Math.floor(Math.random() * 100) + 1;
|
const randomValue = Math.floor(Math.random() * 100) + 1;
|
||||||
const transactionPercentage = await this.dataSaveFactor();
|
|
||||||
|
|
||||||
Logger.log(`Factor ${transactionPercentage} from ${percentage}`);
|
return randomValue > 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) {
|
||||||
|
|
|
@ -25,7 +25,6 @@ export class SalesPriceFormulaDataController {
|
||||||
return await this.orchestrator.update(data);
|
return await this.orchestrator.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public(true)
|
|
||||||
@Put()
|
@Put()
|
||||||
async updateTransactionSetting(
|
async updateTransactionSetting(
|
||||||
@Body() data: TransactionSettingDto,
|
@Body() data: TransactionSettingDto,
|
||||||
|
|
|
@ -16,7 +16,6 @@ export class SalesPriceFormulaReadController {
|
||||||
return await this.orchestrator.detail();
|
return await this.orchestrator.detail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public(true)
|
|
||||||
@Get('detail')
|
@Get('detail')
|
||||||
async getTransactionSetting(): Promise<any> {
|
async getTransactionSetting(): Promise<any> {
|
||||||
return await this.orchestrator.getTransactionSetting();
|
return await this.orchestrator.getTransactionSetting();
|
||||||
|
|
|
@ -22,21 +22,13 @@ 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 { 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, TransactionSettingModel, TaxModel, ItemModel],
|
||||||
SalesPriceFormulaModel,
|
|
||||||
TransactionSettingModel,
|
|
||||||
TransactionModel,
|
|
||||||
TaxModel,
|
|
||||||
ItemModel,
|
|
||||||
],
|
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
@ -57,7 +49,6 @@ import { CouchService } from 'src/modules/configuration/couch/data/services/couc
|
||||||
|
|
||||||
SalesPriceFormulaDataOrchestrator,
|
SalesPriceFormulaDataOrchestrator,
|
||||||
SalesPriceFormulaReadOrchestrator,
|
SalesPriceFormulaReadOrchestrator,
|
||||||
CouchService,
|
|
||||||
],
|
],
|
||||||
exports: [SalesPriceFormulaDataService, SalesPriceFormulaReadService],
|
exports: [SalesPriceFormulaDataService, SalesPriceFormulaReadService],
|
||||||
})
|
})
|
||||||
|
|
|
@ -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