Compare commits
32 Commits
79c9139c3c
...
d6717c9c60
Author | SHA1 | Date |
---|---|---|
|
d6717c9c60 | |
|
d995982203 | |
|
56e475d61f | |
|
3116acd5ab | |
|
068c4ce349 | |
|
d4e8e72af0 | |
|
0b5b0ce09b | |
|
838670c822 | |
|
34d8882ec3 | |
|
8fb8aac0f9 | |
|
737575176e | |
|
f0e8fbddc9 | |
|
d8fa72ba20 | |
|
ab9db39a5f | |
|
7ff0040f9e | |
|
9bbd37ba38 | |
|
b476c92b70 | |
|
dc926d84e4 | |
|
0172eea573 | |
|
464f5cb49e | |
|
1e395ae53f | |
|
0512c51f8e | |
|
033ed0046e | |
|
fdbd667b7d | |
|
baeb72fe7d | |
|
4e2ec4d94f | |
|
e24fee86ba | |
|
399ca0bdda | |
|
b8dd2a4e01 | |
|
6a7ab72e12 | |
|
ffc75ba174 | |
|
18afc47030 |
|
@ -0,0 +1,19 @@
|
|||
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"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
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"`,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
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,6 +5,7 @@ import { TransactionType } from 'src/modules/transaction/transaction/constants';
|
|||
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 { 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';
|
||||
|
||||
export class CreateBookingManager extends CreateTransactionManager {
|
||||
|
@ -43,4 +44,20 @@ export class CreateBookingManager extends CreateTransactionManager {
|
|||
});
|
||||
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,6 +57,13 @@ export class RescheduleVerificationManager {
|
|||
phone: transaction.customer_phone,
|
||||
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;
|
||||
} catch (error) {
|
||||
// You can customize the error handling as needed, e.g., throw HttpException for NestJS
|
||||
|
@ -69,17 +76,17 @@ export class RescheduleVerificationManager {
|
|||
async verifyOtp(
|
||||
booking_id: string,
|
||||
code: number,
|
||||
): Promise<{ success: boolean; message: string }> {
|
||||
): Promise<RescheduleVerificationModel> {
|
||||
const verification = await this.rescheduleVerificationRepository.findOne({
|
||||
where: { booking_id, code },
|
||||
order: { created_at: 'DESC' },
|
||||
});
|
||||
|
||||
if (!verification) {
|
||||
return {
|
||||
throw new UnprocessableEntityException({
|
||||
success: false,
|
||||
message: 'No verification code found for this booking.',
|
||||
};
|
||||
message: 'Verification code not match',
|
||||
});
|
||||
}
|
||||
|
||||
// Optionally, you can implement OTP expiration logic here
|
||||
|
@ -88,12 +95,15 @@ export class RescheduleVerificationManager {
|
|||
// Increment tried count
|
||||
verification.tried = (verification.tried || 0) + 1;
|
||||
await this.rescheduleVerificationRepository.save(verification);
|
||||
return { success: false, message: 'Invalid verification code.' };
|
||||
throw new UnprocessableEntityException({
|
||||
success: false,
|
||||
message: 'Invalid verification code.',
|
||||
});
|
||||
}
|
||||
|
||||
// Optionally, you can mark the verification as used or verified here
|
||||
|
||||
return { success: true, message: 'Verification successful.' };
|
||||
return verification;
|
||||
}
|
||||
|
||||
async findDetailByBookingId(bookingId: string): Promise<TransactionEntity> {
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
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 { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { ItemReadService } from 'src/modules/item-related/item/data/services/item-read.service';
|
||||
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
|
||||
import { IndexItemManager } from 'src/modules/item-related/item/domain/usecases/managers/index-item.manager';
|
||||
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';
|
||||
import { BookingItemManager } from '../domain/usecases/managers/booking-item.manager';
|
||||
|
||||
@ApiTags('Booking Item')
|
||||
@Controller('v1/booking-item')
|
||||
@Public(true)
|
||||
export class ItemController {
|
||||
constructor(
|
||||
private indexManager: IndexItemManager,
|
||||
private indexManager: BookingItemManager,
|
||||
private serviceData: ItemReadService,
|
||||
) {}
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Res,
|
||||
UnprocessableEntityException,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { TransactionDto } from './dto/booking-order.dto';
|
||||
|
@ -15,6 +23,10 @@ import {
|
|||
RescheduleVerificationOTP,
|
||||
} from './dto/reschedule.dto';
|
||||
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')
|
||||
@Controller('v1/booking')
|
||||
|
@ -25,6 +37,7 @@ export class BookingOrderController {
|
|||
private serviceData: TransactionDataService,
|
||||
private midtransService: MidtransService,
|
||||
private rescheduleVerification: RescheduleVerificationManager,
|
||||
private rescheduleManager: RescheduleManager,
|
||||
) {}
|
||||
|
||||
@Post()
|
||||
|
@ -58,6 +71,38 @@ export class BookingOrderController {
|
|||
|
||||
@Post('reschedule')
|
||||
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 maskedPhoneNumber = result.phone_number.replace(/.(?=.{4})/g, '*');
|
||||
result.phone_number = maskedPhoneNumber;
|
||||
|
@ -72,19 +117,32 @@ export class BookingOrderController {
|
|||
+data.code,
|
||||
);
|
||||
|
||||
const transaction = await this.get(data.booking_id);
|
||||
const reschedule = await this.rescheduleManager.reschedule(result);
|
||||
const transaction = await this.get(reschedule.id);
|
||||
|
||||
return { ...result, transaction };
|
||||
return {
|
||||
id: reschedule.id,
|
||||
phone_number: result.phone_number,
|
||||
name: result.name,
|
||||
reschedule_date: result.reschedule_date,
|
||||
transaction,
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
async get(@Param('id') transactionId: string) {
|
||||
const data = await this.serviceData.getOneByOptions({
|
||||
relations: ['items'],
|
||||
relations: [
|
||||
'items',
|
||||
'parent_transaction',
|
||||
'items.item',
|
||||
'items.item.time_group',
|
||||
],
|
||||
where: { id: transactionId },
|
||||
});
|
||||
|
||||
const {
|
||||
parent_id,
|
||||
customer_name,
|
||||
customer_phone,
|
||||
booking_date,
|
||||
|
@ -92,9 +150,30 @@ export class BookingOrderController {
|
|||
status,
|
||||
id,
|
||||
items,
|
||||
parent_transaction,
|
||||
} = data;
|
||||
|
||||
let timeGroup = null;
|
||||
|
||||
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 {
|
||||
id,
|
||||
item_id,
|
||||
|
@ -126,6 +205,20 @@ export class BookingOrderController {
|
|||
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 {
|
||||
customer_name,
|
||||
customer_phone: maskedCustomerPhone,
|
||||
|
@ -133,7 +226,10 @@ export class BookingOrderController {
|
|||
invoice_code,
|
||||
status,
|
||||
id,
|
||||
is_reschedule: !!parent_id,
|
||||
items: usageItems,
|
||||
time_group: timeGroup,
|
||||
parent: parentTransaction,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -148,4 +244,31 @@ export class BookingOrderController {
|
|||
const buffer = Buffer.from(base64Data, 'base64');
|
||||
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,6 +13,8 @@ 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';
|
||||
import { BookingItemManager } from './domain/usecases/managers/booking-item.manager';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
|
@ -26,6 +28,11 @@ import { RescheduleVerificationManager } from './domain/usecases/managers/resche
|
|||
CqrsModule,
|
||||
],
|
||||
controllers: [ItemController, BookingOrderController],
|
||||
providers: [CreateBookingManager, RescheduleVerificationManager],
|
||||
providers: [
|
||||
CreateBookingManager,
|
||||
RescheduleVerificationManager,
|
||||
RescheduleManager,
|
||||
BookingItemManager,
|
||||
],
|
||||
})
|
||||
export class BookingOrderModule {}
|
||||
|
|
|
@ -27,6 +27,9 @@ export class ItemModel
|
|||
@Column('varchar', { name: 'name', unique: true })
|
||||
name: string;
|
||||
|
||||
@Column('text', { name: 'booking_description', nullable: true })
|
||||
booking_description: string;
|
||||
|
||||
@Column('varchar', { name: 'image_url', nullable: true })
|
||||
image_url: string;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity';
|
||||
import { ItemType } from 'src/modules/item-related/item-category/constants';
|
||||
import { LimitType } from '../../constants';
|
||||
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
|
||||
|
||||
export interface ItemEntity extends BaseStatusEntity {
|
||||
name: string;
|
||||
|
@ -18,4 +19,7 @@ export interface ItemEntity extends BaseStatusEntity {
|
|||
use_queue: boolean;
|
||||
show_to_booking: boolean;
|
||||
breakdown_bundling?: boolean;
|
||||
booking_description?: string;
|
||||
|
||||
item_rates?: ItemRateEntity[] | any[];
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ export class DetailItemManager extends BaseDetailManager<ItemEntity> {
|
|||
`${this.tableName}.show_to_booking`,
|
||||
`${this.tableName}.breakdown_bundling`,
|
||||
`${this.tableName}.play_estimation`,
|
||||
`${this.tableName}.booking_description`,
|
||||
|
||||
`item_category.id`,
|
||||
`item_category.name`,
|
||||
|
|
|
@ -54,6 +54,7 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
|||
`${this.tableName}.breakdown_bundling`,
|
||||
`${this.tableName}.play_estimation`,
|
||||
`${this.tableName}.show_to_booking`,
|
||||
`${this.tableName}.booking_description`,
|
||||
|
||||
`item_category.id`,
|
||||
`item_category.name`,
|
||||
|
@ -109,7 +110,7 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
|||
|
||||
if (this.filterParam.time_group_ids?.length) {
|
||||
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,
|
||||
},
|
||||
|
@ -120,6 +121,16 @@ export class IndexItemManager extends BaseIndexManager<ItemEntity> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,6 +138,17 @@ export class ItemDto extends BaseStatusDto implements ItemEntity {
|
|||
@ValidateIf((body) => body.show_to_booking)
|
||||
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({
|
||||
name: 'bundling_items',
|
||||
type: [Object],
|
||||
|
|
|
@ -29,6 +29,7 @@ export class ItemDataController {
|
|||
return await this.orchestrator.create(data);
|
||||
}
|
||||
|
||||
@Public(true)
|
||||
@Post('update-price')
|
||||
async updatePrice(@Body() body: UpdateItemPriceDto): Promise<any> {
|
||||
return await this.orchestrator.updatePrice(body);
|
||||
|
|
|
@ -40,11 +40,14 @@ export class TicketDataService extends BaseDataService<QueueTicket> {
|
|||
}
|
||||
|
||||
async loginQueue(id: string): Promise<QueueOrder> {
|
||||
const start = moment().startOf('day').valueOf();
|
||||
const end = moment().endOf('day').valueOf();
|
||||
|
||||
const order = await this.order.findOne({
|
||||
relations: ['tickets'],
|
||||
where: [
|
||||
{ transaction_id: id },
|
||||
{ code: id, transaction_id: Not(IsNull()) },
|
||||
{ transaction_id: id, date: Between(start, end) },
|
||||
{ code: id, transaction_id: Not(IsNull()), date: Between(start, end) },
|
||||
],
|
||||
});
|
||||
|
||||
|
|
|
@ -275,6 +275,22 @@ 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;
|
||||
}
|
||||
|
|
|
@ -13,4 +13,11 @@ export class TransactionDataService extends BaseDataService<TransactionModel> {
|
|||
) {
|
||||
super(repo);
|
||||
}
|
||||
|
||||
async getTransactionWithReschedule(booking_id: string) {
|
||||
return this.repo.findOne({
|
||||
relations: ['children_transactions', 'items'],
|
||||
where: { id: booking_id },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ export interface TransactionEntity extends BaseStatusEntity {
|
|||
sending_qr_at: number;
|
||||
sending_qr_status: STATUS;
|
||||
|
||||
parent_id?: string;
|
||||
|
||||
calendar_id?: string;
|
||||
calendar_link?: string;
|
||||
|
||||
|
|
|
@ -124,7 +124,6 @@ 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);
|
||||
|
@ -184,7 +183,7 @@ export class WhatsappService {
|
|||
parameters: [
|
||||
{
|
||||
type: 'text',
|
||||
text: ticketUrl, // replace with dynamic URL
|
||||
text: data.id, // replace with dynamic URL
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -199,6 +198,193 @@ 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 }) {
|
||||
// Compose the WhatsApp message payload for OTP using Facebook WhatsApp API
|
||||
const payload = {
|
||||
|
|
Loading…
Reference in New Issue