Compare commits
No commits in common. "d6717c9c603d52156a000985091e409d661c48e4" and "79c9139c3cfa0f3b44b30c199f7ae0cb99de9c56" have entirely different histories.
d6717c9c60
...
79c9139c3c
|
@ -1,19 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddBookingDescriptionToItem1749537252986
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'AddBookingDescriptionToItem1749537252986';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "items" ADD "booking_description" text`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "items" DROP COLUMN "booking_description"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddBookingParentToTransaction1749604239749
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
name = 'AddBookingParentToTransaction1749604239749';
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(`ALTER TABLE "transactions" ADD "parent_id" uuid`);
|
|
||||||
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" ADD CONSTRAINT "FK_413e95171729ba18cabce1c31e3" FOREIGN KEY ("parent_id") REFERENCES "transactions"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" DROP CONSTRAINT "FK_413e95171729ba18cabce1c31e3"`,
|
|
||||||
);
|
|
||||||
await queryRunner.query(
|
|
||||||
`ALTER TABLE "transactions" DROP COLUMN "parent_id"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { RelationParam } from 'src/core/modules/domain/entities/base-filter.entity';
|
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
|
||||||
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
|
||||||
import { SelectQueryBuilder } from 'typeorm';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BookingItemManager extends IndexItemManager {
|
|
||||||
get relations(): RelationParam {
|
|
||||||
return {
|
|
||||||
// relation only join (for query purpose)
|
|
||||||
joinRelations: [],
|
|
||||||
|
|
||||||
// relation join and select (relasi yang ingin ditampilkan),
|
|
||||||
selectRelations: [
|
|
||||||
'item_category',
|
|
||||||
'bundling_items',
|
|
||||||
'tenant',
|
|
||||||
'time_group',
|
|
||||||
'item_rates',
|
|
||||||
],
|
|
||||||
|
|
||||||
// relation yang hanya ingin dihitung (akan return number)
|
|
||||||
countRelations: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get selects(): string[] {
|
|
||||||
const parent = super.selects;
|
|
||||||
return [
|
|
||||||
...parent,
|
|
||||||
`${this.tableName}.image_url`,
|
|
||||||
'item_rates.id',
|
|
||||||
'item_rates.price',
|
|
||||||
'item_rates.season_period_id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
getResult(): PaginationResponse<ItemEntity> {
|
|
||||||
const result = super.getResult();
|
|
||||||
const { data, total } = result;
|
|
||||||
const hasRates = (this.filterParam.season_period_ids?.length ?? 0) > 0;
|
|
||||||
const items = data.map((item) => {
|
|
||||||
const { item_rates, ...rest } = item;
|
|
||||||
const rate = item_rates?.[0]?.['price'] ?? rest.base_price;
|
|
||||||
return {
|
|
||||||
...rest,
|
|
||||||
base_price: hasRates ? rate : rest.base_price,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
return { total, data: items };
|
|
||||||
}
|
|
||||||
|
|
||||||
setQueryFilter(
|
|
||||||
queryBuilder: SelectQueryBuilder<ItemEntity>,
|
|
||||||
): SelectQueryBuilder<ItemEntity> {
|
|
||||||
const query = super.setQueryFilter(queryBuilder);
|
|
||||||
|
|
||||||
if (this.filterParam.season_period_ids) {
|
|
||||||
query.andWhere(`item_rates.season_period_id In (:...seasonIds)`, {
|
|
||||||
seasonIds: this.filterParam.season_period_ids,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
||||||
import { CreateTransactionManager } from 'src/modules/transaction/transaction/domain/usecases/managers/create-transaction.manager';
|
import { CreateTransactionManager } from 'src/modules/transaction/transaction/domain/usecases/managers/create-transaction.manager';
|
||||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
||||||
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
import { mappingRevertTransaction } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/mapping-transaction.helper';
|
||||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
export class CreateBookingManager extends CreateTransactionManager {
|
export class CreateBookingManager extends CreateTransactionManager {
|
||||||
|
@ -44,20 +43,4 @@ export class CreateBookingManager extends CreateTransactionManager {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterProcess(): Promise<void> {
|
|
||||||
const whatsapp = new WhatsappService();
|
|
||||||
console.log(`/snap/v4/redirection/${this.data.payment_midtrans_token}`);
|
|
||||||
console.log(this.data.payment_midtrans_url);
|
|
||||||
await whatsapp.bookingRegister(
|
|
||||||
{
|
|
||||||
phone: this.data.customer_phone,
|
|
||||||
code: this.data.invoice_code,
|
|
||||||
name: this.data.customer_name,
|
|
||||||
time: this.data.booking_date,
|
|
||||||
id: this.data.id,
|
|
||||||
},
|
|
||||||
`snap/v4/redirection/${this.data.payment_midtrans_token}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,13 +57,6 @@ export class RescheduleVerificationManager {
|
||||||
phone: transaction.customer_phone,
|
phone: transaction.customer_phone,
|
||||||
code: otp.toString(),
|
code: otp.toString(),
|
||||||
});
|
});
|
||||||
// whatsapp.bookingRescheduleOTP({
|
|
||||||
// phone: transaction.customer_phone,
|
|
||||||
// code: otp.toString(),
|
|
||||||
// name: transaction.customer_name,
|
|
||||||
// time: new Date(request.reschedule_date).getTime(),
|
|
||||||
// id: transaction.id,
|
|
||||||
// });
|
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// You can customize the error handling as needed, e.g., throw HttpException for NestJS
|
// You can customize the error handling as needed, e.g., throw HttpException for NestJS
|
||||||
|
@ -76,17 +69,17 @@ export class RescheduleVerificationManager {
|
||||||
async verifyOtp(
|
async verifyOtp(
|
||||||
booking_id: string,
|
booking_id: string,
|
||||||
code: number,
|
code: number,
|
||||||
): Promise<RescheduleVerificationModel> {
|
): Promise<{ success: boolean; message: string }> {
|
||||||
const verification = await this.rescheduleVerificationRepository.findOne({
|
const verification = await this.rescheduleVerificationRepository.findOne({
|
||||||
where: { booking_id, code },
|
where: { booking_id, code },
|
||||||
order: { created_at: 'DESC' },
|
order: { created_at: 'DESC' },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!verification) {
|
if (!verification) {
|
||||||
throw new UnprocessableEntityException({
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Verification code not match',
|
message: 'No verification code found for this booking.',
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally, you can implement OTP expiration logic here
|
// Optionally, you can implement OTP expiration logic here
|
||||||
|
@ -95,15 +88,12 @@ export class RescheduleVerificationManager {
|
||||||
// Increment tried count
|
// Increment tried count
|
||||||
verification.tried = (verification.tried || 0) + 1;
|
verification.tried = (verification.tried || 0) + 1;
|
||||||
await this.rescheduleVerificationRepository.save(verification);
|
await this.rescheduleVerificationRepository.save(verification);
|
||||||
throw new UnprocessableEntityException({
|
return { success: false, message: 'Invalid verification code.' };
|
||||||
success: false,
|
|
||||||
message: 'Invalid verification code.',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally, you can mark the verification as used or verified here
|
// Optionally, you can mark the verification as used or verified here
|
||||||
|
|
||||||
return verification;
|
return { success: true, message: 'Verification successful.' };
|
||||||
}
|
}
|
||||||
|
|
||||||
async findDetailByBookingId(bookingId: string): Promise<TransactionEntity> {
|
async findDetailByBookingId(bookingId: string): Promise<TransactionEntity> {
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
|
||||||
import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model';
|
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';
|
|
||||||
import { generateInvoiceCodeHelper } from 'src/modules/transaction/transaction/domain/usecases/managers/helpers/generate-invoice-code.helper';
|
|
||||||
import * as moment from 'moment';
|
|
||||||
import { TransactionItemModel } from 'src/modules/transaction/transaction/data/models/transaction-item.model';
|
|
||||||
import { RescheduleVerificationModel } from '../../../data/models/reschedule-verification.model';
|
|
||||||
import { WhatsappService } from 'src/services/whatsapp/whatsapp.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class RescheduleManager {
|
|
||||||
constructor(private serviceData: TransactionDataService) {}
|
|
||||||
|
|
||||||
async reschedule(data: RescheduleVerificationModel) {
|
|
||||||
const transaction = await this.serviceData.getTransactionWithReschedule(
|
|
||||||
data.booking_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
const rescheduleDate = moment(data.reschedule_date, 'DD-MM-YYYY');
|
|
||||||
|
|
||||||
const id = uuidv4();
|
|
||||||
const invoiceCode = await generateInvoiceCodeHelper(
|
|
||||||
this.serviceData,
|
|
||||||
'BOOK',
|
|
||||||
);
|
|
||||||
|
|
||||||
const items = this.makeItemZeroPrice(transaction.items);
|
|
||||||
const transactionData = this.makeTransactionZeroPrice(transaction);
|
|
||||||
|
|
||||||
Object.assign(transactionData, {
|
|
||||||
parent_id: transaction.id,
|
|
||||||
id,
|
|
||||||
invoice_code: invoiceCode,
|
|
||||||
status: STATUS.SETTLED,
|
|
||||||
invoice_date: rescheduleDate.format('YYYY-MM-DD'),
|
|
||||||
booking_date: rescheduleDate.format('YYYY-MM-DD'),
|
|
||||||
created_at: moment().unix() * 1000,
|
|
||||||
updated_at: moment().unix() * 1000,
|
|
||||||
items,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.serviceData.getRepository().save(transactionData);
|
|
||||||
|
|
||||||
const whatsapp = new WhatsappService();
|
|
||||||
whatsapp.rescheduleCreated({
|
|
||||||
id: transactionData.id,
|
|
||||||
name: transactionData.customer_name,
|
|
||||||
phone: transactionData.customer_phone,
|
|
||||||
time: moment(transactionData.invoice_date).unix() * 1000,
|
|
||||||
code: transactionData.invoice_code,
|
|
||||||
});
|
|
||||||
|
|
||||||
return transactionData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private makeItemZeroPrice(items: TransactionItemModel[]) {
|
|
||||||
return items.map((item) => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
id: uuidv4(),
|
|
||||||
item_price: 0,
|
|
||||||
total_price: 0,
|
|
||||||
total_hpp: 0,
|
|
||||||
total_profit: 0,
|
|
||||||
total_profit_share: 0,
|
|
||||||
payment_total_dpp: 0,
|
|
||||||
payment_total_tax: 0,
|
|
||||||
total_net_price: 0,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private makeTransactionZeroPrice(transaction: TransactionModel) {
|
|
||||||
return {
|
|
||||||
...transaction,
|
|
||||||
payment_sub_total: 0,
|
|
||||||
payment_discount_total: 0,
|
|
||||||
payment_total: 0,
|
|
||||||
payment_total_pay: 0,
|
|
||||||
payment_total_share: 0,
|
|
||||||
payment_total_tax: 0,
|
|
||||||
payment_total_profit: 0,
|
|
||||||
payment_total_net_profit: 0,
|
|
||||||
payment_total_dpp: 0,
|
|
||||||
discount_percentage: 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +1,19 @@
|
||||||
import { Controller, Get, Query } from '@nestjs/common';
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||||
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
||||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||||
|
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||||
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
||||||
import { BookingItemManager } from '../domain/usecases/managers/booking-item.manager';
|
|
||||||
|
|
||||||
@ApiTags('Booking Item')
|
@ApiTags('Booking Item')
|
||||||
@Controller('v1/booking-item')
|
@Controller('v1/booking-item')
|
||||||
@Public(true)
|
@Public(true)
|
||||||
export class ItemController {
|
export class ItemController {
|
||||||
constructor(
|
constructor(
|
||||||
private indexManager: BookingItemManager,
|
private indexManager: IndexItemManager,
|
||||||
private serviceData: ItemReadService,
|
private serviceData: ItemReadService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
import {
|
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
Res,
|
|
||||||
UnprocessableEntityException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { Public } from 'src/core/guards';
|
import { Public } from 'src/core/guards';
|
||||||
import { TransactionDto } from './dto/booking-order.dto';
|
import { TransactionDto } from './dto/booking-order.dto';
|
||||||
|
@ -23,10 +15,6 @@ import {
|
||||||
RescheduleVerificationOTP,
|
RescheduleVerificationOTP,
|
||||||
} from './dto/reschedule.dto';
|
} from './dto/reschedule.dto';
|
||||||
import { RescheduleVerificationManager } from '../domain/usecases/managers/reschedule-verification.manager';
|
import { RescheduleVerificationManager } from '../domain/usecases/managers/reschedule-verification.manager';
|
||||||
import { RescheduleManager } from '../domain/usecases/managers/reschedule.manager';
|
|
||||||
import { STATUS } from 'src/core/strings/constants/base.constants';
|
|
||||||
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')
|
||||||
|
@ -37,7 +25,6 @@ export class BookingOrderController {
|
||||||
private serviceData: TransactionDataService,
|
private serviceData: TransactionDataService,
|
||||||
private midtransService: MidtransService,
|
private midtransService: MidtransService,
|
||||||
private rescheduleVerification: RescheduleVerificationManager,
|
private rescheduleVerification: RescheduleVerificationManager,
|
||||||
private rescheduleManager: RescheduleManager,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@ -71,38 +58,6 @@ export class BookingOrderController {
|
||||||
|
|
||||||
@Post('reschedule')
|
@Post('reschedule')
|
||||||
async reschedule(@Body() data: RescheduleRequestDTO) {
|
async reschedule(@Body() data: RescheduleRequestDTO) {
|
||||||
const transaction = await this.serviceData.getTransactionWithReschedule(
|
|
||||||
data.booking_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
const today = moment().startOf('day');
|
|
||||||
const rescheduleDate = moment(data.reschedule_date, 'DD-MM-YYYY');
|
|
||||||
const rescheduleDateStartOfDay = rescheduleDate.startOf('day');
|
|
||||||
|
|
||||||
//TODO: validate session period priority
|
|
||||||
|
|
||||||
if (rescheduleDateStartOfDay.isSameOrBefore(today)) {
|
|
||||||
throw new UnprocessableEntityException(
|
|
||||||
'Reschedule date must be in the future',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!transaction) {
|
|
||||||
throw new UnprocessableEntityException('Transaction not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transaction.status !== STATUS.SETTLED) {
|
|
||||||
throw new UnprocessableEntityException('Transaction is not settled');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transaction.children_transactions.length > 0) {
|
|
||||||
throw new UnprocessableEntityException('Transaction already rescheduled');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transaction.parent_id) {
|
|
||||||
throw new UnprocessableEntityException('Transaction is a reschedule');
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await this.rescheduleVerification.saveVerification(data);
|
const result = await this.rescheduleVerification.saveVerification(data);
|
||||||
const maskedPhoneNumber = result.phone_number.replace(/.(?=.{4})/g, '*');
|
const maskedPhoneNumber = result.phone_number.replace(/.(?=.{4})/g, '*');
|
||||||
result.phone_number = maskedPhoneNumber;
|
result.phone_number = maskedPhoneNumber;
|
||||||
|
@ -117,32 +72,19 @@ export class BookingOrderController {
|
||||||
+data.code,
|
+data.code,
|
||||||
);
|
);
|
||||||
|
|
||||||
const reschedule = await this.rescheduleManager.reschedule(result);
|
const transaction = await this.get(data.booking_id);
|
||||||
const transaction = await this.get(reschedule.id);
|
|
||||||
|
|
||||||
return {
|
return { ...result, transaction };
|
||||||
id: reschedule.id,
|
|
||||||
phone_number: result.phone_number,
|
|
||||||
name: result.name,
|
|
||||||
reschedule_date: result.reschedule_date,
|
|
||||||
transaction,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async get(@Param('id') transactionId: string) {
|
async get(@Param('id') transactionId: string) {
|
||||||
const data = await this.serviceData.getOneByOptions({
|
const data = await this.serviceData.getOneByOptions({
|
||||||
relations: [
|
relations: ['items'],
|
||||||
'items',
|
|
||||||
'parent_transaction',
|
|
||||||
'items.item',
|
|
||||||
'items.item.time_group',
|
|
||||||
],
|
|
||||||
where: { id: transactionId },
|
where: { id: transactionId },
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
parent_id,
|
|
||||||
customer_name,
|
customer_name,
|
||||||
customer_phone,
|
customer_phone,
|
||||||
booking_date,
|
booking_date,
|
||||||
|
@ -150,30 +92,9 @@ export class BookingOrderController {
|
||||||
status,
|
status,
|
||||||
id,
|
id,
|
||||||
items,
|
items,
|
||||||
parent_transaction,
|
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
let timeGroup = null;
|
|
||||||
|
|
||||||
const usageItems = items.map((item) => {
|
const usageItems = items.map((item) => {
|
||||||
const itemData = item.item;
|
|
||||||
if (itemData.time_group) {
|
|
||||||
const timeGroupData = itemData.time_group;
|
|
||||||
const {
|
|
||||||
id: groupId,
|
|
||||||
name,
|
|
||||||
start_time,
|
|
||||||
end_time,
|
|
||||||
max_usage_time,
|
|
||||||
} = timeGroupData;
|
|
||||||
timeGroup = {
|
|
||||||
id: groupId,
|
|
||||||
name,
|
|
||||||
start_time,
|
|
||||||
end_time,
|
|
||||||
max_usage_time,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
item_id,
|
item_id,
|
||||||
|
@ -205,20 +126,6 @@ export class BookingOrderController {
|
||||||
maskedCustomerPhone = '*'.repeat(customer_phone.length - 4) + last4;
|
maskedCustomerPhone = '*'.repeat(customer_phone.length - 4) + last4;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parentTransaction = undefined;
|
|
||||||
if (parent_transaction) {
|
|
||||||
const {
|
|
||||||
id: parentId,
|
|
||||||
invoice_code: parentInvoiceCode,
|
|
||||||
invoice_date: parentInvoiceDate,
|
|
||||||
} = parent_transaction;
|
|
||||||
parentTransaction = {
|
|
||||||
id: parentId,
|
|
||||||
invoice_code: parentInvoiceCode,
|
|
||||||
invoice_date: parentInvoiceDate,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
customer_name,
|
customer_name,
|
||||||
customer_phone: maskedCustomerPhone,
|
customer_phone: maskedCustomerPhone,
|
||||||
|
@ -226,10 +133,7 @@ export class BookingOrderController {
|
||||||
invoice_code,
|
invoice_code,
|
||||||
status,
|
status,
|
||||||
id,
|
id,
|
||||||
is_reschedule: !!parent_id,
|
|
||||||
items: usageItems,
|
items: usageItems,
|
||||||
time_group: timeGroup,
|
|
||||||
parent: parentTransaction,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,31 +148,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',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,6 @@ import { MidtransModule } from 'src/modules/configuration/midtrans/midtrans.modu
|
||||||
import { CqrsModule } from '@nestjs/cqrs';
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
import { RescheduleVerificationModel } from './data/models/reschedule-verification.model';
|
import { RescheduleVerificationModel } from './data/models/reschedule-verification.model';
|
||||||
import { RescheduleVerificationManager } from './domain/usecases/managers/reschedule-verification.manager';
|
import { RescheduleVerificationManager } from './domain/usecases/managers/reschedule-verification.manager';
|
||||||
import { RescheduleManager } from './domain/usecases/managers/reschedule.manager';
|
|
||||||
import { BookingItemManager } from './domain/usecases/managers/booking-item.manager';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot(),
|
ConfigModule.forRoot(),
|
||||||
|
@ -28,11 +26,6 @@ import { BookingItemManager } from './domain/usecases/managers/booking-item.mana
|
||||||
CqrsModule,
|
CqrsModule,
|
||||||
],
|
],
|
||||||
controllers: [ItemController, BookingOrderController],
|
controllers: [ItemController, BookingOrderController],
|
||||||
providers: [
|
providers: [CreateBookingManager, RescheduleVerificationManager],
|
||||||
CreateBookingManager,
|
|
||||||
RescheduleVerificationManager,
|
|
||||||
RescheduleManager,
|
|
||||||
BookingItemManager,
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
export class BookingOrderModule {}
|
export class BookingOrderModule {}
|
||||||
|
|
|
@ -27,9 +27,6 @@ export class ItemModel
|
||||||
@Column('varchar', { name: 'name', unique: true })
|
@Column('varchar', { name: 'name', unique: true })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column('text', { name: 'booking_description', nullable: true })
|
|
||||||
booking_description: string;
|
|
||||||
|
|
||||||
@Column('varchar', { name: 'image_url', nullable: true })
|
@Column('varchar', { name: 'image_url', nullable: true })
|
||||||
image_url: string;
|
image_url: string;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||||
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';
|
|
||||||
|
|
||||||
export interface ItemEntity extends BaseStatusEntity {
|
export interface ItemEntity extends BaseStatusEntity {
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -19,7 +18,4 @@ export interface ItemEntity extends BaseStatusEntity {
|
||||||
use_queue: boolean;
|
use_queue: boolean;
|
||||||
show_to_booking: boolean;
|
show_to_booking: boolean;
|
||||||
breakdown_bundling?: boolean;
|
breakdown_bundling?: boolean;
|
||||||
booking_description?: string;
|
|
||||||
|
|
||||||
item_rates?: ItemRateEntity[] | any[];
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,6 @@ export class DetailItemManager extends BaseDetailManager<ItemEntity> {
|
||||||
`${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`,
|
||||||
`${this.tableName}.booking_description`,
|
|
||||||
|
|
||||||
`item_category.id`,
|
`item_category.id`,
|
||||||
`item_category.name`,
|
`item_category.name`,
|
||||||
|
|
|
@ -54,7 +54,6 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
`${this.tableName}.breakdown_bundling`,
|
`${this.tableName}.breakdown_bundling`,
|
||||||
`${this.tableName}.play_estimation`,
|
`${this.tableName}.play_estimation`,
|
||||||
`${this.tableName}.show_to_booking`,
|
`${this.tableName}.show_to_booking`,
|
||||||
`${this.tableName}.booking_description`,
|
|
||||||
|
|
||||||
`item_category.id`,
|
`item_category.id`,
|
||||||
`item_category.name`,
|
`item_category.name`,
|
||||||
|
@ -110,7 +109,7 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
|
|
||||||
if (this.filterParam.time_group_ids?.length) {
|
if (this.filterParam.time_group_ids?.length) {
|
||||||
queryBuilder.andWhere(
|
queryBuilder.andWhere(
|
||||||
`(${this.tableName}.time_group_id In (:...timeGroupIds) OR ${this.tableName}.time_group_id Is Null)`,
|
`${this.tableName}.time_group_id In (:...timeGroupIds) OR ${this.tableName}.time_group_id Is Null`,
|
||||||
{
|
{
|
||||||
timeGroupIds: this.filterParam.time_group_ids,
|
timeGroupIds: this.filterParam.time_group_ids,
|
||||||
},
|
},
|
||||||
|
@ -121,16 +120,6 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
||||||
queryBuilder.andWhere(`${this.tableName}.show_to_booking = true`);
|
queryBuilder.andWhere(`${this.tableName}.show_to_booking = true`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.filterParam.without_time_group != null) {
|
|
||||||
const withoutTimeGroup = this.filterParam.without_time_group
|
|
||||||
? 'Is Null'
|
|
||||||
: 'Is Not Null';
|
|
||||||
|
|
||||||
queryBuilder.andWhere(
|
|
||||||
`${this.tableName}.time_group_id ${withoutTimeGroup}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return queryBuilder;
|
return queryBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,17 +138,6 @@ export class ItemDto extends BaseStatusDto implements ItemEntity {
|
||||||
@ValidateIf((body) => body.show_to_booking)
|
@ValidateIf((body) => body.show_to_booking)
|
||||||
show_to_booking: boolean;
|
show_to_booking: boolean;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
required: false,
|
|
||||||
example: '...',
|
|
||||||
})
|
|
||||||
@ValidateIf((body) => body.show_to_booking)
|
|
||||||
@IsString({
|
|
||||||
message: 'Booking description is required when show to booking is enabled.',
|
|
||||||
})
|
|
||||||
booking_description: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
name: 'bundling_items',
|
name: 'bundling_items',
|
||||||
type: [Object],
|
type: [Object],
|
||||||
|
|
|
@ -29,7 +29,6 @@ export class ItemDataController {
|
||||||
return await this.orchestrator.create(data);
|
return await this.orchestrator.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Public(true)
|
|
||||||
@Post('update-price')
|
@Post('update-price')
|
||||||
async updatePrice(@Body() body: UpdateItemPriceDto): Promise<any> {
|
async updatePrice(@Body() body: UpdateItemPriceDto): Promise<any> {
|
||||||
return await this.orchestrator.updatePrice(body);
|
return await this.orchestrator.updatePrice(body);
|
||||||
|
|
|
@ -40,14 +40,11 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async loginQueue(id: string): Promise<QueueOrder> {
|
async loginQueue(id: string): Promise<QueueOrder> {
|
||||||
const start = moment().startOf('day').valueOf();
|
|
||||||
const end = moment().endOf('day').valueOf();
|
|
||||||
|
|
||||||
const order = await this.order.findOne({
|
const order = await this.order.findOne({
|
||||||
relations: ['tickets'],
|
relations: ['tickets'],
|
||||||
where: [
|
where: [
|
||||||
{ transaction_id: id, date: Between(start, end) },
|
{ transaction_id: id },
|
||||||
{ code: id, transaction_id: Not(IsNull()), date: Between(start, end) },
|
{ code: id, transaction_id: Not(IsNull()) },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -275,22 +275,6 @@ export class TransactionModel
|
||||||
})
|
})
|
||||||
refunds: RefundModel[];
|
refunds: RefundModel[];
|
||||||
|
|
||||||
@Column('varchar', { name: 'parent_id', nullable: true })
|
|
||||||
parent_id: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => TransactionModel, (model) => model.id, {
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
@JoinColumn({ name: 'parent_id' })
|
|
||||||
parent_transaction: TransactionModel;
|
|
||||||
|
|
||||||
@OneToMany(() => TransactionModel, (model) => model.parent_transaction, {
|
|
||||||
cascade: true,
|
|
||||||
onDelete: 'CASCADE',
|
|
||||||
onUpdate: 'CASCADE',
|
|
||||||
})
|
|
||||||
children_transactions: TransactionModel[];
|
|
||||||
|
|
||||||
@Column('varchar', { name: 'otp_code', nullable: true })
|
@Column('varchar', { name: 'otp_code', nullable: true })
|
||||||
otp_code: string;
|
otp_code: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,4 @@ export class TransactionDataService extends BaseDataService<TransactionModel> {
|
||||||
) {
|
) {
|
||||||
super(repo);
|
super(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTransactionWithReschedule(booking_id: string) {
|
|
||||||
return this.repo.findOne({
|
|
||||||
relations: ['children_transactions', 'items'],
|
|
||||||
where: { id: booking_id },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,6 @@ export interface TransactionEntity extends BaseStatusEntity {
|
||||||
sending_qr_at: number;
|
sending_qr_at: number;
|
||||||
sending_qr_status: STATUS;
|
sending_qr_status: STATUS;
|
||||||
|
|
||||||
parent_id?: string;
|
|
||||||
|
|
||||||
calendar_id?: string;
|
calendar_id?: string;
|
||||||
calendar_link?: string;
|
calendar_link?: string;
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ export class WhatsappService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async bookingCreated(data: WhatsappBookingCreate) {
|
async bookingCreated(data: WhatsappBookingCreate) {
|
||||||
|
const ticketUrl = `${BOOKING_TICKET_URL}${data.id}`;
|
||||||
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
||||||
|
|
||||||
const momentDate = moment(data.time);
|
const momentDate = moment(data.time);
|
||||||
|
@ -183,7 +184,7 @@ export class WhatsappService {
|
||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
text: data.id, // replace with dynamic URL
|
text: ticketUrl, // replace with dynamic URL
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -198,193 +199,6 @@ export class WhatsappService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async rescheduleCreated(data: WhatsappBookingCreate) {
|
|
||||||
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
|
||||||
|
|
||||||
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: 'reschedule_created',
|
|
||||||
language: {
|
|
||||||
code: 'id', // language code
|
|
||||||
},
|
|
||||||
components: [
|
|
||||||
{
|
|
||||||
type: 'header',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'image',
|
|
||||||
image: {
|
|
||||||
link: imageUrl,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'body',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'customer',
|
|
||||||
text: data.name, // replace with name variable
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'booking_code',
|
|
||||||
text: data.code, // replace with queue_code variable
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'booking_date',
|
|
||||||
text: fallbackValue,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
sub_type: 'url',
|
|
||||||
index: '0',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
text: data.id, // replace with dynamic URL
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
|
||||||
if (response)
|
|
||||||
Logger.log(
|
|
||||||
`Notification register Booking for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async bookingRegister(data: WhatsappBookingCreate, paymentUrl: string) {
|
|
||||||
const momentDate = moment(data.time);
|
|
||||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
messaging_product: 'whatsapp',
|
|
||||||
to: phoneNumberOnly(data.phone), // recipient's phone number
|
|
||||||
type: 'template',
|
|
||||||
template: {
|
|
||||||
name: 'booking_register',
|
|
||||||
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: 'booking_date',
|
|
||||||
text: fallbackValue,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
sub_type: 'url',
|
|
||||||
index: '0',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
text: paymentUrl, // replace with dynamic URL
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
|
||||||
if (response)
|
|
||||||
Logger.log(
|
|
||||||
`Notification register Booking for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async bookingRescheduleOTP(data: WhatsappBookingCreate) {
|
|
||||||
const momentDate = moment(data.time);
|
|
||||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
messaging_product: 'whatsapp',
|
|
||||||
to: phoneNumberOnly(data.phone), // recipient's phone number
|
|
||||||
type: 'template',
|
|
||||||
template: {
|
|
||||||
name: 'booking_reschedule',
|
|
||||||
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: 'booking_code',
|
|
||||||
text: data.code, // replace with queue_code variable
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'booking_date',
|
|
||||||
text: fallbackValue,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
parameter_name: 'otp',
|
|
||||||
text: data.code,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'button',
|
|
||||||
sub_type: 'copy_code',
|
|
||||||
index: '0',
|
|
||||||
parameters: [
|
|
||||||
{
|
|
||||||
type: 'coupon_code',
|
|
||||||
coupon_code: data.code,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await this.sendMessage(payload);
|
|
||||||
if (response)
|
|
||||||
Logger.log(
|
|
||||||
`Notification reschedule Booking for ${data.code} send to ${data.phone}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async sendOtpNotification(data: { phone: string; code: string }) {
|
async sendOtpNotification(data: { phone: string; code: string }) {
|
||||||
// Compose the WhatsApp message payload for OTP using Facebook WhatsApp API
|
// Compose the WhatsApp message payload for OTP using Facebook WhatsApp API
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|
Loading…
Reference in New Issue