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 customerNotes = require('../../../customer-notes')
|
||||||
const machineLoader = require('../../../machine-loader')
|
const machineLoader = require('../../../machine-loader')
|
||||||
|
|
||||||
const getCustomerById = customerId =>
|
const addLastUsedMachineName = customer =>
|
||||||
customers.getCustomerById(customerId)
|
(customer.lastUsedMachine ? machineLoader.getMachineName(customer.lastUsedMachine) : Promise.resolve(null))
|
||||||
.then(customer =>
|
.then(lastUsedMachineName => Object.assign(customer, { lastUsedMachineName }))
|
||||||
machineLoader.getMachineName(customer.lastUsedMachine)
|
|
||||||
.then(lastUsedMachineName => Object.assign(customer, { lastUsedMachineName }))
|
|
||||||
)
|
|
||||||
|
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
Customer: {
|
Customer: {
|
||||||
|
|
@ -18,7 +15,7 @@ const resolvers = {
|
||||||
},
|
},
|
||||||
Query: {
|
Query: {
|
||||||
customers: (...[, { phone, email, name, address, id }]) => customers.getCustomersList(phone, name, address, id, email),
|
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()
|
customerFilters: () => filters.customer()
|
||||||
},
|
},
|
||||||
Mutation: {
|
Mutation: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue