refactor: don't try to get machine name if there's no lastUsedMachine

This commit is contained in:
siiky 2024-07-18 17:32:59 +01:00
parent 05ac89f6fa
commit 85e3c16225

View file

@ -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: {