UNPKG

@speakr/speakr-module-services

Version:
43 lines (33 loc) 984 B
"use strict"; const db = require('../../db'); const _ = require('lodash'); module.exports = { newRecord }; function newRecord(options) { let where = { id_hash: options.req.params.id_hash }; let include = [{model: db.contacts}]; return db.campaigns.findOne({where, include}) .then((campaigns) => { if(!!campaigns) { let create = { title: options.req.body.title, name: options.req.body.name, phone: options.req.body.phone, email: options.req.body.email, type: options.req.body.type, campaign_id: campaigns.id }; return db.contacts.create(create) .then((contacts) => { return contacts.reload() .then((contacts) => { options.contacts = contacts; return Promise.resolve(options) }); }).catch((err) => { return Promise.reject(err); }) } }); }