feat: enhance CronService and OrderSchema with new scheduling and authorization features
- Removed unnecessary logging from CronService methods to streamline execution. - Introduced a new cron job in CronService to check if all schedule dates are completed and update the schedule status accordingly. - Added a new query in OrderSchema to retrieve completed orders for moderators, including authorization checks for user roles. - Updated PersonalMilestoneSchema to allow for creating multiple personal milestones with necessary input fields. These changes improve the scheduling logic and enhance the GraphQL API's authorization mechanisms, ensuring better user experience and state management.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||
import { OrderStatus, ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
||||
import { OrderStatus, Role, ScheduleDateStatus, ScheduleStatus } from '@prisma/client'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import _ from 'lodash'
|
||||
import { Builder } from '../Graphql/graphql.builder'
|
||||
@@ -160,7 +160,40 @@ export class OrderSchema extends PothosSchema {
|
||||
})
|
||||
},
|
||||
}),
|
||||
completedOrdersForModerator: t.prismaField({
|
||||
type: [this.order()],
|
||||
description: 'Retrieve a list of completed orders for moderator',
|
||||
args: this.builder.generator.findManyArgs('Order'),
|
||||
resolve: async (query, _root, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Orders cannot be retrieved in subscription context')
|
||||
}
|
||||
if (!ctx.http.me) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
// only for role moderator
|
||||
if (ctx.http.me.role !== Role.MODERATOR) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
// return completed order list where schedule status is COMPLETED
|
||||
return await this.prisma.order.findMany({
|
||||
...query,
|
||||
where: {
|
||||
AND: [
|
||||
...(args.filter ? [args.filter] : []),
|
||||
{
|
||||
status: OrderStatus.PAID,
|
||||
schedule: {
|
||||
status: ScheduleStatus.COMPLETED,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
// mutation section
|
||||
this.builder.mutationFields((t) => ({
|
||||
createOrder: t.prismaField({
|
||||
|
||||
Reference in New Issue
Block a user