Skip to content

Commit 68b2ffb

Browse files
authored
Merge pull request #195 from gdg-ibadan01/staging
fix: handle pdf gen error
2 parents 01c7d30 + e98672e commit 68b2ffb

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

backend/src/modules/order/order.service.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
1+
import {
2+
Inject,
3+
Injectable,
4+
InternalServerErrorException,
5+
Logger,
6+
NotFoundException,
7+
} from '@nestjs/common';
28
import {
39
Discount,
410
DiscountType,
@@ -356,6 +362,14 @@ export class OrdersService {
356362
OrdersService.ERRORS.OrderNotFoundErr,
357363
);
358364
}
365+
366+
if (order.status !== OrderStatus.PAID) {
367+
throw new ServiceError(
368+
'Order payment not confirmed yet',
369+
OrdersService.ERRORS.ValidationErr,
370+
);
371+
}
372+
359373
let pdfBuffer: Buffer<ArrayBuffer> | undefined | void;
360374
if (!order.ticketUrl) {
361375
pdfBuffer = await this.pdfService
@@ -367,7 +381,10 @@ export class OrdersService {
367381
d.toLocaleDateString('en-US', { weekday: 'long' }),
368382
),
369383
})
370-
.catch((err) => this.logger.error(err))
384+
.catch((err) => {
385+
this.logger.error(err);
386+
throw new InternalServerErrorException('Unable to generate PDF');
387+
})
371388
.then((res) => {
372389
this.logger.debug('pdfBuffer generated successfully');
373390
return res;
@@ -386,7 +403,12 @@ export class OrdersService {
386403
});
387404
return upload;
388405
})
389-
.catch((err) => this.logger.error(err));
406+
.catch((err) => {
407+
this.logger.error(err);
408+
throw new InternalServerErrorException(
409+
'Unable to generate ticket URL',
410+
);
411+
});
390412
}
391413

392414
return {
@@ -834,7 +856,11 @@ Initiating refund for order ${order.id}`,
834856
if (shouldIssueTicket) {
835857
await tx.order.update({
836858
where: { id: order.id },
837-
data: { status: OrderStatus.PAID, paidAt: now },
859+
data: {
860+
status: OrderStatus.PAID,
861+
paidAt: now,
862+
providerTransactionRef: event.transactionReference,
863+
},
838864
});
839865

840866
await this.setEventAsProcessed(tx, event.webhookEventId);

0 commit comments

Comments
 (0)