UNPKG

read-email-cg-lib

Version:
37 lines (30 loc) 1.05 kB
const {constants, log, helpers} = require('utils-nxg-cg'); const {objectEmail, extraProp} = require('./objects'); const {emailTransform} = require('./transforms'); /** * Method for process the data user and execute query single or batch by transactions * @param msg * @param cfg * @param test * @returns {Promise<array|object>} */ const emailProcess = async (msg = {}, cfg = {}, test = false) => { try { const {data} = msg; let properties = {...objectEmail}; let extraProps = {...extraProp}; if (!test && !data) { throw Error(`${constants.ERROR_PROPERTY} data`); } const valid = helpers.validProperties(properties, data, cfg); if (valid) { helpers.validProperties(extraProps, data, cfg, true); properties = {...properties, ...extraProps}; return await emailTransform(properties); } } catch (e) { log.error(e); throw Error(e); } }; module.exports = {emailProcess};