fix: improve individual discount loading

This commit is contained in:
Rafael Taranto 2025-04-17 09:48:56 +01:00
parent 3ccc202efa
commit ac56ace4bd
5 changed files with 44 additions and 19 deletions

View file

@ -1,6 +1,16 @@
const DataLoader = require('dataloader')
const loyalty = require('../../../loyalty')
const { getSlimCustomerByIdBatch } = require('../../../customers')
const customerLoader = new DataLoader(ids => {
return getSlimCustomerByIdBatch(ids)
}, { cache: false })
const resolvers = {
IndividualDiscount: {
customer: parent => customerLoader.load(parent.customerId)
},
Query: {
promoCodes: () => loyalty.getAvailablePromoCodes(),
individualDiscounts: () => loyalty.getAvailableIndividualDiscounts()

View file

@ -3,9 +3,15 @@ const gql = require('graphql-tag')
const typeDef = gql`
type IndividualDiscount {
id: ID!
customerId: ID!
customer: DiscountCustomer!
discount: Int
}
type DiscountCustomer {
id: ID!
phone: String
idCardData: JSONObject
}
type PromoCode {
id: ID!