fix: improve individual discount loading
This commit is contained in:
parent
3ccc202efa
commit
ac56ace4bd
5 changed files with 44 additions and 19 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue