fix: stop writing to database on null data
This commit is contained in:
parent
e44e5012f1
commit
658c8d74d4
1 changed files with 8 additions and 3 deletions
|
|
@ -20,8 +20,13 @@ const machineLoader = require('../machine-loader')
|
||||||
const { loadLatestConfig } = require('../new-settings-loader')
|
const { loadLatestConfig } = require('../new-settings-loader')
|
||||||
const customInfoRequestQueries = require('../new-admin/services/customInfoRequests')
|
const customInfoRequestQueries = require('../new-admin/services/customInfoRequests')
|
||||||
|
|
||||||
function updateCustomerCustomInfoRequest (customerId, dataToSave, req, res) {
|
function updateCustomerCustomInfoRequest (customerId, patch, req, res) {
|
||||||
return customInfoRequestQueries.setCustomerData(customerId, dataToSave.info_request_id, dataToSave)
|
if (_.isNil(patch.data)) {
|
||||||
|
return customers.getById(customerId)
|
||||||
|
.then(customer => respond(req, res, { customer }))
|
||||||
|
}
|
||||||
|
|
||||||
|
return customInfoRequestQueries.setCustomerData(customerId, patch.infoRequestId, patch)
|
||||||
.then(() => customers.getById(customerId))
|
.then(() => customers.getById(customerId))
|
||||||
.then(customer => respond(req, res, { customer }))
|
.then(customer => respond(req, res, { customer }))
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +40,7 @@ function updateCustomer (req, res, next) {
|
||||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||||
|
|
||||||
if (patch.customRequestPatch) {
|
if (patch.customRequestPatch) {
|
||||||
return updateCustomerCustomInfoRequest(id, patch.dataToSave, req, res).catch(next)
|
return updateCustomerCustomInfoRequest(id, patch.customRequestPatch, req, res).catch(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
customers.getById(id)
|
customers.getById(id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue