refactor: don't try to get machine name if there's no lastUsedMachine
This commit is contained in:
parent
05ac89f6fa
commit
85e3c16225
1 changed files with 4 additions and 7 deletions
|
|
@ -5,12 +5,9 @@ const filters = require('../../filters')
|
|||
const customerNotes = require('../../../customer-notes')
|
||||
const machineLoader = require('../../../machine-loader')
|
||||
|
||||
const getCustomerById = customerId =>
|
||||
customers.getCustomerById(customerId)
|
||||
.then(customer =>
|
||||
machineLoader.getMachineName(customer.lastUsedMachine)
|
||||
const addLastUsedMachineName = customer =>
|
||||
(customer.lastUsedMachine ? machineLoader.getMachineName(customer.lastUsedMachine) : Promise.resolve(null))
|
||||
.then(lastUsedMachineName => Object.assign(customer, { lastUsedMachineName }))
|
||||
)
|
||||
|
||||
const resolvers = {
|
||||
Customer: {
|
||||
|
|
@ -18,7 +15,7 @@ const resolvers = {
|
|||
},
|
||||
Query: {
|
||||
customers: (...[, { phone, email, name, address, id }]) => customers.getCustomersList(phone, name, address, id, email),
|
||||
customer: (...[, { customerId }]) => getCustomerById(customerId),
|
||||
customer: (...[, { customerId }]) => customers.getCustomerById(customerId).then(addLastUsedMachineName),
|
||||
customerFilters: () => filters.customer()
|
||||
},
|
||||
Mutation: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue