feat: customer notes migration

feat: customer notes backend operations

feat: add customer note mutation
feat: add editing capabilities to PropertyCard
feat: connect customer notes backend to frontend
fix: customer note form and static content styling

fix: SQL uppercasing

fix: set default value for notes content
fix: SQL after dev rebase
refactor: move get current user token to separate method
This commit is contained in:
Sérgio Salgado 2021-08-02 04:15:11 +01:00
parent f14674c4f3
commit dcd3259484
11 changed files with 268 additions and 38 deletions

View file

@ -1,6 +1,8 @@
const authentication = require('../modules/authentication')
const anonymous = require('../../../constants').anonymousCustomer
const customers = require('../../../customers')
const filters = require('../../filters')
const customerNotes = require('../../../customer-notes')
const resolvers = {
@ -14,8 +16,7 @@ const resolvers = {
},
Mutation: {
setCustomer: (root, { customerId, customerInput }, context, info) => {
// TODO: To be replaced by function that fetchs the token
const token = !!context.req.cookies.lamassu_sid && context.req.session.user.id
const token = authentication.getToken(context)
if (customerId === anonymous.uuid) return customers.getCustomerById(customerId)
return customers.updateCustomer(customerId, customerInput, token)
},
@ -23,14 +24,12 @@ const resolvers = {
saveCustomField: (...[, { customerId, fieldId, newValue }]) => customers.saveCustomField(customerId, fieldId, newValue),
removeCustomField: (...[, [ { customerId, fieldId } ]]) => customers.removeCustomField(customerId, fieldId),
editCustomer: async (root, { customerId, customerEdit }, context) => {
// TODO: To be replaced by function that fetchs the token
const token = !!context.req.cookies.lid && context.req.session.user.id
const token = authentication.getToken(context)
const editedData = await customerEdit
return customers.edit(customerId, editedData, token)
},
replacePhoto: async (root, { customerId, photoType, newPhoto }, context) => {
// TODO: To be replaced by function that fetchs the token
const token = !!context.req.cookies.lid && context.req.session.user.id
const token = authentication.getToken(context)
const photo = await newPhoto
if (!photo) return customers.getCustomerById(customerId)
return customers.updateEditedPhoto(customerId, photo, photoType)
@ -39,6 +38,10 @@ const resolvers = {
deleteEditedData: (root, { customerId, customerEdit }) => {
// TODO: NOT IMPLEMENTING THIS FEATURE FOR THE CURRENT VERSION
return customers.getCustomerById(customerId)
},
setCustomerNotes: (...[, { customerId, newContent }, context]) => {
const token = authentication.getToken(context)
return customerNotes.updateCustomerNotes(customerId, token, newContent)
}
}
}