Claim log hotfix
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2023-03-24 09:59:55 +01:00
parent 4762f3b54f
commit e67a40714c
1 changed files with 25 additions and 25 deletions

View File

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