feat: update refund ticket handling and enhance service schemas
- Removed the taskRefundTicket method from CronService to streamline scheduling logic. - Updated PayosService to include MessageContextType for chat messages, improving message context handling. - Enhanced RefundTicketSchema with additional fields for requester and improved error handling for unauthorized access. - Implemented logic to update order and schedule statuses upon refund ticket approval, ensuring proper state management. - Modified ServiceSchema to utilize createManyAndReturn for message creation, enhancing notification efficiency. These changes improve the handling of refund tickets and enhance the overall functionality of the service schemas, ensuring better user experience and state management.
This commit is contained in:
@@ -99,51 +99,6 @@ export class CronService {
|
||||
}
|
||||
}
|
||||
|
||||
// handle refund ticket by order, if order status is refunded, disable schedule and remove schedule date in future
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async taskRefundTicket() {
|
||||
Logger.log('Handling refund ticket', 'CronService')
|
||||
const now = DateTimeUtils.now().toJSDate()
|
||||
// get all orders where status is REFUNDED and has schedule.dates in future
|
||||
const orders = await this.prisma.order.findMany({
|
||||
where: {
|
||||
status: OrderStatus.REFUNDED,
|
||||
schedule: {
|
||||
dates: {
|
||||
some: {
|
||||
end: {
|
||||
gt: now,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
schedule: {
|
||||
include: {
|
||||
dates: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Logger.log(`Found ${orders.length} orders to handle`, 'CronService')
|
||||
for (const order of orders) {
|
||||
await this.prisma.schedule.update({
|
||||
where: { id: order.scheduleId },
|
||||
data: { status: ScheduleStatus.REFUNDED },
|
||||
})
|
||||
}
|
||||
// remove schedule date in future
|
||||
for (const order of orders) {
|
||||
await this.prisma.scheduleDate.deleteMany({
|
||||
where: {
|
||||
id: { in: order.schedule.dates.map((d) => d.id) },
|
||||
start: { gt: now },
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// cron every 1 minute to check if there is any schedule date start in less than 30 minutes
|
||||
@Cron(CronExpression.EVERY_MINUTE)
|
||||
async taskCheckScheduleDateStart() {
|
||||
|
||||
Reference in New Issue
Block a user