Compare commits
No commits in common. "0172eea57319a583963e197c1bb8ac93854e5d5a" and "1e395ae53feff9a8b49654069e1192c07a17f688" have entirely different histories.
0172eea573
...
1e395ae53f
|
@ -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"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ export class RescheduleVerificationManager {
|
|||
phone: transaction.customer_phone,
|
||||
code: otp.toString(),
|
||||
});
|
||||
// whatsapp.bookingRescheduleOTP({
|
||||
// whatsapp.bookingReschedule({
|
||||
// phone: transaction.customer_phone,
|
||||
// code: otp.toString(),
|
||||
// name: transaction.customer_name,
|
||||
|
@ -76,17 +76,17 @@ export class RescheduleVerificationManager {
|
|||
async verifyOtp(
|
||||
booking_id: string,
|
||||
code: number,
|
||||
): Promise<RescheduleVerificationModel> {
|
||||
): Promise<{ success: boolean; message: string }> {
|
||||
const verification = await this.rescheduleVerificationRepository.findOne({
|
||||
where: { booking_id, code },
|
||||
order: { created_at: 'DESC' },
|
||||
});
|
||||
|
||||
if (!verification) {
|
||||
throw new UnprocessableEntityException({
|
||||
return {
|
||||
success: false,
|
||||
message: 'Verification code not match',
|
||||
});
|
||||
message: 'No verification code found for this booking.',
|
||||
};
|
||||
}
|
||||
|
||||
// Optionally, you can implement OTP expiration logic here
|
||||
|
@ -95,15 +95,12 @@ export class RescheduleVerificationManager {
|
|||
// Increment tried count
|
||||
verification.tried = (verification.tried || 0) + 1;
|
||||
await this.rescheduleVerificationRepository.save(verification);
|
||||
throw new UnprocessableEntityException({
|
||||
success: false,
|
||||
message: 'Invalid verification code.',
|
||||
});
|
||||
return { success: false, message: 'Invalid verification code.' };
|
||||
}
|
||||
|
||||
// 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> {
|
||||
|
|
|
@ -1,116 +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.getRepository().findOne({
|
||||
relations: ['children_transactions', 'items'],
|
||||
where: { id: 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 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'),
|
||||
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: data.code.toString(),
|
||||
});
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ import {
|
|||
RescheduleVerificationOTP,
|
||||
} from './dto/reschedule.dto';
|
||||
import { RescheduleVerificationManager } from '../domain/usecases/managers/reschedule-verification.manager';
|
||||
import { RescheduleManager } from '../domain/usecases/managers/reschedule.manager';
|
||||
|
||||
@ApiTags('Booking Order')
|
||||
@Controller('v1/booking')
|
||||
|
@ -26,7 +25,6 @@ export class BookingOrderController {
|
|||
private serviceData: TransactionDataService,
|
||||
private midtransService: MidtransService,
|
||||
private rescheduleVerification: RescheduleVerificationManager,
|
||||
private rescheduleManager: RescheduleManager,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
|
@ -74,16 +72,9 @@ export class BookingOrderController {
|
|||
+data.code,
|
||||
);
|
||||
|
||||
const reschedule = await this.rescheduleManager.reschedule(result);
|
||||
const transaction = await this.get(reschedule.id);
|
||||
const transaction = await this.get(data.booking_id);
|
||||
|
||||
return {
|
||||
id: reschedule.id,
|
||||
phone_number: result.phone_number,
|
||||
name: result.name,
|
||||
reschedule_date: result.reschedule_date,
|
||||
transaction,
|
||||
};
|
||||
return { ...result, transaction };
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
|
|
@ -13,7 +13,6 @@ import { MidtransModule } from 'src/modules/configuration/midtrans/midtrans.modu
|
|||
import { CqrsModule } from '@nestjs/cqrs';
|
||||
import { RescheduleVerificationModel } from './data/models/reschedule-verification.model';
|
||||
import { RescheduleVerificationManager } from './domain/usecases/managers/reschedule-verification.manager';
|
||||
import { RescheduleManager } from './domain/usecases/managers/reschedule.manager';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -27,10 +26,6 @@ import { RescheduleManager } from './domain/usecases/managers/reschedule.manager
|
|||
CqrsModule,
|
||||
],
|
||||
controllers: [ItemController, BookingOrderController],
|
||||
providers: [
|
||||
CreateBookingManager,
|
||||
RescheduleVerificationManager,
|
||||
RescheduleManager,
|
||||
],
|
||||
providers: [CreateBookingManager, RescheduleVerificationManager],
|
||||
})
|
||||
export class BookingOrderModule {}
|
||||
|
|
|
@ -275,22 +275,6 @@ export class TransactionModel
|
|||
})
|
||||
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 })
|
||||
otp_code: string;
|
||||
}
|
||||
|
|
|
@ -86,8 +86,6 @@ export interface TransactionEntity extends BaseStatusEntity {
|
|||
sending_qr_at: number;
|
||||
sending_qr_status: STATUS;
|
||||
|
||||
parent_id?: string;
|
||||
|
||||
calendar_id?: string;
|
||||
calendar_link?: string;
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ export class WhatsappService {
|
|||
}
|
||||
|
||||
async bookingCreated(data: WhatsappBookingCreate) {
|
||||
const ticketUrl = `${BOOKING_TICKET_URL}${data.id}`;
|
||||
const imageUrl = `${BOOKING_QR_URL}${data.id}`;
|
||||
|
||||
const momentDate = moment(data.time);
|
||||
|
@ -183,82 +184,7 @@ export class WhatsappService {
|
|||
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 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
|
||||
text: ticketUrl, // replace with dynamic URL
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -324,7 +250,7 @@ export class WhatsappService {
|
|||
);
|
||||
}
|
||||
|
||||
async bookingRescheduleOTP(data: WhatsappBookingCreate) {
|
||||
async bookingReschedule(data: WhatsappBookingCreate) {
|
||||
const momentDate = moment(data.time);
|
||||
const fallbackValue = momentDate.locale('id').format('dddd, DD MMMM YYYY');
|
||||
|
||||
|
|
Loading…
Reference in New Issue