Compare commits
10 Commits
1.5.0-alph
...
developmen
Author | SHA1 | Date |
---|---|---|
|
94e769795a | |
|
968697ee17 | |
|
2dd0bd45a8 | |
|
8afbe33c01 | |
|
928e2e7648 | |
|
94baf956dd | |
|
e92f325807 | |
|
66d76634b7 | |
|
b91080906e | |
|
714b075e1d |
|
@ -33,7 +33,10 @@ 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 { 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 { 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';
|
||||||
|
@ -93,7 +96,9 @@ import {
|
||||||
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
|
import { ItemQueueModule } from './modules/item-related/item-queue/item-queue.module';
|
||||||
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from './modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model';
|
import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model';
|
||||||
|
import { VerificationModel } from './modules/booking-online/authentication/data/models/verification.model';
|
||||||
|
import { BookingOnlineAuthModule } from './modules/booking-online/authentication/auth.module';
|
||||||
|
import { BookingOrderModule } from './modules/booking-online/order/order.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ApmModule.register(),
|
ApmModule.register(),
|
||||||
|
@ -137,6 +142,7 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
||||||
TransactionItemBreakdownModel,
|
TransactionItemBreakdownModel,
|
||||||
TransactionItemTaxModel,
|
TransactionItemTaxModel,
|
||||||
TransactionBreakdownTaxModel,
|
TransactionBreakdownTaxModel,
|
||||||
|
TransactionSettingModel,
|
||||||
UserModel,
|
UserModel,
|
||||||
UserLoginModel,
|
UserLoginModel,
|
||||||
|
|
||||||
|
@ -153,6 +159,9 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
||||||
QueueItemModel,
|
QueueItemModel,
|
||||||
QueueModel,
|
QueueModel,
|
||||||
QueueBucketModel,
|
QueueBucketModel,
|
||||||
|
|
||||||
|
// Booking Online
|
||||||
|
VerificationModel,
|
||||||
],
|
],
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
}),
|
}),
|
||||||
|
@ -214,6 +223,9 @@ import { QueueBucketModel } from './modules/queue/data/models/queue-bucket.model
|
||||||
GateScanModule,
|
GateScanModule,
|
||||||
|
|
||||||
QueueModule,
|
QueueModule,
|
||||||
|
|
||||||
|
BookingOnlineAuthModule,
|
||||||
|
BookingOrderModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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',
|
||||||
|
|
|
@ -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"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class BookingAuthentication1748313715598 implements MigrationInterface {
|
||||||
|
name = 'BookingAuthentication1748313715598';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`CREATE TABLE "booking_verification" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying NOT NULL, "phone_number" character varying NOT NULL, "code" character varying, "tried" integer NOT NULL DEFAULT '0', "created_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, "updated_at" bigint NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()) * 1000, CONSTRAINT "PK_046e9288c7dd05c7259275d9fc0" PRIMARY KEY ("id"))`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP TABLE "booking_verification"`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { VerificationModel } from './data/models/verification.model';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { BookingAuthenticationController } from './infrastructure/controllers/booking-authentication.controller';
|
||||||
|
import { VerificationService } from './data/services/verification.service';
|
||||||
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||||
|
import { JWT_SECRET } from 'src/core/sessions/constants';
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
TypeOrmModule.forFeature([VerificationModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
|
||||||
|
JwtModule.register({
|
||||||
|
secret: JWT_SECRET,
|
||||||
|
signOptions: { expiresIn: JWT_EXPIRED },
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
controllers: [BookingAuthenticationController],
|
||||||
|
providers: [VerificationService],
|
||||||
|
})
|
||||||
|
export class BookingOnlineAuthModule {}
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||||
|
@Entity('booking_verification')
|
||||||
|
export class VerificationModel implements BookingVerification {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
phone_number: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
code?: string;
|
||||||
|
|
||||||
|
@Column({ default: 0 })
|
||||||
|
tried: number;
|
||||||
|
|
||||||
|
@Column({ type: 'bigint', default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000' })
|
||||||
|
created_at: number;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
type: 'bigint',
|
||||||
|
default: () => 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||||
|
onUpdate: 'EXTRACT(EPOCH FROM NOW()) * 1000',
|
||||||
|
})
|
||||||
|
updated_at: number;
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { VerificationModel } from '../models/verification.model';
|
||||||
|
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||||
|
import { UnprocessableEntityException } from '@nestjs/common';
|
||||||
|
import { JwtService } from '@nestjs/jwt';
|
||||||
|
export class VerificationService {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(VerificationModel)
|
||||||
|
private readonly verificationRepository: Repository<VerificationModel>,
|
||||||
|
private readonly jwtService: JwtService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
maxAttempts = 3;
|
||||||
|
expiredTime = 5 * 60 * 1000;
|
||||||
|
expiredTimeRegister = 1 * 60 * 1000;
|
||||||
|
|
||||||
|
async generateToken(payload: BookingVerification) {
|
||||||
|
return this.jwtService.sign({
|
||||||
|
phone_number: payload.phone_number,
|
||||||
|
name: payload.name,
|
||||||
|
created_at: payload.created_at,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async register(data: BookingVerification) {
|
||||||
|
const currentTime = Math.floor(Date.now()); // current time in seconds
|
||||||
|
if (
|
||||||
|
data.created_at &&
|
||||||
|
currentTime - data.created_at > this.expiredTimeRegister
|
||||||
|
) {
|
||||||
|
throw new UnprocessableEntityException('Please try again in 1 minute');
|
||||||
|
}
|
||||||
|
// Generate a 4 digit OTP code
|
||||||
|
data.code = Math.floor(1000 + Math.random() * 9000).toString();
|
||||||
|
data.tried = 0;
|
||||||
|
data.updated_at = currentTime;
|
||||||
|
|
||||||
|
let verification = await this.verificationRepository.findOne({
|
||||||
|
where: { phone_number: data.phone_number },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (verification) {
|
||||||
|
// Update existing record
|
||||||
|
verification = this.verificationRepository.merge(verification, data);
|
||||||
|
} else {
|
||||||
|
// Create new record
|
||||||
|
verification = this.verificationRepository.create(data);
|
||||||
|
}
|
||||||
|
return this.verificationRepository.save(verification);
|
||||||
|
}
|
||||||
|
|
||||||
|
async findByPhoneNumber(phoneNumber: string) {
|
||||||
|
return this.verificationRepository.findOne({
|
||||||
|
where: { phone_number: phoneNumber },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async verify(data: BookingVerification): Promise<BookingVerification> {
|
||||||
|
const verification = await this.findByPhoneNumber(data.phone_number);
|
||||||
|
if (!verification) {
|
||||||
|
throw new UnprocessableEntityException('Phone number not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verification.tried >= this.maxAttempts) {
|
||||||
|
throw new UnprocessableEntityException(
|
||||||
|
'Too many attempts, please resend OTP Code',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (verification.code != data.code) {
|
||||||
|
verification.tried++;
|
||||||
|
await this.verificationRepository.save(verification);
|
||||||
|
throw new UnprocessableEntityException('Invalid verification code');
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentTime = Math.floor(Date.now());
|
||||||
|
if (
|
||||||
|
verification.updated_at &&
|
||||||
|
currentTime - verification.updated_at > this.expiredTime
|
||||||
|
) {
|
||||||
|
throw new UnprocessableEntityException('Verification code expired');
|
||||||
|
}
|
||||||
|
|
||||||
|
return verification;
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, data: BookingVerification) {
|
||||||
|
return this.verificationRepository.update(id, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
async delete(id: string) {
|
||||||
|
return this.verificationRepository.delete(id);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
export interface BookingVerification {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
phone_number: string;
|
||||||
|
code?: string;
|
||||||
|
tried?: number;
|
||||||
|
created_at?: number;
|
||||||
|
updated_at?: number;
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { Controller, Post, Body, Get, Param } from '@nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
BookingVerificationDto,
|
||||||
|
VerificationCodeDto,
|
||||||
|
} from '../dto/booking-verification.dto';
|
||||||
|
import { VerificationService } from '../../data/services/verification.service';
|
||||||
|
import { Public } from 'src/core/guards/domain/decorators/unprotected.guard';
|
||||||
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
@ApiTags('Booking Authentication')
|
||||||
|
@Public()
|
||||||
|
@Controller('v1/booking-authentication')
|
||||||
|
export class BookingAuthenticationController {
|
||||||
|
constructor(
|
||||||
|
private readonly bookingAuthenticationService: VerificationService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Post('verify')
|
||||||
|
async verify(@Body() body: VerificationCodeDto) {
|
||||||
|
const verification = await this.bookingAuthenticationService.verify(body);
|
||||||
|
const token = await this.bookingAuthenticationService.generateToken(
|
||||||
|
verification,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
message: `Verification successful for ${verification.phone_number}`,
|
||||||
|
token,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('register')
|
||||||
|
async register(@Body() body: BookingVerificationDto) {
|
||||||
|
const verification = await this.bookingAuthenticationService.register(body);
|
||||||
|
return {
|
||||||
|
message: `Verification code sent to ${verification.phone_number}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('get-by-phone/:phone_number')
|
||||||
|
async getByPhoneNumber(@Param('phone_number') phone_number: string) {
|
||||||
|
return this.bookingAuthenticationService.findByPhoneNumber(phone_number);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { BookingVerification } from '../../domain/entities/booking-verification.entity';
|
||||||
|
import { IsString, IsNotEmpty, Matches } from 'class-validator';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class BookingVerificationDto implements BookingVerification {
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
example: 'John Doe',
|
||||||
|
description: 'Name of the person booking',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
example: '628123456789',
|
||||||
|
description: 'Phone number containing only numeric characters',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@Matches(/^\d+$/, {
|
||||||
|
message: 'phone_number must contain only numeric characters',
|
||||||
|
})
|
||||||
|
phone_number: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class VerificationCodeDto implements BookingVerification {
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
example: 'John Doe',
|
||||||
|
description: 'Name of the person booking',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
example: '628123456789',
|
||||||
|
description: 'Phone number containing only numeric characters',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
@Matches(/^\d+$/, {
|
||||||
|
message: 'phone_number must contain only numeric characters',
|
||||||
|
})
|
||||||
|
phone_number: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
example: '1234',
|
||||||
|
description: 'Verification code',
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
code?: string;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { Public } from 'src/core/guards';
|
||||||
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
|
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
||||||
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||||
|
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
||||||
|
|
||||||
|
@ApiTags('Booking Item')
|
||||||
|
@Controller('v1/booking-item')
|
||||||
|
@Public(true)
|
||||||
|
export class ItemController {
|
||||||
|
constructor(
|
||||||
|
private indexManager: IndexItemManager,
|
||||||
|
private serviceData: ItemReadService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async index(
|
||||||
|
@Query() params: FilterItemDto,
|
||||||
|
): Promise<PaginationResponse<ItemEntity>> {
|
||||||
|
try {
|
||||||
|
params.show_to_booking = true;
|
||||||
|
this.indexManager.setFilterParam(params);
|
||||||
|
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
||||||
|
await this.indexManager.execute();
|
||||||
|
return this.indexManager.getResult();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||||
|
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
|
import { ItemModule } from 'src/modules/item-related/item/item.module';
|
||||||
|
import { ItemController } from './infrastructure/item.controller';
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot(),
|
||||||
|
TypeOrmModule.forFeature([ItemModel], CONNECTION_NAME.DEFAULT),
|
||||||
|
ItemModule,
|
||||||
|
],
|
||||||
|
controllers: [ItemController],
|
||||||
|
providers: [],
|
||||||
|
})
|
||||||
|
export class BookingOrderModule {}
|
|
@ -97,6 +97,40 @@ export class CouchService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
getUnixTimestampLast7Days() {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
date.setDate(date.getDate() - 4);
|
date.setDate(date.getDate() - 4);
|
||||||
|
|
|
@ -98,6 +98,10 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
queryBuilder.andWhere(`${this.tableName}.tenant_id Is Null`);
|
queryBuilder.andWhere(`${this.tableName}.tenant_id Is Null`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.filterParam.show_to_booking) {
|
||||||
|
queryBuilder.andWhere(`${this.tableName}.show_to_booking = true`);
|
||||||
|
}
|
||||||
|
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,4 +40,6 @@ export class FilterItemDto extends BaseFilterDto implements FilterItemEntity {
|
||||||
})
|
})
|
||||||
@Transform((body) => body.value == 'true')
|
@Transform((body) => body.value == 'true')
|
||||||
all_item: boolean;
|
all_item: boolean;
|
||||||
|
|
||||||
|
show_to_booking: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ export class SeasonPeriodReadController {
|
||||||
return await this.orchestrator.index(params);
|
return await this.orchestrator.index(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public(true)
|
||||||
@Get('current-period')
|
@Get('current-period')
|
||||||
async currentPeriod(
|
async currentPeriod(
|
||||||
@Query() params: FilterCurrentSeasonDto,
|
@Query() params: FilterCurrentSeasonDto,
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
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 { 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';
|
||||||
|
@ -31,3 +34,12 @@ 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,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 { 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 { 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 { 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> {
|
||||||
|
@ -18,6 +31,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -31,11 +49,44 @@ export class SalesPriceFormulaDataService extends BaseDataService<SalesPriceForm
|
||||||
}
|
}
|
||||||
|
|
||||||
async sentToBlackHole() {
|
async sentToBlackHole() {
|
||||||
const percentage = 80;
|
const transactionSettingData = await this.transactionSetting.findOne({
|
||||||
|
where: {},
|
||||||
|
});
|
||||||
|
const percentage = transactionSettingData?.value ?? 100;
|
||||||
|
|
||||||
const randomValue = Math.floor(Math.random() * 100) + 1;
|
// const transactionPercentage = Math.floor(Math.random() * 100) + 1;
|
||||||
|
const transactionPercentage = await this.dataSaveFactor();
|
||||||
|
|
||||||
return randomValue > percentage;
|
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) {
|
||||||
|
@ -98,3 +149,13 @@ 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,7 +1,10 @@
|
||||||
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 { 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 { 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';
|
||||||
|
@ -11,7 +14,25 @@ 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,5 +1,6 @@
|
||||||
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
|
||||||
|
@ -16,3 +17,7 @@ export interface AdditionalFormula {
|
||||||
formula_string: string;
|
formula_string: string;
|
||||||
value_for: 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 { Injectable } from '@nestjs/common';
|
||||||
import { SalesPriceFormulaDataService } from '../../data/services/sales-price-formula-data.service';
|
import {
|
||||||
import { SalesPriceFormulaEntity } from '../entities/sales-price-formula.entity';
|
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 { 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 {
|
||||||
|
@ -12,6 +19,8 @@ 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> {
|
||||||
|
@ -30,4 +39,14 @@ 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,4 +17,12 @@ 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,6 +2,7 @@ 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';
|
||||||
|
@ -32,6 +33,21 @@ 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,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 { 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 { 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';
|
import { Public } from 'src/core/guards';
|
||||||
|
|
||||||
@ApiTags(`sales price formulas - data`)
|
@ApiTags(`sales price formulas - data`)
|
||||||
@Controller('v1/sales-price-formula')
|
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class SalesPriceFormulaDataController {
|
export class SalesPriceFormulaDataController {
|
||||||
|
@ -18,4 +24,12 @@ 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')
|
@Controller(['v1/sales-price-formula', 'v1/transaction-setting'])
|
||||||
@Public(false)
|
@Public(false)
|
||||||
@ApiBearerAuth('JWT')
|
@ApiBearerAuth('JWT')
|
||||||
export class SalesPriceFormulaReadController {
|
export class SalesPriceFormulaReadController {
|
||||||
|
@ -15,4 +15,10 @@ 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,7 +2,10 @@ 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 { 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 { 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';
|
||||||
|
@ -11,20 +14,33 @@ 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 { 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 { 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,
|
||||||
|
@ -33,10 +49,12 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
||||||
providers: [
|
providers: [
|
||||||
DetailSalesPriceFormulaManager,
|
DetailSalesPriceFormulaManager,
|
||||||
UpdateSalesPriceFormulaManager,
|
UpdateSalesPriceFormulaManager,
|
||||||
|
UpdateTransactionSettingManager,
|
||||||
|
|
||||||
TaxDataService,
|
TaxDataService,
|
||||||
SalesPriceFormulaDataService,
|
SalesPriceFormulaDataService,
|
||||||
SalesPriceFormulaReadService,
|
SalesPriceFormulaReadService,
|
||||||
|
TransactionSettingDataService,
|
||||||
|
|
||||||
SalesPriceFormulaDataOrchestrator,
|
SalesPriceFormulaDataOrchestrator,
|
||||||
SalesPriceFormulaReadOrchestrator,
|
SalesPriceFormulaReadOrchestrator,
|
||||||
|
|
|
@ -23,14 +23,17 @@ 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 { 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';
|
import { IndexTaxFormulaManager } from './domain/usecases/managers/index-tax-formula.manager';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[TaxModel, SalesPriceFormulaModel],
|
[TaxModel, SalesPriceFormulaModel, TransactionSettingModel],
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
|
|
@ -31,6 +31,9 @@ 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,6 +110,7 @@ export class PosTransactionHandler implements IEventHandler<ChangeDocEvent> {
|
||||||
// Check if this transaction should be sent to the "black hole" (not saved)
|
// Check if this transaction should be sent to the "black hole" (not saved)
|
||||||
// This is only applicable for SETTLED transactions
|
// This is only applicable for SETTLED transactions
|
||||||
const shouldSkipSaving =
|
const shouldSkipSaving =
|
||||||
|
activeSkipTransaction &&
|
||||||
data.status === STATUS.SETTLED &&
|
data.status === STATUS.SETTLED &&
|
||||||
(await this.formulaService.sentToBlackHole());
|
(await this.formulaService.sentToBlackHole());
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,10 @@ 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 { 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 { 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';
|
||||||
|
@ -43,6 +46,7 @@ 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],
|
||||||
|
@ -57,6 +61,7 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
||||||
TransactionTaxModel,
|
TransactionTaxModel,
|
||||||
TransactionItemTaxModel,
|
TransactionItemTaxModel,
|
||||||
TransactionBreakdownTaxModel,
|
TransactionBreakdownTaxModel,
|
||||||
|
TransactionSettingModel,
|
||||||
TaxModel,
|
TaxModel,
|
||||||
SalesPriceFormulaModel,
|
SalesPriceFormulaModel,
|
||||||
PaymentMethodModel,
|
PaymentMethodModel,
|
||||||
|
@ -65,6 +70,7 @@ import { ItemModel } from 'src/modules/item-related/item/data/models/item.model'
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
|
CouchModule,
|
||||||
],
|
],
|
||||||
controllers: [TransactionDataController, TransactionReadController],
|
controllers: [TransactionDataController, TransactionReadController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
Loading…
Reference in New Issue