maestro-server/server-app

View on GitHub
app/core/hooks/auditHookPatched.js

Summary

Maintainability
A
2 hrs
Test Coverage
A
100%
'use strict';

/*
hooks: {
  after_create: {
    auditHookPatched: {
        entity: 'servers',
        fill: filled //array with allowed fields
    }
  }
},
*/

const _ = require('lodash');
const {AuditHTTPService} = require('core/services/HTTPService');

const auditHookPatched = ({entity, fill}) => (data) => {
    const cleandata = _.pick(data, fill);

    AuditHTTPService()
        .patch(`/audit/${entity}/${data['_id']}/${_.get(data, 'user.email', '?')}`, cleandata)
        .catch(console.error);


    return data;
};

module.exports = auditHookPatched;