diff --git a/modules/claim/back/methods/claim/logs.js b/modules/claim/back/methods/claim/logs.js index c7e69680b..f47513e9e 100644 --- a/modules/claim/back/methods/claim/logs.js +++ b/modules/claim/back/methods/claim/logs.js @@ -1,7 +1,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; -const {mergeFilters, mergeWhere} = require('vn-loopback/util/filter'); +const { mergeFilters, mergeWhere } = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('logs', { @@ -12,27 +12,27 @@ module.exports = Self => { arg: 'id', type: 'Number', description: 'The claim id', - http: {source: 'path'} + http: { source: 'path' } }, { arg: 'filter', type: 'object', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'search', type: 'string', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'userFk', type: 'number', - http: {source: 'query'} + http: { source: 'query' } }, { arg: 'created', type: 'date', - http: {source: 'query'} + http: { source: 'query' } }, ], returns: { @@ -45,7 +45,7 @@ module.exports = Self => { } }); - Self.logs = async(ctx, id, filter, options) => { + Self.logs = async (ctx, id, filter, options) => { const conn = Self.dataSource.connector; const args = ctx.args; const myOptions = {}; @@ -56,25 +56,25 @@ module.exports = Self => { let where = buildFilter(args, (param, value) => { switch (param) { - case 'search': - return { - or: [ - {changedModel: {like: `%${value}%`}}, - {oldInstance: {like: `%${value}%`}} - ] - }; - case 'userFk': - return {'cl.userFk': value}; - case 'created': - value.setHours(0, 0, 0, 0); - to = new Date(value); - to.setHours(23, 59, 59, 999); + case 'search': + return { + or: [ + { changedModel: { like: `%${value}%` } }, + { oldInstance: { like: `%${value}%` } } + ] + }; + case 'userFk': + return { 'cl.userFk': value }; + case 'created': + value.setHours(0, 0, 0, 0); + to = new Date(value); + to.setHours(23, 59, 59, 999); - return {creationDate: {between: [value, to]}}; + return { creationDate: { between: [value, to] } }; } }); - where = mergeWhere(where, {['cl.originFk']: id}); - filter = mergeFilters(args.filter, {where}); + where = mergeWhere(where, { ['cl.originFk']: id }); + filter = mergeFilters(args.filter, { where }); const stmts = []; @@ -102,8 +102,8 @@ module.exports = Self => { const logs = []; for (const row of result) { const changes = []; - const oldInstance = JSON.parse(row.oldInstance); - const newInstance = JSON.parse(row.newInstance); + const oldInstance = JSON.parse(row.oldInstance) || {}; + const newInstance = JSON.parse(row.newInstance) || {}; const mergedProperties = [...Object.keys(oldInstance), ...Object.keys(newInstance)]; const properties = new Set(mergedProperties); for (const property of properties) {