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:
parent
f14674c4f3
commit
dcd3259484
11 changed files with 268 additions and 38 deletions
30
lib/customer-notes.js
Normal file
30
lib/customer-notes.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
const uuid = require('uuid')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const db = require('./db')
|
||||
|
||||
const getCustomerNotes = customerId => {
|
||||
const sql = `SELECT * FROM customer_notes WHERE customer_id=$1 LIMIT 1`
|
||||
return db.oneOrNone(sql, [customerId]).then(res => _.mapKeys((_, key) => _.camelize(key), res))
|
||||
}
|
||||
|
||||
const createCustomerNotes = (customerId, userId, content) => {
|
||||
const sql = `INSERT INTO customer_notes (id, customer_id, last_edited_by, last_edited_at, content) VALUES ($1, $2, $3, now(), $4)`
|
||||
return db.none(sql, [uuid.v4(), customerId, userId, content])
|
||||
}
|
||||
|
||||
const updateCustomerNotes = (customerId, userId, content) => {
|
||||
const sql = `UPDATE customer_notes SET last_edited_at=now(), last_edited_by=$1, content=$2 WHERE customer_id=$3 RETURNING *`
|
||||
return db.any(sql, [userId, content, customerId])
|
||||
.then(res => {
|
||||
if (_.isEmpty(res)) {
|
||||
createCustomerNotes(customerId, userId, content)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getCustomerNotes,
|
||||
createCustomerNotes,
|
||||
updateCustomerNotes
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue