feat: add migration to add customer custom fields related tables

feat: create CustomerCustomField type on graphql
feat: add custom fields fetching to getCustomer and getCustomerList functions
feat: add mutations to interact with customer custom fields
This commit is contained in:
Sérgio Salgado 2021-09-06 16:45:02 +01:00
parent 0035684040
commit fec57bf173
4 changed files with 118 additions and 8 deletions

View file

@ -16,7 +16,10 @@ const resolvers = {
const token = !!context.req.cookies.lamassu_sid && context.req.session.user.id
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, newValue }]) => customers.saveCustomField(customerId, fieldId, newValue),
removeCustomField: (...[, [ { customerId, fieldId } ]]) => customers.removeCustomField(customerId, fieldId)
}
}

View file

@ -1,6 +1,12 @@
const { gql } = require('apollo-server-express')
const typeDef = gql`
type CustomerCustomField {
id: ID
label: String
value: String
}
type Customer {
id: ID!
authorizedOverride: String
@ -30,6 +36,7 @@ const typeDef = gql`
lastTxClass: String
transactions: [Transaction]
subscriberInfo: JSONObject
customFields: [CustomerCustomField]
}
input CustomerInput {
@ -56,6 +63,7 @@ const typeDef = gql`
lastTxClass: String
suspendedUntil: Date
subscriberInfo: Boolean
customFields: [JSONObject]
}
type Query {
@ -66,6 +74,9 @@ const typeDef = gql`
type Mutation {
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer @auth
addCustomField(customerId: ID!, label: String!, value: String!): CustomerCustomField @auth
saveCustomField(customerId: ID!, fieldId: ID!, value: String!): CustomerCustomField @auth
removeCustomField(customerId: ID!, fieldId: ID!): CustomerCustomField @auth
}
`