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,4 +1,4 @@
const { ApolloError } = require('apollo-server-express')
const { ApolloError, AuthenticationError } = require('apollo-server-express')
class InvalidCredentialsError extends ApolloError {
constructor(message) {
@ -29,6 +29,7 @@ class InvalidUrlError extends ApolloError {
}
module.exports = {
AuthenticationError,
InvalidCredentialsError,
UserAlreadyExistsError,
InvalidTwoFactorError,

View file

@ -239,6 +239,13 @@ const reset2FA = (token, userID, code, context) => {
.then(() => true)
}
const getToken = context => {
if (_.isNil(context.req.cookies.lid) || _.isNil(context.req.session.user.id))
throw new authErrors.AuthenticationError('Authentication failed')
return context.req.session.user.id
}
module.exports = {
authenticateUser,
getUserData,
@ -259,5 +266,6 @@ module.exports = {
createRegisterToken,
register,
resetPassword,
reset2FA
reset2FA,
getToken
}

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)
}
}
}

View file

@ -41,6 +41,7 @@ const typeDef = gql`
subscriberInfo: JSONObject
customFields: [CustomerCustomField]
customInfoRequests: [CustomRequestData]
notes: String
}
input CustomerInput {
@ -89,6 +90,7 @@ const typeDef = gql`
editCustomer(customerId: ID!, customerEdit: CustomerEdit): Customer @auth
deleteEditedData(customerId: ID!, customerEdit: CustomerEdit): Customer @auth
replacePhoto(customerId: ID!, photoType: String, newPhoto: UploadGQL): Customer @auth
setCustomerNotes(customerId: ID!, newContent: String!): Customer @auth
}
`