chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -6,41 +6,56 @@ const customerNotes = require('../../../customer-notes')
const machineLoader = require('../../../machine-loader')
const addLastUsedMachineName = customer =>
(customer.lastUsedMachine ? machineLoader.getMachineName(customer.lastUsedMachine) : Promise.resolve(null))
.then(lastUsedMachineName => Object.assign(customer, { lastUsedMachineName }))
(customer.lastUsedMachine
? machineLoader.getMachineName(customer.lastUsedMachine)
: Promise.resolve(null)
).then(lastUsedMachineName =>
Object.assign(customer, { lastUsedMachineName }),
)
const resolvers = {
Customer: {
isAnonymous: parent => (parent.customerId === anonymous.uuid)
isAnonymous: parent => parent.customerId === anonymous.uuid,
},
Query: {
customers: (...[, { phone, email, name, address, id }]) => customers.getCustomersList(phone, name, address, id, email),
customer: (...[, { customerId }]) => customers.getCustomerById(customerId).then(addLastUsedMachineName),
customerFilters: () => filters.customer()
customers: (...[, { phone, email, name, address, id }]) =>
customers.getCustomersList(phone, name, address, id, email),
customer: (...[, { customerId }]) =>
customers.getCustomerById(customerId).then(addLastUsedMachineName),
customerFilters: () => filters.customer(),
},
Mutation: {
setCustomer: (root, { customerId, customerInput }, context, info) => {
setCustomer: (root, { customerId, customerInput }, context) => {
const token = authentication.getToken(context)
if (customerId === anonymous.uuid) return customers.getCustomerById(customerId)
if (customerId === anonymous.uuid)
return customers.getCustomerById(customerId)
return customers.updateCustomer(customerId, customerInput, token)
},
addCustomField: (...[, { customerId, label, value }]) => customers.addCustomField(customerId, label, value),
saveCustomField: (...[, { customerId, fieldId, value }]) => customers.saveCustomField(customerId, fieldId, value),
removeCustomField: (...[, [ { customerId, fieldId } ]]) => customers.removeCustomField(customerId, fieldId),
addCustomField: (...[, { customerId, label, value }]) =>
customers.addCustomField(customerId, label, value),
saveCustomField: (...[, { customerId, fieldId, value }]) =>
customers.saveCustomField(customerId, fieldId, value),
removeCustomField: (...[, [{ customerId, fieldId }]]) =>
customers.removeCustomField(customerId, fieldId),
editCustomer: async (root, { customerId, customerEdit }, context) => {
const token = authentication.getToken(context)
const editedData = await customerEdit
return customers.edit(customerId, editedData, token)
},
replacePhoto: async (root, { customerId, photoType, newPhoto }, context) => {
replacePhoto: async (
root,
{ customerId, photoType, newPhoto },
context,
) => {
const token = authentication.getToken(context)
const { file } = newPhoto
const photo = await file
if (!photo) return customers.getCustomerById(customerId)
return customers.updateEditedPhoto(customerId, photo, photoType)
return customers
.updateEditedPhoto(customerId, photo, photoType)
.then(newPatch => customers.edit(customerId, newPatch, token))
},
deleteEditedData: (root, { customerId, customerEdit }) => {
deleteEditedData: (root, { customerId }) => {
// TODO: NOT IMPLEMENTING THIS FEATURE FOR THE CURRENT VERSION
return customers.getCustomerById(customerId)
},
@ -55,12 +70,13 @@ const resolvers = {
deleteCustomerNote: (...[, { noteId }]) => {
return customerNotes.deleteCustomerNote(noteId)
},
createCustomer: (...[, { phoneNumber }]) => customers.add({ phone: phoneNumber }),
createCustomer: (...[, { phoneNumber }]) =>
customers.add({ phone: phoneNumber }),
enableTestCustomer: (...[, { customerId }]) =>
customers.enableTestCustomer(customerId),
disableTestCustomer: (...[, { customerId }]) =>
customers.disableTestCustomer(customerId)
}
customers.disableTestCustomer(customerId),
},
}
module.exports = resolvers