Compare commits

..

No commits in common. "b476c92b7016cfc46b5e53b83872c9619f0fd47d" and "0172eea57319a583963e197c1bb8ac93854e5d5a" have entirely different histories.

3 changed files with 33 additions and 65 deletions

View File

@ -14,11 +14,38 @@ export class RescheduleManager {
constructor(private serviceData: TransactionDataService) {}
async reschedule(data: RescheduleVerificationModel) {
const transaction = await this.serviceData.getTransactionWithReschedule(
data.booking_id,
);
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(
@ -35,7 +62,6 @@ export class RescheduleManager {
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,
@ -49,7 +75,7 @@ export class RescheduleManager {
name: transactionData.customer_name,
phone: transactionData.customer_phone,
time: moment(transactionData.invoice_date).unix() * 1000,
code: transactionData.invoice_code,
code: data.code.toString(),
});
return transactionData;

View File

@ -1,12 +1,4 @@
import {
Body,
Controller,
Get,
Param,
Post,
Res,
UnprocessableEntityException,
} from '@nestjs/common';
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { TransactionDto } from './dto/booking-order.dto';
@ -24,8 +16,6 @@ import {
} 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';
@ApiTags('Booking Order')
@Controller('v1/booking')
@ -70,38 +60,6 @@ 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;
@ -131,7 +89,7 @@ export class BookingOrderController {
@Get(':id')
async get(@Param('id') transactionId: string) {
const data = await this.serviceData.getOneByOptions({
relations: ['items', 'items.item', 'items.item.time_group'],
relations: ['items'],
where: { id: transactionId },
});
@ -146,9 +104,6 @@ export class BookingOrderController {
} = data;
const usageItems = items.map((item) => {
const itemData = item.item;
const timeGroupData = itemData.time_group;
const { id: groupId, name, start_time, end_time } = timeGroupData;
const {
id,
item_id,
@ -170,12 +125,6 @@ export class BookingOrderController {
total_net_price,
qty,
qty_remaining,
time_group: {
id: groupId,
name,
start_time,
end_time,
},
};
});

View File

@ -13,11 +13,4 @@ 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 },
});
}
}