Compare commits

...

32 Commits

Author SHA1 Message Date
shancheas d6717c9c60 feat: add resend notification endpoint in BookingOrderController to send WhatsApp notifications 2025-06-16 09:26:09 +07:00
shancheas d995982203 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-11 19:03:26 +07:00
shancheas 56e475d61f fix: ensure time_group data is only accessed if it exists in BookingOrderController 2025-06-11 19:03:09 +07:00
shancheas 3116acd5ab feat: add image_url to booking item selection in BookingItemManager 2025-06-11 19:02:10 +07:00
firmanr 068c4ce349 Merge pull request 'feat: rename header key basic auth' (#156) from feat/otp-cancel into development
Reviewed-on: #156
2025-06-11 18:28:47 +07:00
firmanr d4e8e72af0 Merge pull request 'feat: rename header key basic auth' (#155) from feat/otp-cancel into development
Reviewed-on: #155
2025-06-11 18:15:45 +07:00
firmanr 0b5b0ce09b Merge pull request 'feat: update validation otp cancel reconciliation' (#154) from feat/otp-cancel into development
Reviewed-on: #154
2025-06-11 17:53:15 +07:00
shancheas 838670c822 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-11 16:31:28 +07:00
shancheas 34d8882ec3 feat: make update price public 2025-06-11 16:31:15 +07:00
firmanr 8fb8aac0f9 Merge pull request 'feat: update validation otp cancel reconciliation' (#153) from feat/otp-cancel into development
Reviewed-on: #153
2025-06-11 16:00:02 +07:00
shancheas 737575176e Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-11 15:46:53 +07:00
shancheas f0e8fbddc9 feat: include parent transaction details in booking order retrieval 2025-06-11 15:46:43 +07:00
shancheas d8fa72ba20 feat: implement BookingItemManager for enhanced item booking functionality 2025-06-11 15:41:07 +07:00
firmanr ab9db39a5f Merge pull request 'feat: add feature basic auth request OTP' (#152) from feat/otp-cancel into development
Reviewed-on: #152
2025-06-11 14:58:12 +07:00
shancheas 7ff0040f9e refactor: enhance time group data structure in booking order controller 2025-06-11 13:04:32 +07:00
shancheas 9bbd37ba38 refactor: update time group handling in booking order controller 2025-06-11 13:03:48 +07:00
shancheas b476c92b70 feat: add time group information to detail booking 2025-06-11 11:04:41 +07:00
shancheas dc926d84e4 refactor: streamline rescheduling logic and enhance transaction retrieval
- Replaced direct transaction retrieval with a dedicated method for better clarity.
- Consolidated validation checks for rescheduling into the controller.
- Added booking date to the transaction data being created.
- Improved error handling for various transaction states during rescheduling.
2025-06-11 10:35:06 +07:00
shancheas 0172eea573 Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-11 08:53:25 +07:00
shancheas 464f5cb49e feat: add booking parent relationship to transactions and implement rescheduling functionality 2025-06-11 08:53:12 +07:00
firmanr 1e395ae53f Merge pull request 'feat: sync time group to couch' (#151) from feat/otp-cancel into development
Reviewed-on: #151
2025-06-10 16:45:26 +07:00
irfan 0512c51f8e Merge pull request 'feat: sync time group to couch' (#150) from feat/otp-cancel into development
Reviewed-on: #150
2025-06-10 16:42:59 +07:00
shancheas 033ed0046e Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-10 16:34:17 +07:00
shancheas fdbd667b7d feat: enhance loginQueue method to filter orders by date range 2025-06-10 16:34:00 +07:00
shancheas baeb72fe7d feat: add filtering option for items based on time group presence 2025-06-10 16:33:36 +07:00
firmanr 4e2ec4d94f Merge pull request 'feat: save otp code when reject reconciliation' (#149) from feat/otp-cancel into development
Reviewed-on: #149
2025-06-10 16:16:07 +07:00
firmanr e24fee86ba Merge pull request 'feat/otp-cancel' (#148) from feat/otp-cancel into development
Reviewed-on: #148
2025-06-10 15:19:45 +07:00
shancheas 399ca0bdda Merge branch 'development' of ssh://git.eigen.co.id:2222/eigen/pos-be into development 2025-06-10 14:31:07 +07:00
shancheas b8dd2a4e01 temp: update WhatsApp notification method for rescheduling to use OTP notification 2025-06-10 14:30:50 +07:00
shancheas 6a7ab72e12 feat: add booking description field to item model and database 2025-06-10 14:29:46 +07:00
shancheas ffc75ba174 feat: integrate WhatsApp notifications for booking registration and rescheduling 2025-06-10 13:28:58 +07:00
firmanr 18afc47030 Merge pull request 'feat/otp-cancel' (#147) from feat/otp-cancel into development
Reviewed-on: #147
2025-06-10 13:21:34 +07:00
20 changed files with 621 additions and 19 deletions

View File

@ -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"`,
);
}
}

View File

@ -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"`,
);
}
}

View File

@ -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;
}
}

View File

@ -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}`,
);
}
}

View File

@ -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> {

View File

@ -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,
};
}
}

View File

@ -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,
) {}

View File

@ -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',
});
}
}
}

View File

@ -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 {}

View File

@ -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;

View File

@ -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[];
}

View File

@ -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`,

View File

@ -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;
}
}

View File

@ -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],

View File

@ -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);

View File

@ -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) },
],
});

View File

@ -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;
}

View File

@ -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 },
});
}
}

View File

@ -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;

View File

@ -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 = {