Compare commits
No commits in common. "development" and "1.6.18-alpha.4" have entirely different histories.
developmen
...
1.6.18-alp
|
@ -106,7 +106,6 @@ import { OtpVerificationModule } from './modules/configuration/otp-verification/
|
||||||
import { OtpVerificationModel } from './modules/configuration/otp-verification/data/models/otp-verification.model';
|
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 { OtpVerifierModel } from './modules/configuration/otp-verification/data/models/otp-verifier.model';
|
||||||
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
import { RescheduleVerificationModel } from './modules/booking-online/order/data/models/reschedule-verification.model';
|
||||||
import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -247,8 +246,6 @@ import { OtpCheckerGuard } from './core/guards/domain/otp-checker.guard';
|
||||||
providers: [
|
providers: [
|
||||||
AuthService,
|
AuthService,
|
||||||
PrivilegeService,
|
PrivilegeService,
|
||||||
OtpCheckerGuard,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default all request from client will protect by JWT
|
* By default all request from client will protect by JWT
|
||||||
* if there is some endpoint/function that does'nt require authentication
|
* if there is some endpoint/function that does'nt require authentication
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log({ dataIdentity, otpCode, otpData });
|
|
||||||
if (otpData && otpData?.verified_at) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnprocessableEntityException('OTP not verified.');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -55,7 +55,7 @@ export class ValidateRelationHelper<Entity> {
|
||||||
const relationColumn =
|
const relationColumn =
|
||||||
data[relation.relation]?.[`${relation.singleQuery[0]}`];
|
data[relation.relation]?.[`${relation.singleQuery[0]}`];
|
||||||
if (
|
if (
|
||||||
// !!relationColumn &&
|
!!relationColumn &&
|
||||||
this.mappingValidator(
|
this.mappingValidator(
|
||||||
relationColumn,
|
relationColumn,
|
||||||
relation.singleQuery[1],
|
relation.singleQuery[1],
|
||||||
|
|
|
@ -31,6 +31,4 @@ export enum MODULE_NAME {
|
||||||
|
|
||||||
TIME_GROUPS = 'time-groups',
|
TIME_GROUPS = 'time-groups',
|
||||||
OTP_VERIFICATIONS = 'otp-verification',
|
OTP_VERIFICATIONS = 'otp-verification',
|
||||||
|
|
||||||
OTP_VERIFIER = 'otp-verifier',
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'AddEnumOtpActionTypeAndUpdateColumnOtpVerifier1750045520332';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifier" ADD "is_all_action" boolean NOT NULL DEFAULT false`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TYPE "public"."otp_verifier_action_types_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifier" ADD "action_types" "public"."otp_verifier_action_types_enum" array`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TYPE "public"."otp_verifications_action_type_enum" RENAME TO "otp_verifications_action_type_enum_old"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TYPE "public"."otp_verifications_action_type_enum" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION', 'ACTIVATE_ITEM', 'ACTIVATE_USER', 'UPDATE_ITEM_PRICE', 'UPDATE_ITEM_DETAILS', 'CONFIRM_TRANSACTION')`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`DROP TYPE "public"."otp_verifications_action_type_enum_old"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TYPE "public"."otp_verifications_action_type_enum_old" AS ENUM('CREATE_DISCOUNT', 'CANCEL_TRANSACTION', 'REJECT_RECONCILIATION')`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifications" ALTER COLUMN "action_type" TYPE "public"."otp_verifications_action_type_enum_old" USING "action_type"::"text"::"public"."otp_verifications_action_type_enum_old"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`DROP TYPE "public"."otp_verifications_action_type_enum"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TYPE "public"."otp_verifications_action_type_enum_old" RENAME TO "otp_verifications_action_type_enum"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifier" DROP COLUMN "action_types"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`DROP TYPE "public"."otp_verifier_action_types_enum"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "otp_verifier" DROP COLUMN "is_all_action"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddUsageTypeToItem1750319148269 implements MigrationInterface {
|
|
||||||
name = 'AddUsageTypeToItem1750319148269';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TYPE "public"."item_queues_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" ADD "usage_type" "public"."item_queues_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`CREATE TYPE "public"."items_usage_type_enum" AS ENUM('one_time', 'multiple')`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "items" ADD "usage_type" "public"."items_usage_type_enum" NOT NULL DEFAULT 'one_time'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "usage_type"`);
|
|
||||||
await queryRunner.query(`DROP TYPE "public"."items_usage_type_enum"`);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "item_queues" DROP COLUMN "usage_type"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(`DROP TYPE "public"."item_queues_usage_type_enum"`);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class RemoveItemNameUnique1750834308368 implements MigrationInterface {
|
|
||||||
name = 'RemoveItemNameUnique1750834308368';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "items" DROP CONSTRAINT "UQ_213736582899b3599acaade2cd1"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "items" ADD CONSTRAINT "UQ_213736582899b3599acaade2cd1" UNIQUE ("name")`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -30,7 +30,6 @@ export class BookingItemManager extends IndexItemManager {
|
||||||
const parent = super.selects;
|
const parent = super.selects;
|
||||||
return [
|
return [
|
||||||
...parent,
|
...parent,
|
||||||
`${this.tableName}.image_url`,
|
|
||||||
'item_rates.id',
|
'item_rates.id',
|
||||||
'item_rates.price',
|
'item_rates.price',
|
||||||
'item_rates.season_period_id',
|
'item_rates.season_period_id',
|
||||||
|
@ -42,11 +41,8 @@ export class BookingItemManager extends IndexItemManager {
|
||||||
const { data, total } = result;
|
const { data, total } = result;
|
||||||
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
||||||
const items = data.map((item) => {
|
const items = data.map((item) => {
|
||||||
const currentRate = item.item_rates.find((rate) =>
|
|
||||||
this.filterParam.season_period_ids?.includes(rate.season_period_id),
|
|
||||||
);
|
|
||||||
const { item_rates, ...rest } = item;
|
const { item_rates, ...rest } = item;
|
||||||
const rate = currentRate?.['price'] ?? rest.base_price;
|
const rate = item_rates?.[0]?.['price'] ?? rest.base_price;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
base_price: hasRates ? rate : rest.base_price,
|
base_price: hasRates ? rate : rest.base_price,
|
||||||
|
@ -60,8 +56,11 @@ export class BookingItemManager extends IndexItemManager {
|
||||||
): SelectQueryBuilder<ItemEntity> {
|
): SelectQueryBuilder<ItemEntity> {
|
||||||
const query = super.setQueryFilter(queryBuilder);
|
const query = super.setQueryFilter(queryBuilder);
|
||||||
|
|
||||||
query.andWhere(`${this.tableName}.status = 'active'`);
|
if (this.filterParam.season_period_ids) {
|
||||||
|
query.andWhere(`item_rates.season_period_id In (:...seasonIds)`, {
|
||||||
|
seasonIds: this.filterParam.season_period_ids,
|
||||||
|
});
|
||||||
|
}
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ export class CreateBookingManager extends CreateTransactionManager {
|
||||||
time: this.data.booking_date,
|
time: this.data.booking_date,
|
||||||
id: this.data.id,
|
id: this.data.id,
|
||||||
},
|
},
|
||||||
this.data.payment_total,
|
|
||||||
`snap/v4/redirection/${this.data.payment_midtrans_token}`,
|
`snap/v4/redirection/${this.data.payment_midtrans_token}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ export class ItemController {
|
||||||
): Promise<PaginationResponse<ItemEntity>> {
|
): Promise<PaginationResponse<ItemEntity>> {
|
||||||
params.limit = 1000;
|
params.limit = 1000;
|
||||||
params.show_to_booking = true;
|
params.show_to_booking = true;
|
||||||
params.all_item = true;
|
|
||||||
this.indexManager.setFilterParam(params);
|
this.indexManager.setFilterParam(params);
|
||||||
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
this.indexManager.setService(this.serviceData, TABLE_NAME.ITEM);
|
||||||
await this.indexManager.execute();
|
await this.indexManager.execute();
|
||||||
|
|
|
@ -26,7 +26,6 @@ import { RescheduleVerificationManager } from '../domain/usecases/managers/resch
|
||||||
import { RescheduleManager } from '../domain/usecases/managers/reschedule.manager';
|
import { RescheduleManager } from '../domain/usecases/managers/reschedule.manager';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
import { STATUS } from 'src/core/strings/constants/base.constants';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
|
||||||
|
|
||||||
@ApiTags('Booking Order')
|
@ApiTags('Booking Order')
|
||||||
@Controller('v1/booking')
|
@Controller('v1/booking')
|
||||||
|
@ -157,23 +156,21 @@ export class BookingOrderController {
|
||||||
|
|
||||||
const usageItems = items.map((item) => {
|
const usageItems = items.map((item) => {
|
||||||
const itemData = item.item;
|
const itemData = item.item;
|
||||||
if (itemData.time_group) {
|
const timeGroupData = itemData.time_group;
|
||||||
const timeGroupData = itemData.time_group;
|
const {
|
||||||
const {
|
id: groupId,
|
||||||
id: groupId,
|
name,
|
||||||
name,
|
start_time,
|
||||||
start_time,
|
end_time,
|
||||||
end_time,
|
max_usage_time,
|
||||||
max_usage_time,
|
} = timeGroupData;
|
||||||
} = timeGroupData;
|
timeGroup = {
|
||||||
timeGroup = {
|
id: groupId,
|
||||||
id: groupId,
|
name,
|
||||||
name,
|
start_time,
|
||||||
start_time,
|
end_time,
|
||||||
end_time,
|
max_usage_time,
|
||||||
max_usage_time,
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
item_id,
|
item_id,
|
||||||
|
@ -244,31 +241,4 @@ export class BookingOrderController {
|
||||||
const buffer = Buffer.from(base64Data, 'base64');
|
const buffer = Buffer.from(base64Data, 'base64');
|
||||||
res.send(buffer);
|
res.send(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('resend-notification/:id')
|
|
||||||
async resendNotification(@Param('id') id: string) {
|
|
||||||
try {
|
|
||||||
const transaction = await this.serviceData.getOneByOptions({
|
|
||||||
where: { id },
|
|
||||||
});
|
|
||||||
|
|
||||||
const whatsappService = new WhatsappService();
|
|
||||||
const formattedDate = moment(transaction.booking_date);
|
|
||||||
const payload = {
|
|
||||||
id: transaction.id,
|
|
||||||
phone: transaction.customer_phone,
|
|
||||||
code: transaction.invoice_code,
|
|
||||||
name: transaction.customer_name,
|
|
||||||
time: formattedDate.valueOf(),
|
|
||||||
};
|
|
||||||
await whatsappService.bookingCreated(payload);
|
|
||||||
return {
|
|
||||||
message: 'Notification sent successfully',
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
throw new UnprocessableEntityException({
|
|
||||||
message: 'Failed to send notification',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ 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 { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
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 { TransactionTaxModel } from 'src/modules/transaction/transaction/data/models/transaction-tax.model';
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -19,7 +19,6 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [GoogleCalendarController],
|
controllers: [GoogleCalendarController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { TransactionDataService } from 'src/modules/transaction/transaction/data
|
||||||
import { PaymentTransactionHandler } from './domain/handlers/payment-transaction.handler';
|
import { PaymentTransactionHandler } from './domain/handlers/payment-transaction.handler';
|
||||||
import { MailTemplateController } from './infrastructure/mail.controller';
|
import { MailTemplateController } from './infrastructure/mail.controller';
|
||||||
import { PdfMakeManager } from '../export/domain/managers/pdf-make.manager';
|
import { PdfMakeManager } from '../export/domain/managers/pdf-make.manager';
|
||||||
import { CouchModule } from '../couch/couch.module';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -19,7 +19,6 @@ import { CouchModule } from '../couch/couch.module';
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [MailTemplateController],
|
controllers: [MailTemplateController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -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 { OtpVerifierEntity } from '../../domain/entities/otp-verification.entity';
|
||||||
OTP_ACTION_TYPE,
|
|
||||||
OtpVerifierEntity,
|
|
||||||
} from '../../domain/entities/otp-verification.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';
|
||||||
|
|
||||||
|
@ -16,10 +13,4 @@ export class OtpVerifierModel
|
||||||
|
|
||||||
@Column({ type: 'varchar', nullable: false })
|
@Column({ type: 'varchar', nullable: false })
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
|
|
||||||
@Column({ default: false })
|
|
||||||
is_all_action: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'enum', enum: OTP_ACTION_TYPE, array: true, nullable: true })
|
|
||||||
action_types: OTP_ACTION_TYPE[] | null;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { OtpVerificationModel } from '../models/otp-verification.model';
|
import { OtpVerificationModel } from '../models/otp-verification.model';
|
||||||
import {
|
import {
|
||||||
OTP_ACTION_TYPE,
|
|
||||||
OtpRequestEntity,
|
OtpRequestEntity,
|
||||||
OtpVerificationEntity,
|
OtpVerificationEntity,
|
||||||
OtpVerifierEntity,
|
OtpVerifierEntity,
|
||||||
|
@ -38,28 +37,16 @@ export class OtpVerificationService {
|
||||||
return moment().valueOf(); // epoch millis verification time (now)
|
return moment().valueOf(); // epoch millis verification time (now)
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateHeaderTemplate(payload) {
|
private generateOTPMsgTemplate(payload) {
|
||||||
const label = payload.action_type;
|
const { userRequest, newOtp } = payload;
|
||||||
|
const header = newOtp.action_type.split('_').join(' ');
|
||||||
// Optional logic to override label based on action type.
|
const otpCode = newOtp?.otp_code;
|
||||||
// e.g., if (payload.action_type === OTP_ACTION_TYPE.CONFIRM_TRANSACTION) label = 'CONFIRM_BOOKING_TRANSACTION'
|
const username = userRequest?.username;
|
||||||
|
const otpType = newOtp.action_type
|
||||||
const header = label.split('_').join(' ');
|
|
||||||
const type = label
|
|
||||||
.split('_')
|
.split('_')
|
||||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
||||||
.join(' ');
|
.join(' ');
|
||||||
|
|
||||||
return { header, type };
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateOTPMsgTemplate(payload) {
|
|
||||||
const { userRequest, newOtp } = payload;
|
|
||||||
const { header, type } = this.generateHeaderTemplate(newOtp);
|
|
||||||
|
|
||||||
const otpCode = newOtp?.otp_code;
|
|
||||||
const username = userRequest?.username;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'general_flow',
|
name: 'general_flow',
|
||||||
language: { code: 'id' },
|
language: { code: 'id' },
|
||||||
|
@ -90,7 +77,7 @@ export class OtpVerificationService {
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
parameter_name: 'type',
|
parameter_name: 'type',
|
||||||
text: type,
|
text: otpType,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -159,12 +146,10 @@ export class OtpVerificationService {
|
||||||
|
|
||||||
// save otp to database
|
// save otp to database
|
||||||
await this.otpVerificationRepo.save(newOtp);
|
await this.otpVerificationRepo.save(newOtp);
|
||||||
const verifiers: OtpVerifierEntity[] = await this.getVerifier([
|
const verifiers: OtpVerifierEntity[] = await this.otpVerifierRepo.find();
|
||||||
payload.action_type,
|
|
||||||
]);
|
|
||||||
const notificationService = new WhatsappService();
|
const notificationService = new WhatsappService();
|
||||||
|
|
||||||
verifiers?.map((v) => {
|
verifiers.map((v) => {
|
||||||
notificationService.sendTemplateMessage({
|
notificationService.sendTemplateMessage({
|
||||||
phone: v.phone_number,
|
phone: v.phone_number,
|
||||||
templateMsg: this.generateOTPMsgTemplate({ userRequest, newOtp }),
|
templateMsg: this.generateOTPMsgTemplate({ userRequest, newOtp }),
|
||||||
|
@ -253,14 +238,4 @@ export class OtpVerificationService {
|
||||||
)
|
)
|
||||||
.getOne();
|
.getOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVerifier(actions: OTP_ACTION_TYPE[]) {
|
|
||||||
const tableALias = TABLE_NAME.OTP_VERIFIER;
|
|
||||||
const results = await this.otpVerifierRepo
|
|
||||||
.createQueryBuilder(tableALias)
|
|
||||||
.where(`${tableALias}.is_all_action = :isAll`, { isAll: true })
|
|
||||||
.orWhere(`${tableALias}.action_types && :actions`, { actions })
|
|
||||||
.getMany();
|
|
||||||
return results ?? [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { OtpVerifierModel } from '../models/otp-verifier.model';
|
|
||||||
import { OtpVerifierCreateDto } from '../../infrastructure/dto/otp-verification.dto';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class OtpVerifierService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(OtpVerifierModel)
|
|
||||||
private readonly otpVerifierRepo: Repository<OtpVerifierModel>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async create(payload: OtpVerifierCreateDto) {
|
|
||||||
const dateNow = moment().valueOf();
|
|
||||||
|
|
||||||
return this.otpVerifierRepo.save({
|
|
||||||
...payload,
|
|
||||||
created_at: dateNow,
|
|
||||||
updated_at: dateNow,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,14 +4,6 @@ export enum OTP_ACTION_TYPE {
|
||||||
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
|
CREATE_DISCOUNT = 'CREATE_DISCOUNT',
|
||||||
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
|
CANCEL_TRANSACTION = 'CANCEL_TRANSACTION',
|
||||||
REJECT_RECONCILIATION = 'REJECT_RECONCILIATION',
|
REJECT_RECONCILIATION = 'REJECT_RECONCILIATION',
|
||||||
|
|
||||||
ACTIVATE_USER = 'ACTIVATE_USER',
|
|
||||||
|
|
||||||
ACTIVATE_ITEM = 'ACTIVATE_ITEM',
|
|
||||||
UPDATE_ITEM_PRICE = 'UPDATE_ITEM_PRICE',
|
|
||||||
UPDATE_ITEM_DETAILS = 'UPDATE_ITEM_DETAILS',
|
|
||||||
|
|
||||||
CONFIRM_TRANSACTION = 'CONFIRM_TRANSACTION',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum OTP_SOURCE {
|
export enum OTP_SOURCE {
|
||||||
|
@ -45,6 +37,4 @@ export interface OtpVerifyEntity extends OtpRequestEntity {
|
||||||
export interface OtpVerifierEntity {
|
export interface OtpVerifierEntity {
|
||||||
name: string;
|
name: string;
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
is_all_action?: boolean;
|
|
||||||
action_types?: OTP_ACTION_TYPE[] | null;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
import {
|
import { IsNotEmpty, IsString, ValidateIf } from 'class-validator';
|
||||||
IsArray,
|
|
||||||
IsBoolean,
|
|
||||||
IsEnum,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsOptional,
|
|
||||||
IsPhoneNumber,
|
|
||||||
IsString,
|
|
||||||
ValidateIf,
|
|
||||||
} from 'class-validator';
|
|
||||||
import {
|
import {
|
||||||
OTP_ACTION_TYPE,
|
OTP_ACTION_TYPE,
|
||||||
OTP_SOURCE,
|
OTP_SOURCE,
|
||||||
|
@ -15,7 +6,6 @@ import {
|
||||||
OtpVerifyEntity,
|
OtpVerifyEntity,
|
||||||
} from '../../domain/entities/otp-verification.entity';
|
} from '../../domain/entities/otp-verification.entity';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
|
|
||||||
export class OtpRequestDto implements OtpRequestEntity {
|
export class OtpRequestDto implements OtpRequestEntity {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
@ -63,50 +53,3 @@ export class OtpVerifyDto extends OtpRequestDto implements OtpVerifyEntity {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
otp_code: string;
|
otp_code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OtpVerifierCreateDto {
|
|
||||||
@ApiProperty({
|
|
||||||
example: 'Item Manager',
|
|
||||||
description: 'Nama verifier, opsional.',
|
|
||||||
})
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
name?: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: '6281234567890',
|
|
||||||
description: 'Nomor telepon verifier dalam format internasional (E.164).',
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
@IsPhoneNumber('ID')
|
|
||||||
phone_number: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
example: false,
|
|
||||||
description:
|
|
||||||
'True jika verifier boleh memverifikasi semua aksi tanpa batas.',
|
|
||||||
})
|
|
||||||
@IsBoolean()
|
|
||||||
is_all_action: boolean;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
isArray: true,
|
|
||||||
enum: OTP_ACTION_TYPE,
|
|
||||||
example: [
|
|
||||||
'CREATE_DISCOUNT',
|
|
||||||
'CANCEL_TRANSACTION',
|
|
||||||
'REJECT_RECONCILIATION',
|
|
||||||
'ACTIVATE_ITEM',
|
|
||||||
'ACTIVATE_USER',
|
|
||||||
'UPDATE_ITEM_PRICE',
|
|
||||||
'UPDATE_ITEM_DETAILS',
|
|
||||||
'CONFIRM_TRANSACTION',
|
|
||||||
],
|
|
||||||
description: 'Daftar tipe aksi yang boleh diverifikasi, jika bukan semua.',
|
|
||||||
})
|
|
||||||
@IsOptional()
|
|
||||||
@IsArray()
|
|
||||||
@IsEnum(OTP_ACTION_TYPE, { each: true })
|
|
||||||
@Type(() => String)
|
|
||||||
action_types?: OTP_ACTION_TYPE[];
|
|
||||||
}
|
|
||||||
|
|
|
@ -32,8 +32,9 @@ export class OtpAuthGuard implements CanActivate {
|
||||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
const request = context.switchToHttp().getRequest();
|
const request = context.switchToHttp().getRequest();
|
||||||
const jwtAuth = request.headers['authorization'];
|
const jwtAuth = request.headers['authorization'];
|
||||||
const basicAuth = request.headers['x-basic-authorization'];
|
const basicAuth = request.headers['basic_authorization'];
|
||||||
|
|
||||||
|
console.log({ jwtAuth, basicAuth });
|
||||||
// 1. Cek OTP Auth (basic_authorization header)
|
// 1. Cek OTP Auth (basic_authorization header)
|
||||||
if (basicAuth) {
|
if (basicAuth) {
|
||||||
try {
|
try {
|
|
@ -7,18 +7,14 @@ import {
|
||||||
Req,
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { OtpVerificationService } from '../data/services/otp-verification.service';
|
import { OtpVerificationService } from '../data/services/otp-verification.service';
|
||||||
import {
|
import { OtpRequestDto, OtpVerifyDto } from './dto/otp-verification.dto';
|
||||||
OtpRequestDto,
|
import { OtpAuthGuard } from './guards/otp-auth-guard';
|
||||||
OtpVerifierCreateDto,
|
|
||||||
OtpVerifyDto,
|
|
||||||
} from './dto/otp-verification.dto';
|
|
||||||
import { OtpAuthGuard } from './guards/otp-auth.guard';
|
|
||||||
import { OtpVerifierService } from '../data/services/otp-verifier.service';
|
|
||||||
|
|
||||||
|
//TODO implementation auth
|
||||||
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.OTP_VERIFICATIONS.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
|
@Controller(`v1/${MODULE_NAME.OTP_VERIFICATIONS}`)
|
||||||
@Public()
|
@Public()
|
||||||
|
@ -44,17 +40,3 @@ export class OtpVerificationController {
|
||||||
return this.otpVerificationService.getActiveOtp(ref_or_target_id);
|
return this.otpVerificationService.getActiveOtp(ref_or_target_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.OTP_VERIFIER.split('-').join(' ')} - data`)
|
|
||||||
@Controller(`v1/${MODULE_NAME.OTP_VERIFIER}`)
|
|
||||||
@ApiBearerAuth('JWT')
|
|
||||||
@Public(false)
|
|
||||||
export class OtpVerifierController {
|
|
||||||
constructor(private readonly otpVerifierService: OtpVerifierService) {}
|
|
||||||
|
|
||||||
@Post()
|
|
||||||
@ExcludePrivilege()
|
|
||||||
async create(@Body() body: OtpVerifierCreateDto) {
|
|
||||||
return await this.otpVerifierService.create(body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,18 +4,14 @@ import { ConfigModule } from '@nestjs/config';
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { OtpVerificationModel } from './data/models/otp-verification.model';
|
import { OtpVerificationModel } from './data/models/otp-verification.model';
|
||||||
import {
|
import { OtpVerificationController } from './infrastructure/otp-verification-data.controller';
|
||||||
OtpVerificationController,
|
|
||||||
OtpVerifierController,
|
|
||||||
} from './infrastructure/otp-verification-data.controller';
|
|
||||||
import { OtpVerificationService } from './data/services/otp-verification.service';
|
import { OtpVerificationService } from './data/services/otp-verification.service';
|
||||||
import { OtpVerifierModel } from './data/models/otp-verifier.model';
|
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 { JwtModule } from '@nestjs/jwt';
|
||||||
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
import { JWT_EXPIRED } from 'src/core/sessions/constants';
|
||||||
import { JWT_SECRET } from 'src/core/sessions/constants';
|
import { JWT_SECRET } from 'src/core/sessions/constants';
|
||||||
import { OtpVerifierService } from './data/services/otp-verifier.service';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -31,7 +27,7 @@ import { OtpVerifierService } from './data/services/otp-verifier.service';
|
||||||
signOptions: { expiresIn: JWT_EXPIRED },
|
signOptions: { expiresIn: JWT_EXPIRED },
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
controllers: [OtpVerificationController, OtpVerifierController],
|
controllers: [OtpVerificationController],
|
||||||
providers: [OtpAuthGuard, OtpVerificationService, OtpVerifierService],
|
providers: [OtpAuthGuard, OtpVerificationService],
|
||||||
})
|
})
|
||||||
export class OtpVerificationModule {}
|
export class OtpVerificationModule {}
|
||||||
|
|
|
@ -5,8 +5,3 @@ export enum ItemType {
|
||||||
FREE_GIFT = 'free gift',
|
FREE_GIFT = 'free gift',
|
||||||
OTHER = 'other',
|
OTHER = 'other',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum UsageType {
|
|
||||||
ONE_TIME = 'one_time',
|
|
||||||
MULTIPLE = 'multiple',
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
import { ItemQueueEntity } from '../../domain/entities/item-queue.entity';
|
||||||
import { Column, Entity, OneToMany } from 'typeorm';
|
import { Column, Entity, OneToMany } from 'typeorm';
|
||||||
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
|
||||||
import { ItemType, UsageType } from '../../constants';
|
import { ItemType } from '../../constants';
|
||||||
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
import { ItemModel } from 'src/modules/item-related/item/data/models/item.model';
|
||||||
|
|
||||||
@Entity(TABLE_NAME.ITEM_QUEUE)
|
@Entity(TABLE_NAME.ITEM_QUEUE)
|
||||||
|
@ -29,13 +29,6 @@ export class ItemQueueModel
|
||||||
})
|
})
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
|
||||||
@Column('enum', {
|
|
||||||
name: 'usage_type',
|
|
||||||
enum: UsageType,
|
|
||||||
default: UsageType.ONE_TIME,
|
|
||||||
})
|
|
||||||
usage_type: UsageType;
|
|
||||||
|
|
||||||
@OneToMany(() => ItemModel, (model) => model.item_queue, {
|
@OneToMany(() => ItemModel, (model) => model.item_queue, {
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
import { ItemType, UsageType } from '../../constants';
|
import { ItemType } from '../../constants';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
|
||||||
export interface ItemQueueEntity extends BaseStatusEntity {
|
export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
|
@ -11,5 +11,4 @@ export interface ItemQueueEntity extends BaseStatusEntity {
|
||||||
items: ItemEntity[];
|
items: ItemEntity[];
|
||||||
use_notification?: boolean;
|
use_notification?: boolean;
|
||||||
requiring_notification?: boolean;
|
requiring_notification?: boolean;
|
||||||
usage_type?: UsageType;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,6 @@ export class DetailItemQueueManager extends BaseDetailManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
`${this.tableName}.use_notification`,
|
`${this.tableName}.use_notification`,
|
||||||
`${this.tableName}.requiring_notification`,
|
`${this.tableName}.requiring_notification`,
|
||||||
`${this.tableName}.usage_type`,
|
|
||||||
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
|
|
|
@ -43,7 +43,7 @@ export class IndexItemQueueManager extends BaseIndexManager<ItemQueueEntity> {
|
||||||
`${this.tableName}.call_preparation`,
|
`${this.tableName}.call_preparation`,
|
||||||
`${this.tableName}.use_notification`,
|
`${this.tableName}.use_notification`,
|
||||||
`${this.tableName}.requiring_notification`,
|
`${this.tableName}.requiring_notification`,
|
||||||
`${this.tableName}.usage_type`,
|
|
||||||
`items.id`,
|
`items.id`,
|
||||||
`items.created_at`,
|
`items.created_at`,
|
||||||
`items.status`,
|
`items.status`,
|
||||||
|
|
|
@ -18,14 +18,13 @@ import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/it
|
||||||
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
import { GateModel } from 'src/modules/web-information/gate/data/models/gate.model';
|
||||||
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
import { ItemQueueModel } from 'src/modules/item-related/item-queue/data/models/item-queue.model';
|
||||||
import { TimeGroupModel } from 'src/modules/item-related/time-group/data/models/time-group.model';
|
import { TimeGroupModel } from 'src/modules/item-related/time-group/data/models/time-group.model';
|
||||||
import { UsageType } from 'src/modules/item-related/item-queue/constants';
|
|
||||||
|
|
||||||
@Entity(TABLE_NAME.ITEM)
|
@Entity(TABLE_NAME.ITEM)
|
||||||
export class ItemModel
|
export class ItemModel
|
||||||
extends BaseStatusModel<ItemEntity>
|
extends BaseStatusModel<ItemEntity>
|
||||||
implements ItemEntity
|
implements ItemEntity
|
||||||
{
|
{
|
||||||
@Column('varchar', { name: 'name' })
|
@Column('varchar', { name: 'name', unique: true })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column('text', { name: 'booking_description', nullable: true })
|
@Column('text', { name: 'booking_description', nullable: true })
|
||||||
|
@ -44,13 +43,6 @@ export class ItemModel
|
||||||
})
|
})
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
|
||||||
@Column('enum', {
|
|
||||||
name: 'usage_type',
|
|
||||||
enum: UsageType,
|
|
||||||
default: UsageType.ONE_TIME,
|
|
||||||
})
|
|
||||||
usage_type: UsageType;
|
|
||||||
|
|
||||||
@Column('bigint', { name: 'hpp', nullable: true })
|
@Column('bigint', { name: 'hpp', nullable: true })
|
||||||
hpp: number;
|
hpp: number;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.e
|
||||||
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
||||||
import { LimitType } from '../../constants';
|
import { LimitType } from '../../constants';
|
||||||
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
||||||
import { UsageType } from 'src/modules/item-related/item-queue/constants';
|
|
||||||
export interface ItemEntity extends BaseStatusEntity {
|
export interface ItemEntity extends BaseStatusEntity {
|
||||||
name: string;
|
name: string;
|
||||||
item_type: ItemType;
|
item_type: ItemType;
|
||||||
|
@ -20,7 +20,6 @@ export interface ItemEntity extends BaseStatusEntity {
|
||||||
show_to_booking: boolean;
|
show_to_booking: boolean;
|
||||||
breakdown_bundling?: boolean;
|
breakdown_bundling?: boolean;
|
||||||
booking_description?: string;
|
booking_description?: string;
|
||||||
usage_type?: UsageType;
|
|
||||||
|
|
||||||
item_rates?: ItemRateEntity[] | any[];
|
item_rates?: ItemRateEntity[] | any[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import { ItemEntity } from '../../entities/item.entity';
|
||||||
import { ItemModel } from '../../../data/models/item.model';
|
import { ItemModel } from '../../../data/models/item.model';
|
||||||
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
import { BaseCreateManager } from 'src/core/modules/domain/usecase/managers/base-create.manager';
|
||||||
import { ItemCreatedEvent } from '../../entities/event/item-created.event';
|
import { ItemCreatedEvent } from '../../entities/event/item-created.event';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
||||||
|
@ -30,37 +29,11 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
get validateRelations(): validateRelations[] {
|
||||||
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
|
return [];
|
||||||
const relation =
|
|
||||||
this.data.bundling_items?.length > 0
|
|
||||||
? 'bundling_items'
|
|
||||||
: 'bundling_parents';
|
|
||||||
return timeGroupId != null
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
relation: relation,
|
|
||||||
singleQuery: ['time_group_id', '!=', timeGroupId],
|
|
||||||
message: `Gagal Update! Time group item dan bundling item tidak sama`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get uniqueColumns(): columnUniques[] {
|
get uniqueColumns(): columnUniques[] {
|
||||||
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
|
return [{ column: 'name' }];
|
||||||
return timeGroupId != null
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
column: 'name',
|
|
||||||
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
column: 'name',
|
|
||||||
query: `(status = '${STATUS.ACTIVE}')`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get eventTopics(): EventTopics[] {
|
get eventTopics(): EventTopics[] {
|
||||||
|
|
|
@ -53,7 +53,6 @@ export class DetailItemManager extends BaseDetailManager<ItemEntity> {
|
||||||
`${this.tableName}.total_price`,
|
`${this.tableName}.total_price`,
|
||||||
`${this.tableName}.base_price`,
|
`${this.tableName}.base_price`,
|
||||||
`${this.tableName}.use_queue`,
|
`${this.tableName}.use_queue`,
|
||||||
`${this.tableName}.usage_type`,
|
|
||||||
`${this.tableName}.show_to_booking`,
|
`${this.tableName}.show_to_booking`,
|
||||||
`${this.tableName}.breakdown_bundling`,
|
`${this.tableName}.breakdown_bundling`,
|
||||||
`${this.tableName}.play_estimation`,
|
`${this.tableName}.play_estimation`,
|
||||||
|
|
|
@ -55,7 +55,6 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
`${this.tableName}.play_estimation`,
|
`${this.tableName}.play_estimation`,
|
||||||
`${this.tableName}.show_to_booking`,
|
`${this.tableName}.show_to_booking`,
|
||||||
`${this.tableName}.booking_description`,
|
`${this.tableName}.booking_description`,
|
||||||
`${this.tableName}.usage_type`,
|
|
||||||
|
|
||||||
`item_category.id`,
|
`item_category.id`,
|
||||||
`item_category.name`,
|
`item_category.name`,
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
columnUniques,
|
columnUniques,
|
||||||
validateRelations,
|
validateRelations,
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
||||||
|
@ -40,31 +39,11 @@ export class UpdateItemManager extends BaseUpdateManager<ItemEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
get validateRelations(): validateRelations[] {
|
get validateRelations(): validateRelations[] {
|
||||||
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
|
return [];
|
||||||
const relation =
|
|
||||||
this.data.bundling_items?.length > 0
|
|
||||||
? 'bundling_items'
|
|
||||||
: 'bundling_parents';
|
|
||||||
|
|
||||||
return timeGroupId != null
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
relation: relation,
|
|
||||||
singleQuery: ['time_group_id', '!=', timeGroupId],
|
|
||||||
message: `Gagal Update! Time group item dan bundling item tidak sama`,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get uniqueColumns(): columnUniques[] {
|
get uniqueColumns(): columnUniques[] {
|
||||||
const timeGroupId = this.data.time_group_id ?? this.data.time_group?.id;
|
return [];
|
||||||
return [
|
|
||||||
{
|
|
||||||
column: 'name',
|
|
||||||
query: `(status = '${STATUS.ACTIVE}' AND (${this.tableName}.time_group_id Is Null OR ${this.tableName}.time_group_id = '${timeGroupId}'))`,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get entityTarget(): any {
|
get entityTarget(): any {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ItemDataOrchestrator } from '../domain/usecases/item-data.orchestrator';
|
import { ItemDataOrchestrator } from '../domain/usecases/item-data.orchestrator';
|
||||||
import { ItemDto } from './dto/item.dto';
|
import { ItemDto } from './dto/item.dto';
|
||||||
|
@ -17,7 +16,6 @@ import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { UpdateItemPriceDto } from './dto/update-item-price.dto';
|
import { UpdateItemPriceDto } from './dto/update-item-price.dto';
|
||||||
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.ITEM.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.ITEM.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.ITEM}`)
|
@Controller(`v1/${MODULE_NAME.ITEM}`)
|
||||||
|
@ -43,7 +41,6 @@ export class ItemDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/active')
|
@Patch(':id/active')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async active(@Param('id') dataId: string): Promise<string> {
|
async active(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.active(dataId);
|
return await this.orchestrator.active(dataId);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +51,6 @@ export class ItemDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +71,6 @@ export class ItemDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id')
|
@Put(':id')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async update(
|
async update(
|
||||||
@Param('id') dataId: string,
|
@Param('id') dataId: string,
|
||||||
@Body() data: ItemDto,
|
@Body() data: ItemDto,
|
||||||
|
|
|
@ -6,8 +6,6 @@ import {
|
||||||
Param,
|
Param,
|
||||||
RelationParam,
|
RelationParam,
|
||||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||||
import * as moment from 'moment';
|
|
||||||
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// Implementasikan filter by start_time, end_timen, dan max_usage_time
|
// Implementasikan filter by start_time, end_timen, dan max_usage_time
|
||||||
|
@ -15,10 +13,6 @@ import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntity> {
|
export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntity> {
|
||||||
async prepareData(): Promise<void> {
|
async prepareData(): Promise<void> {
|
||||||
Object.assign(this.filterParam, {
|
|
||||||
order_by: `${this.tableName}.start_time`,
|
|
||||||
order_type: ORDER_TYPE.ASC,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,15 +60,6 @@ export class IndexPublicTimeGroupManager extends BaseIndexManager<TimeGroupEntit
|
||||||
queryBuilder: SelectQueryBuilder<TimeGroupEntity>,
|
queryBuilder: SelectQueryBuilder<TimeGroupEntity>,
|
||||||
): SelectQueryBuilder<TimeGroupEntity> {
|
): SelectQueryBuilder<TimeGroupEntity> {
|
||||||
queryBuilder.andWhere(`items.id is not null`);
|
queryBuilder.andWhere(`items.id is not null`);
|
||||||
|
|
||||||
if (!this.filterParam.date) {
|
|
||||||
const currentTime = moment().utcOffset('+07:00').format('HH:mm:ss');
|
|
||||||
|
|
||||||
queryBuilder.andWhere(`${this.tableName}.end_time >= :current_time`, {
|
|
||||||
current_time: currentTime,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,4 @@ export class FilterTimeGroupDto
|
||||||
@ApiProperty({ type: 'string', required: false })
|
@ApiProperty({ type: 'string', required: false })
|
||||||
@ValidateIf((body) => body.max_usage_time_to)
|
@ValidateIf((body) => body.max_usage_time_to)
|
||||||
max_usage_time_to: string;
|
max_usage_time_to: string;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Date,
|
|
||||||
required: false,
|
|
||||||
example: '2024-01-01',
|
|
||||||
})
|
|
||||||
@ValidateIf((body) => body.date)
|
|
||||||
date: Date;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,27 +51,27 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (!order) {
|
if (!order) {
|
||||||
// const { customer_name, customer_phone } =
|
const { customer_name, customer_phone } =
|
||||||
// await this.transaction.findOneOrFail({
|
await this.transaction.findOneOrFail({
|
||||||
// where: {
|
where: {
|
||||||
// id,
|
id,
|
||||||
// },
|
},
|
||||||
// });
|
});
|
||||||
|
|
||||||
// const start = moment().startOf('day').valueOf();
|
const start = moment().startOf('day').valueOf();
|
||||||
// const end = moment().endOf('day').valueOf();
|
const end = moment().endOf('day').valueOf();
|
||||||
// const order = this.order.findOneOrFail({
|
const order = this.order.findOneOrFail({
|
||||||
// relations: ['tickets'],
|
relations: ['tickets'],
|
||||||
// where: {
|
where: {
|
||||||
// customer: customer_name,
|
customer: customer_name,
|
||||||
// phone: customer_phone,
|
phone: customer_phone,
|
||||||
// date: Between(start, end),
|
date: Between(start, end),
|
||||||
// },
|
},
|
||||||
// });
|
});
|
||||||
|
|
||||||
// return order;
|
return order;
|
||||||
// }
|
}
|
||||||
|
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class QueueOrchestrator {
|
||||||
return order;
|
return order;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new UnauthorizedException({
|
throw new UnauthorizedException({
|
||||||
message: 'Invoice tidak ditemukan untuk tanggal hari ini',
|
message: 'Invoice tidak ditemukan',
|
||||||
error: 'INVOICE_NOT_FOUND',
|
error: 'INVOICE_NOT_FOUND',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 { QueueTimeFormula } from './domain/usecases/formula/queue-time.formula';
|
||||||
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
import { QueueJobController } from './infrastructure/controllers/queue-job.controller';
|
||||||
import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
import { GenerateQueueManager } from './domain/usecases/generate-queue.manager';
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -57,7 +57,6 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [QueueController, QueueAdminController, QueueJobController],
|
controllers: [QueueController, QueueAdminController, QueueJobController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { SeasonPeriodDataOrchestrator } from '../domain/usecases/season-period-data.orchestrator';
|
import { SeasonPeriodDataOrchestrator } from '../domain/usecases/season-period-data.orchestrator';
|
||||||
import { SeasonPeriodDto } from './dto/season-period.dto';
|
import { SeasonPeriodDto } from './dto/season-period.dto';
|
||||||
|
@ -19,7 +18,6 @@ import { Public } from 'src/core/guards';
|
||||||
import { UpdateSeasonPeriodDto } from './dto/update-season-period.dto';
|
import { UpdateSeasonPeriodDto } from './dto/update-season-period.dto';
|
||||||
import { UpdateSeasonPeriodItemDto } from './dto/update-season-period-item.dto';
|
import { UpdateSeasonPeriodItemDto } from './dto/update-season-period-item.dto';
|
||||||
import { UpdateSeasonPriceDto } from './dto/update-season-price.dto';
|
import { UpdateSeasonPriceDto } from './dto/update-season-price.dto';
|
||||||
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.SEASON_PERIOD.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.SEASON_PERIOD.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.SEASON_PERIOD}`)
|
@Controller(`v1/${MODULE_NAME.SEASON_PERIOD}`)
|
||||||
|
@ -29,13 +27,11 @@ export class SeasonPeriodDataController {
|
||||||
constructor(private orchestrator: SeasonPeriodDataOrchestrator) {}
|
constructor(private orchestrator: SeasonPeriodDataOrchestrator) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async create(@Body() data: SeasonPeriodDto): Promise<SeasonPeriodEntity> {
|
async create(@Body() data: SeasonPeriodDto): Promise<SeasonPeriodEntity> {
|
||||||
return await this.orchestrator.create(data);
|
return await this.orchestrator.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/update-price')
|
@Post('/update-price')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async updatePrice(@Body() body: UpdateSeasonPriceDto): Promise<BatchResult> {
|
async updatePrice(@Body() body: UpdateSeasonPriceDto): Promise<BatchResult> {
|
||||||
return await this.orchestrator.updatePrice(body);
|
return await this.orchestrator.updatePrice(body);
|
||||||
}
|
}
|
||||||
|
@ -84,9 +80,7 @@ export class SeasonPeriodDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pemisahan update data dengan update items dikarenakan payload (based on tampilan) berbeda
|
// pemisahan update data dengan update items dikarenakan payload (based on tampilan) berbeda
|
||||||
// TODO => simpan OTP update yang disikim dari request ini
|
|
||||||
@Put(':id/items')
|
@Put(':id/items')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async updateItems(
|
async updateItems(
|
||||||
@Param('id') dataId: string,
|
@Param('id') dataId: string,
|
||||||
@Body() data: UpdateSeasonPeriodItemDto,
|
@Body() data: UpdateSeasonPeriodItemDto,
|
||||||
|
|
|
@ -19,13 +19,13 @@ import { BatchCancelReconciliationManager } from './domain/usecases/managers/bat
|
||||||
import { BatchConfirmReconciliationManager } from './domain/usecases/managers/batch-confirm-reconciliation.manager';
|
import { BatchConfirmReconciliationManager } from './domain/usecases/managers/batch-confirm-reconciliation.manager';
|
||||||
import { RecapReconciliationManager } from './domain/usecases/managers/recap-reconciliation.manager';
|
import { RecapReconciliationManager } from './domain/usecases/managers/recap-reconciliation.manager';
|
||||||
import { RecapPosTransactionHandler } from './domain/usecases/handlers/recap-pos-transaction.handler';
|
import { RecapPosTransactionHandler } from './domain/usecases/handlers/recap-pos-transaction.handler';
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
import { SalesPriceFormulaDataService } from '../sales-price-formula/data/services/sales-price-formula-data.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
TypeOrmModule.forFeature([TransactionModel], CONNECTION_NAME.DEFAULT),
|
TypeOrmModule.forFeature([TransactionModel], CONNECTION_NAME.DEFAULT),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [ReconciliationDataController, ReconciliationReadController],
|
controllers: [ReconciliationDataController, ReconciliationReadController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -31,10 +31,6 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
||||||
'items.bundling_items',
|
'items.bundling_items',
|
||||||
'items.refunds item_refunds',
|
'items.refunds item_refunds',
|
||||||
'item_refunds.refund item_refunds_refund',
|
'item_refunds.refund item_refunds_refund',
|
||||||
|
|
||||||
'transaction.items transaction_items',
|
|
||||||
'transaction_items.item transaction_items_item',
|
|
||||||
'transaction_items_item.time_group transaction_items_item_time_group',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// relation yang hanya ingin dihitung (akan return number)
|
// relation yang hanya ingin dihitung (akan return number)
|
||||||
|
@ -69,10 +65,6 @@ export class DetailRefundManager extends BaseDetailManager<RefundEntity> {
|
||||||
'item_refunds',
|
'item_refunds',
|
||||||
'item_refunds_refund.id',
|
'item_refunds_refund.id',
|
||||||
'item_refunds_refund.status',
|
'item_refunds_refund.status',
|
||||||
|
|
||||||
'transaction_items',
|
|
||||||
'transaction_items_item',
|
|
||||||
'transaction_items_item_time_group',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ import { CancelRefundManager } from './domain/usecases/managers/cancel-refund.ma
|
||||||
import { RefundItemModel } from './data/models/refund-item.model';
|
import { RefundItemModel } from './data/models/refund-item.model';
|
||||||
import { TransactionDataService } from '../transaction/data/services/transaction-data.service';
|
import { TransactionDataService } from '../transaction/data/services/transaction-data.service';
|
||||||
import { TransactionModel } from '../transaction/data/models/transaction.model';
|
import { TransactionModel } from '../transaction/data/models/transaction.model';
|
||||||
import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -32,7 +32,6 @@ import { CouchModule } from 'src/modules/configuration/couch/couch.module';
|
||||||
CONNECTION_NAME.DEFAULT,
|
CONNECTION_NAME.DEFAULT,
|
||||||
),
|
),
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
CouchModule,
|
|
||||||
],
|
],
|
||||||
controllers: [RefundDataController, RefundReadController],
|
controllers: [RefundDataController, RefundReadController],
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
@ -4,14 +4,12 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { TransactionModel } from '../models/transaction.model';
|
import { TransactionModel } from '../models/transaction.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 { CouchService } from 'src/modules/configuration/couch/data/services/couch.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionDataService extends BaseDataService<TransactionModel> {
|
export class TransactionDataService extends BaseDataService<TransactionModel> {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
@InjectRepository(TransactionModel, CONNECTION_NAME.DEFAULT)
|
||||||
private repo: Repository<TransactionModel>,
|
private repo: Repository<TransactionModel>,
|
||||||
private couchService: CouchService,
|
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
@ -22,14 +20,4 @@ export class TransactionDataService extends BaseDataService<TransactionModel> {
|
||||||
where: { id: booking_id },
|
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,64 +30,4 @@ export class TransactionReadService extends BaseReadService<TransactionEntity> {
|
||||||
|
|
||||||
return transactions;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,22 +77,6 @@ export class MidtransCallbackHandler
|
||||||
await whatsappService.bookingCreated(payload);
|
await whatsappService.bookingCreated(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
|
||||||
transaction.status === STATUS.EXPIRED &&
|
|
||||||
transaction.type === TransactionType.ONLINE
|
|
||||||
) {
|
|
||||||
const whatsappService = new WhatsappService();
|
|
||||||
const formattedDate = moment(transaction.booking_date);
|
|
||||||
const payload = {
|
|
||||||
id: transaction.id,
|
|
||||||
phone: transaction.customer_phone,
|
|
||||||
code: transaction.invoice_code,
|
|
||||||
name: transaction.customer_name,
|
|
||||||
time: formattedDate.valueOf(),
|
|
||||||
};
|
|
||||||
await whatsappService.bookingExpired(payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.eventBus.publish(
|
this.eventBus.publish(
|
||||||
new TransactionChangeStatusEvent({
|
new TransactionChangeStatusEvent({
|
||||||
id: data_id,
|
id: data_id,
|
||||||
|
|
|
@ -31,9 +31,6 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
'items.refunds item_refunds',
|
'items.refunds item_refunds',
|
||||||
'item_refunds.refund item_refunds_refund',
|
'item_refunds.refund item_refunds_refund',
|
||||||
'refunds',
|
'refunds',
|
||||||
|
|
||||||
'items.item items_item',
|
|
||||||
'items_item.time_group items_item_time_group',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// relation yang hanya ingin dihitung (akan return number)
|
// relation yang hanya ingin dihitung (akan return number)
|
||||||
|
@ -95,8 +92,6 @@ export class DetailTransactionManager extends BaseDetailManager<TransactionEntit
|
||||||
'item_refunds_refund.status',
|
'item_refunds_refund.status',
|
||||||
|
|
||||||
'refunds',
|
'refunds',
|
||||||
'items_item',
|
|
||||||
'items_item_time_group',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,6 @@ export function mappingTransaction(data, refundId?: string) {
|
||||||
if (refundId)
|
if (refundId)
|
||||||
refund = itemData.refunds?.find((item) => item.refund.id == refundId);
|
refund = itemData.refunds?.find((item) => item.refund.id == refundId);
|
||||||
|
|
||||||
const timeGroup = itemData?.item?.time_group;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item: {
|
item: {
|
||||||
id: itemData.item_id,
|
id: itemData.item_id,
|
||||||
|
@ -59,7 +57,6 @@ export function mappingTransaction(data, refundId?: string) {
|
||||||
},
|
},
|
||||||
breakdown_bundling: itemData.breakdown_bundling,
|
breakdown_bundling: itemData.breakdown_bundling,
|
||||||
bundling_items: itemData.bundling_items,
|
bundling_items: itemData.bundling_items,
|
||||||
time_group: timeGroup,
|
|
||||||
},
|
},
|
||||||
id: itemData.id,
|
id: itemData.id,
|
||||||
refund: refund,
|
refund: refund,
|
||||||
|
|
|
@ -141,10 +141,4 @@ export class TransactionDataOrchestrator {
|
||||||
await this.batchConfirmDataManager.execute();
|
await this.batchConfirmDataManager.execute();
|
||||||
return this.batchConfirmDataManager.getResult();
|
return this.batchConfirmDataManager.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveTransactionToCouch(transaction: any[]) {
|
|
||||||
for (const t of transaction) {
|
|
||||||
await this.serviceData.saveTransactionToCouch(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@ import { BaseReadOrchestrator } from 'src/core/modules/domain/usecase/orchestrat
|
||||||
import { DetailTransactionManager } from './managers/detail-transaction.manager';
|
import { DetailTransactionManager } from './managers/detail-transaction.manager';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { PriceCalculator } from './calculator/price.calculator';
|
import { PriceCalculator } from './calculator/price.calculator';
|
||||||
import { In } from 'typeorm';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionReadOrchestrator extends BaseReadOrchestrator<TransactionEntity> {
|
export class TransactionReadOrchestrator extends BaseReadOrchestrator<TransactionEntity> {
|
||||||
|
@ -28,16 +26,6 @@ export class TransactionReadOrchestrator extends BaseReadOrchestrator<Transactio
|
||||||
return this.indexManager.getResult();
|
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> {
|
async detail(dataId: string): Promise<TransactionEntity> {
|
||||||
this.detailManager.setData(dataId);
|
this.detailManager.setData(dataId);
|
||||||
this.detailManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
this.detailManager.setService(this.serviceData, TABLE_NAME.TRANSACTION);
|
||||||
|
@ -62,24 +50,17 @@ export class TransactionReadOrchestrator extends BaseReadOrchestrator<Transactio
|
||||||
transaction.payment_total_dpp = price.dpp_value;
|
transaction.payment_total_dpp = price.dpp_value;
|
||||||
transaction.payment_total_share = price.other.total_profit_share;
|
transaction.payment_total_share = price.other.total_profit_share;
|
||||||
transaction.payment_total_tax = price.other.payment_total_tax;
|
transaction.payment_total_tax = price.other.payment_total_tax;
|
||||||
console.log(transaction.id);
|
console.log({ price }, transaction.payment_total);
|
||||||
await this.serviceData.getRepository().save(transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ids = [];
|
|
||||||
|
|
||||||
async calculatePrice(): Promise<void> {
|
async calculatePrice(): Promise<void> {
|
||||||
const transactions = await this.serviceData.getManyByOptions({
|
const transactions = await this.serviceData.getManyByOptions({
|
||||||
where: {
|
where: {
|
||||||
// is_recap_transaction: false,
|
is_recap_transaction: false,
|
||||||
id: In(this.ids),
|
|
||||||
},
|
},
|
||||||
relations: ['items', 'items.bundling_items'],
|
relations: ['items', 'items.bundling_items'],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(transactions.length);
|
|
||||||
// return;
|
|
||||||
|
|
||||||
for (const transaction of transactions) {
|
for (const transaction of transactions) {
|
||||||
try {
|
try {
|
||||||
const price = await this.calculator.calculate(transaction);
|
const price = await this.calculator.calculate(transaction);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
|
@ -8,20 +7,17 @@ import {
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Res,
|
Res,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { TransactionDataOrchestrator } from '../domain/usecases/transaction-data.orchestrator';
|
import { TransactionDataOrchestrator } from '../domain/usecases/transaction-data.orchestrator';
|
||||||
import { TransactionDto } from './dto/transaction.dto';
|
import { TransactionDto } from './dto/transaction.dto';
|
||||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||||
import { ApiBearerAuth, ApiBody, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { TransactionEntity } from '../domain/entities/transaction.entity';
|
import { TransactionEntity } from '../domain/entities/transaction.entity';
|
||||||
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { DownloadPdfDto } from './dto/donwload-pdf.dto';
|
import { DownloadPdfDto } from './dto/donwload-pdf.dto';
|
||||||
import { OtpAuthGuard } from 'src/modules/configuration/otp-verification/infrastructure/guards/otp-auth.guard';
|
|
||||||
import { OtpCheckerGuard } from 'src/core/guards/domain/otp-checker.guard';
|
|
||||||
|
|
||||||
@ApiTags(`${MODULE_NAME.TRANSACTION.split('-').join(' ')} - data`)
|
@ApiTags(`${MODULE_NAME.TRANSACTION.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.TRANSACTION}`)
|
@Controller(`v1/${MODULE_NAME.TRANSACTION}`)
|
||||||
|
@ -54,7 +50,6 @@ export class TransactionDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm-data')
|
@Patch(':id/confirm-data')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async confirmData(@Param('id') dataId: string): Promise<string> {
|
async confirmData(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirmData(dataId);
|
return await this.orchestrator.confirmData(dataId);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +60,6 @@ export class TransactionDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
@ -97,29 +91,4 @@ export class TransactionDataController {
|
||||||
async delete(@Param('id') dataId: string): Promise<string> {
|
async delete(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.delete(dataId);
|
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,12 +28,6 @@ export class TransactionReadController {
|
||||||
return await this.orchestrator.detail(id);
|
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)
|
@Public(true)
|
||||||
@Get('dummy/:id')
|
@Get('dummy/:id')
|
||||||
async calculate(@Param('id') id: string): Promise<string> {
|
async calculate(@Param('id') id: string): Promise<string> {
|
||||||
|
|
|
@ -47,9 +47,6 @@ import { TransactionDemographyModel } from './data/models/transaction-demography
|
||||||
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';
|
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({
|
@Module({
|
||||||
exports: [
|
exports: [
|
||||||
|
@ -59,10 +56,6 @@ import { JwtModule } from '@nestjs/jwt';
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
JwtModule.register({
|
|
||||||
secret: JWT_SECRET,
|
|
||||||
signOptions: { expiresIn: JWT_EXPIRED },
|
|
||||||
}),
|
|
||||||
TypeOrmModule.forFeature(
|
TypeOrmModule.forFeature(
|
||||||
[
|
[
|
||||||
TransactionModel,
|
TransactionModel,
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Patch,
|
Patch,
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
import { UserDataOrchestrator } from '../domain/usecases/user-data.orchestrator';
|
||||||
import { UserDto } from './dto/user.dto';
|
import { UserDto } from './dto/user.dto';
|
||||||
|
@ -18,7 +17,6 @@ import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto'
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
import { UpdatePasswordUserDto } from './dto/update-password-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`)
|
@ApiTags(`${MODULE_NAME.USER.split('-').join(' ')} - data`)
|
||||||
@Controller(`v1/${MODULE_NAME.USER}`)
|
@Controller(`v1/${MODULE_NAME.USER}`)
|
||||||
|
@ -38,7 +36,6 @@ export class UserDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/active')
|
@Patch(':id/active')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async active(@Param('id') dataId: string): Promise<string> {
|
async active(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.active(dataId);
|
return await this.orchestrator.active(dataId);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +46,6 @@ export class UserDataController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/confirm')
|
@Patch(':id/confirm')
|
||||||
@UseGuards(OtpCheckerGuard)
|
|
||||||
async confirm(@Param('id') dataId: string): Promise<string> {
|
async confirm(@Param('id') dataId: string): Promise<string> {
|
||||||
return await this.orchestrator.confirm(dataId);
|
return await this.orchestrator.confirm(dataId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,57 +198,6 @@ export class WhatsappService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bookingExpired(data: WhatsappBookingCreate) {
|
|
||||||
const momentDate = moment(data.time);
|
|
||||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
|
||||||
// const dayOfWeek = momentDate.day();
|
|
||||||
// const dayOfMonth = momentDate.date();
|
|
||||||
// const year = momentDate.year();
|
|
||||||
// const month = momentDate.month() + 1;
|
|
||||||
// const hour = momentDate.hour();
|
|
||||||
// const minute = momentDate.minute();
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
messaging_product: 'whatsapp',
|
|
||||||
to: phoneNumberOnly(data.phone), // recipient's phone number
|
|
||||||
type: 'template',
|
|
||||||
template: {
|
|
||||||
name: 'booking_expired',
|
|
||||||
language: {
|
|
||||||
code: 'id', // language code
|
|
||||||
},
|
|
||||||
components: [
|
|
||||||
{
|
|
||||||
type: 'body',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'customer',
|
|
||||||
text: data.name, // replace with name variable
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'code',
|
|
||||||
text: data.code, // replace with queue_code variable
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'booking_date',
|
|
||||||
text: fallbackValue,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
|
||||||
if (response)
|
|
||||||
Logger.log(
|
|
||||||
`Notification register Booking for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async rescheduleCreated(data: WhatsappBookingCreate) {
|
async rescheduleCreated(data: WhatsappBookingCreate) {
|
||||||
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
||||||
|
|
||||||
|
@ -324,23 +273,10 @@ export class WhatsappService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async bookingRegister(
|
async bookingRegister(data: WhatsappBookingCreate, paymentUrl: string) {
|
||||||
data: WhatsappBookingCreate,
|
|
||||||
total: number,
|
|
||||||
paymentUrl: string,
|
|
||||||
) {
|
|
||||||
const momentDate = moment(data.time);
|
const momentDate = moment(data.time);
|
||||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||||
|
|
||||||
const formattedTotal = new Intl.NumberFormat('id-ID', {
|
|
||||||
style: 'currency',
|
|
||||||
currency: 'IDR',
|
|
||||||
minimumFractionDigits: 0,
|
|
||||||
maximumFractionDigits: 0,
|
|
||||||
})
|
|
||||||
.format(total)
|
|
||||||
.replace('IDR', 'Rp');
|
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
messaging_product: 'whatsapp',
|
messaging_product: 'whatsapp',
|
||||||
to: phoneNumberOnly(data.phone), // recipient's phone number
|
to: phoneNumberOnly(data.phone), // recipient's phone number
|
||||||
|
@ -364,16 +300,6 @@ export class WhatsappService {
|
||||||
parameter_name: 'booking_date',
|
parameter_name: 'booking_date',
|
||||||
text: fallbackValue,
|
text: fallbackValue,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'booking_code',
|
|
||||||
text: data.code,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'total',
|
|
||||||
text: formattedTotal,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue