Compare commits
7 Commits
1d9cdfe8e6
...
822cfe606a
Author | SHA1 | Date |
---|---|---|
|
822cfe606a | |
|
de43f0f28b | |
|
afad02ba52 | |
|
6636c596f4 | |
|
01fb358875 | |
|
f9dc49f7d5 | |
|
47d45cb65c |
|
@ -106,6 +106,7 @@ import { OtpVerificationModule } from './modules/configuration/otp-verification/
|
|||
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||
import { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
||||
import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -246,6 +247,8 @@ import { RescheduleVerificationModel } from './modules/booking-online/order/data
|
|||
providers: [
|
||||
AuthService,
|
||||
PrivilegeService,
|
||||
OtpCheckerGuard,
|
||||
|
||||
/**
|
||||
* By default all request from client will protect by JWT
|
||||
* if there is some endpoint/function that does'nt require authentication
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectDataSource } from '@nestjs/typeorm';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { OtpVerificationModel } from 'src/modules/configuration/otp-verification/data/models/otp-verification.model';
|
||||
import { OtpVerificationEntity } from 'src/modules/configuration/otp-verification/domain/entities/otp-verification.entity';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class OtpCheckerGuard implements CanActivate {
|
||||
constructor(
|
||||
@InjectDataSource(CONNECTION_NAME.DEFAULT)
|
||||
protected readonly dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
get otpRepository() {
|
||||
return this.dataSource.getRepository(OtpVerificationModel);
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const verificationCode = request.headers['x-verification-code'];
|
||||
console.log({ verificationCode });
|
||||
|
||||
if (verificationCode) {
|
||||
const decoded = Buffer.from(verificationCode, 'base64').toString('ascii');
|
||||
const [dataIdentity, otpCode] = decoded.split('|');
|
||||
|
||||
let otpData: OtpVerificationEntity;
|
||||
|
||||
otpData = await this.otpRepository.findOne({
|
||||
where: {
|
||||
otp_code: otpCode,
|
||||
target_id: dataIdentity,
|
||||
},
|
||||
});
|
||||
|
||||
if (!otpData) {
|
||||
otpData = await this.otpRepository.findOne({
|
||||
where: {
|
||||
otp_code: otpCode,
|
||||
reference: dataIdentity,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (otpData && otpData?.verified_at) return true;
|
||||
console.log({ dataIdentity, otpCode, otpData });
|
||||
}
|
||||
|
||||
throw new UnprocessableEntityException('OTP not verified.');
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
||||
import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
|
||||
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -19,6 +19,7 @@ import { TransactionTaxModel } from 'src/modules/transaction/transaction/data/mo
|
|||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [GoogleCalendarController],
|
||||
providers: [
|
||||
|
|
|
@ -10,7 +10,7 @@ import { TransactionDataService } from 'src/modules/transaction/transaction/data
|
|||
import { PaymentTransactionHandler } from './domain/handlers/payment-transaction.handler';
|
||||
import { MailTemplateController } from './infrastructure/mail.controller';
|
||||
import { PdfMakeManager } from '../export/domain/managers/pdf-make.manager';
|
||||
|
||||
import { CouchModule } from '../couch/couch.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -19,6 +19,7 @@ import { PdfMakeManager } from '../export/domain/managers/pdf-make.manager';
|
|||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [MailTemplateController],
|
||||
providers: [
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
OtpVerifierCreateDto,
|
||||
OtpVerifyDto,
|
||||
} from './dto/otp-verification.dto';
|
||||
import { OtpAuthGuard } from './guards/otp-auth-guard';
|
||||
import { OtpAuthGuard } from './guards/otp-auth.guard';
|
||||
import { OtpVerifierService } from '../data/services/otp-verifier.service';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from './infrastructure/otp-verification-data.controller';
|
||||
import { OtpVerificationService } from './data/services/otp-verification.service';
|
||||
import { OtpVerifierModel } from './data/models/otp-verifier.model';
|
||||
import { OtpAuthGuard } from './infrastructure/guards/otp-auth-guard';
|
||||
import { OtpAuthGuard } from './infrastructure/guards/otp-auth.guard';
|
||||
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||
|
|
|
@ -39,7 +39,7 @@ import { ItemQueueModel } from '../item-related/item-queue/data/models/item-queu
|
|||
import { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
||||
import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
||||
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -57,6 +57,7 @@ import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
|||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [QueueController, QueueAdminController, QueueJobController],
|
||||
providers: [
|
||||
|
|
|
@ -19,13 +19,13 @@ import { BatchCancelReconciliationManager } from './domain/usecases/managers/bat
|
|||
import { BatchConfirmReconciliationManager } from './domain/usecases/managers/batch-confirm-reconciliation.manager';
|
||||
import { RecapReconciliationManager } from './domain/usecases/managers/recap-reconciliation.manager';
|
||||
import { RecapPosTransactionHandler } from './domain/usecases/handlers/recap-pos-transaction.handler';
|
||||
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
|
||||
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([TransactionModel], CONNECTION_NAME.DEFAULT),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [ReconciliationDataController, ReconciliationReadController],
|
||||
providers: [
|
||||
|
|
|
@ -23,7 +23,7 @@ import { CancelRefundManager } from './domain/usecases/managers/cancel-refund.ma
|
|||
import { RefundItemModel } from './data/models/refund-item.model';
|
||||
import { TransactionDataService } from '../transaction/data/services/transaction-data.service';
|
||||
import { TransactionModel } from '../transaction/data/models/transaction.model';
|
||||
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -32,6 +32,7 @@ import { TransactionModel } from '../transaction/data/models/transaction.model';
|
|||
CONNECTION_NAME.DEFAULT,
|
||||
),
|
||||
CqrsModule,
|
||||
CouchModule,
|
||||
],
|
||||
controllers: [RefundDataController, RefundReadController],
|
||||
providers: [
|
||||
|
|
|
@ -4,12 +4,14 @@ import { InjectRepository } from '@nestjs/typeorm';
|
|||
import { TransactionModel } from '../models/transaction.model';
|
||||
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionDataService extends BaseDataService<TransactionModel> {
|
||||
constructor(
|
||||
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<TransactionModel>,
|
||||
private couchService: CouchService,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
|
@ -20,4 +22,14 @@ export class TransactionDataService extends BaseDataService<TransactionModel> {
|
|||
where: { id: booking_id },
|
||||
});
|
||||
}
|
||||
|
||||
async saveTransactionToCouch(transaction) {
|
||||
const id = transaction.id ?? transaction._id;
|
||||
const couchData = await this.couchService.getDoc(id, 'transaction');
|
||||
if (!couchData) {
|
||||
await this.couchService.createDoc(transaction, 'transaction');
|
||||
} else {
|
||||
await this.couchService.updateDoc(transaction, 'transaction');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,4 +30,64 @@ export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
|||
|
||||
return transactions;
|
||||
}
|
||||
|
||||
async getSummary(posId: string, startDate: string) {
|
||||
const query = `select payment_type_counter, payment_type_method_name, sum(payment_total) payment_total, sum(payment_total_pay) payment_total_pay
|
||||
from transactions t
|
||||
where 1=1
|
||||
and t.creator_counter_no IN (${posId})
|
||||
and invoice_date = '${startDate}'
|
||||
and status = 'settled'
|
||||
group by payment_type_counter, payment_type_method_name;`;
|
||||
const transactions = await this.repo.query(query);
|
||||
|
||||
const qtyQuery = `select ti.item_id, ti.item_name, sum(ti.qty) total_qty, count(ti.item_name), sum(ti.qty), string_agg(distinct ti.item_price::text, '') price,
|
||||
sum(payment_total) payment_total, sum(payment_total_pay) payment_total_pay
|
||||
from transactions t
|
||||
inner join transaction_items ti on t.id = ti.transaction_id
|
||||
where t.creator_counter_no IN (${posId})
|
||||
and invoice_date = '${startDate}'
|
||||
and t.status = 'settled'
|
||||
group by ti.item_name, ti.item_id`;
|
||||
const qtyTransactions = await this.repo.query(qtyQuery);
|
||||
|
||||
const totalSalesQuery = `select sum(payment_total) payment_total
|
||||
from transactions t
|
||||
where 1=1
|
||||
and t.creator_counter_no IN (${posId})
|
||||
and invoice_date = '${startDate}'
|
||||
and status = 'settled'`;
|
||||
const totalSales = await this.repo.query(totalSalesQuery);
|
||||
|
||||
return {
|
||||
payment: transactions,
|
||||
qty: qtyTransactions,
|
||||
totalSales: totalSales?.[0]?.payment_total ?? 0,
|
||||
};
|
||||
}
|
||||
|
||||
async getLastTransactionByPos(
|
||||
posId: string,
|
||||
): Promise<TransactionEntity | null> {
|
||||
const transaction = await this.repo.findOne({
|
||||
select: [
|
||||
'id',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'status',
|
||||
'invoice_code',
|
||||
'creator_counter_no',
|
||||
'invoice_date',
|
||||
'payment_total',
|
||||
],
|
||||
where: {
|
||||
creator_counter_no: parseInt(posId),
|
||||
},
|
||||
order: {
|
||||
created_at: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
return transaction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,4 +141,10 @@ export class TransactionDataOrchestrator {
|
|||
await this.batchConfirmDataManager.execute();
|
||||
return this.batchConfirmDataManager.getResult();
|
||||
}
|
||||
|
||||
async saveTransactionToCouch(transaction: any[]) {
|
||||
for (const t of transaction) {
|
||||
await this.serviceData.saveTransactionToCouch(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrat
|
|||
import { DetailTransactionManager } from './managers/detail-transaction.manager';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { PriceCalculator } from './calculator/price.calculator';
|
||||
import { In } from 'typeorm';
|
||||
import * as moment from 'moment';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionReadOrchestrator extends BaseReadOrchestrator<TransactionEntity> {
|
||||
|
@ -26,6 +28,16 @@ export class TransactionReadOrchestrator extends BaseReadOrchestrator<Transactio
|
|||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async summary(posId: string) {
|
||||
const today = moment().format('YYYY-MM-DD');
|
||||
const summary = await this.serviceData.getSummary(posId, today);
|
||||
const lastTransaction = await this.serviceData.getLastTransactionByPos(
|
||||
posId,
|
||||
);
|
||||
|
||||
return { summary, lastTransaction };
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<TransactionEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
||||
|
@ -50,17 +62,24 @@ export class TransactionReadOrchestrator extends BaseReadOrchestrator<Transactio
|
|||
transaction.payment_total_dpp = price.dpp_value;
|
||||
transaction.payment_total_share = price.other.total_profit_share;
|
||||
transaction.payment_total_tax = price.other.payment_total_tax;
|
||||
console.log({ price }, transaction.payment_total);
|
||||
console.log(transaction.id);
|
||||
await this.serviceData.getRepository().save(transaction);
|
||||
}
|
||||
|
||||
ids = [];
|
||||
|
||||
async calculatePrice(): Promise<void> {
|
||||
const transactions = await this.serviceData.getManyByOptions({
|
||||
where: {
|
||||
is_recap_transaction: false,
|
||||
// is_recap_transaction: false,
|
||||
id: In(this.ids),
|
||||
},
|
||||
relations: ['items', 'items.bundling_items'],
|
||||
});
|
||||
|
||||
console.log(transactions.length);
|
||||
// return;
|
||||
|
||||
for (const transaction of transactions) {
|
||||
try {
|
||||
const price = await this.calculator.calculate(transaction);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
|
@ -7,17 +8,19 @@ import {
|
|||
Post,
|
||||
Put,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { TransactionDataOrchestrator } from '../domain/usecases/transaction-data.orchestrator';
|
||||
import { TransactionDto } from './dto/transaction.dto';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiBody, ApiTags } from '@nestjs/swagger';
|
||||
import { TransactionEntity } from '../domain/entities/transaction.entity';
|
||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { DownloadPdfDto } from './dto/donwload-pdf.dto';
|
||||
import { OtpAuthGuard } from 'src/modules/configuration/otp-verification/infrastructure/guards/otp-auth.guard';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.TRANSACTION.split('-').join(' ')} - data`)
|
||||
@Controller(`v1/${MODULE_NAME.TRANSACTION}`)
|
||||
|
@ -91,4 +94,29 @@ export class TransactionDataController {
|
|||
async delete(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.delete(dataId);
|
||||
}
|
||||
|
||||
@Post('save-to-couch')
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
})
|
||||
@Public(true)
|
||||
// @UseGuards(OtpAuthGuard)
|
||||
async saveToCouch(@Body() body: any[]) {
|
||||
try {
|
||||
await this.orchestrator.saveTransactionToCouch(body);
|
||||
return {
|
||||
message: 'Success',
|
||||
};
|
||||
} catch (error) {
|
||||
throw new BadRequestException({
|
||||
message: error.message,
|
||||
error: error.stack,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,12 @@ export class TransactionReadController {
|
|||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
|
||||
@Public(true)
|
||||
@Get('summary/:posId')
|
||||
async summary(@Param('posId') posId: string) {
|
||||
return await this.orchestrator.summary(posId);
|
||||
}
|
||||
|
||||
@Public(true)
|
||||
@Get('dummy/:id')
|
||||
async calculate(@Param('id') id: string): Promise<string> {
|
||||
|
|
|
@ -47,6 +47,9 @@ import { TransactionDemographyModel } from './data/models/transaction-demography
|
|||
import { PriceCalculator } from './domain/usecases/calculator/price.calculator';
|
||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||
import { JWT_SECRET } from 'src/core/sessions/constants';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
@Module({
|
||||
exports: [
|
||||
|
@ -56,6 +59,10 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|||
],
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
JwtModule.register({
|
||||
secret: JWT_SECRET,
|
||||
signOptions: { expiresIn: JWT_EXPIRED },
|
||||
}),
|
||||
TypeOrmModule.forFeature(
|
||||
[
|
||||
TransactionModel,
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
||||
import { UserDto } from './dto/user.dto';
|
||||
|
@ -17,6 +18,7 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
|
|||
import { Public } from 'src/core/guards';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { UpdatePasswordUserDto } from './dto/update-password-user.dto';
|
||||
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
||||
|
||||
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
|
||||
@Controller(`v1/${MODULE_NAME.USER}`)
|
||||
|
@ -36,25 +38,23 @@ export class UserDataController {
|
|||
}
|
||||
|
||||
@Patch(':id/active')
|
||||
// TODO => simpan OTP update yang disikim dari request ini
|
||||
@UseGuards(OtpCheckerGuard)
|
||||
async active(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.active(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-active')
|
||||
// TODO => simpan OTP update yang disikim dari request ini
|
||||
async batchActive(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchActive(body.ids);
|
||||
}
|
||||
|
||||
@Patch(':id/confirm')
|
||||
// TODO => simpan OTP update yang disikim dari request ini
|
||||
@UseGuards(OtpCheckerGuard)
|
||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||
return await this.orchestrator.confirm(dataId);
|
||||
}
|
||||
|
||||
@Put('/batch-confirm')
|
||||
// TODO => simpan OTP update yang disikim dari request ini
|
||||
async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
|
||||
return await this.orchestrator.batchConfirm(body.ids);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue