prey/prey-node-client

View on GitHub
lib/agent/ack.js

Summary

Maintainability
A
0 mins
Test Coverage
const storage = require('./utils/storage');
const ackType = 'ack';

const existKeyAckInJson = (json) => {
  //eslint-disable-next-line no-prototype-builtins
  if (json.hasOwnProperty('ack_id')) {
    return true;
  }
  return false;
};
const existKeyIdInJson = (json) => {
  //eslint-disable-next-line no-prototype-builtins
  if (json.hasOwnProperty('id')) {
    return true;
  }
  return false;
};

exports.processAck = (json, cb) => {
  if (!existKeyAckInJson(json)) {
    return cb(new Error('there is no key ack_id in the json'));
  }
  return cb(null, {
    ack_id: json.ack_id,
    type: ackType,
    id: existKeyIdInJson(json) ? json.id : '',
  });
};