Add single-order query
This commit is contained in:
@@ -468,6 +468,30 @@ export const resolvers = {
|
||||
orderBy: { name: 'asc' },
|
||||
}),
|
||||
|
||||
order: async (_, { id }, context) => {
|
||||
const user = requireUser(context);
|
||||
const order = await context.prisma.order.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
items: true,
|
||||
history: { orderBy: { createdAt: 'desc' } },
|
||||
},
|
||||
});
|
||||
|
||||
if (!order) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isManagerRole(user.role)) {
|
||||
if (!await canManagerAccessUser(context.prisma, user, order.customerId)) {
|
||||
return null;
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
return order.customerId === user.id ? order : null;
|
||||
},
|
||||
|
||||
myOrders: (_, __, context) => {
|
||||
const user = requireUser(context);
|
||||
return context.prisma.order.findMany({
|
||||
|
||||
@@ -334,6 +334,7 @@ type Query {
|
||||
myNotificationHistory(channel: MessengerType!, limit: Int = 50): [NotificationHistoryItem!]!
|
||||
managerNotificationHistory(userId: ID!, channel: MessengerType!, limit: Int = 50): [NotificationHistoryItem!]!
|
||||
clientProducts: [Product!]!
|
||||
order(id: ID!): Order
|
||||
myOrders: [Order!]!
|
||||
myCurrentOrders: [Order!]!
|
||||
managerUsers: [ManagerUser!]!
|
||||
|
||||
Reference in New Issue
Block a user