@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
83 lines (70 loc) • 3.56 kB
JavaScript
;
const db = require('../../db/');
module.exports = {
fromCampaignIdHash
};
function fromCampaignIdHash(options) {
let platform = options.req.body.platform;
let status = options.req.body.status;
let where = { id_hash: options.req.params.id_hash };
return db.campaigns.findOne({ where })
.then((campaigns) => {
where = {name: status};
return db.statuses.findOne({ where })
.then((statuses) => {
where = {name: platform};
return db.platforms.findOne({ where })
.then((platforms) => {
return db.initiatives.create({
campaign_id: campaigns.id,
network_id: campaigns.network_id,
id_hash: options.req.params.id_hash,
name: options.req.body.name,
description: options.req.body.description,
target_link: options.req.body.target_link,
earnings_percentage_bonus_enabled: options.req.body.earnings_percentage_bonus_enabled,
earnings_percentage_bonus: options.req.body.earnings_percentage_bonus,
earnings_flat_rate: options.req.body.earnings_flat_rate,
additional_information_enabled: options.req.body.additional_information_enabled,
user_created_media_type: options.req.body.user_created_media_type,
disclosure_type: options.req.body.disclosure_type,
payment_type: options.req.body.payment_type,
dynamic_disclosure: options.req.body.dynamic_disclosure,
custom_disclosure: options.req.body.custom_disclosure,
video_link: options.req.body.video_link,
image_link: options.req.body.image_link,
start_date: options.req.body.start_date,
end_date: options.req.body.end_date,
instructions: options.req.body.instructions, //Now that we are using the new wysiwyg, this can prob be removed and we'll keep instructions_json only
instructions_json: options.req.body.instructions_json,
budget: options.req.body.budget,
posts_per_day: options.req.body.posts_per_day,
standard_disapproved_words: options.req.body.standard_disapproved_words,
required_words: options.req.body.required_words,
disapproved_words: options.req.body.disapproved_words,
product: options.req.body.product,
initiative_status_id: statuses.id,
platform_id: platforms.id,
fb_sponsor_name: options.req.body.fb_sponsor_name,
fb_sponsor_id: options.req.body.fb_sponsor_id,
fb_sponsor_url: options.req.body.fb_sponsor_url,
fb_sponsor_image: options.req.body.fb_sponsor_image,
fb_sponsor_category: options.req.body.fb_sponsor_category,
fb_is_verified: options.req.body.fb_is_verified,
youtube_tags: options.req.body.youtube_tags,
})
.then((initiatives) => {
where = { id: initiatives.id };
return db.initiatives.findOne({ where, include: [
db.platforms,
db.statuses
] })
.then(initiatives => {
options.initiatives = initiatives;
return Promise.resolve(options)
}).catch(err => Promise.reject(err));
}).catch(err => Promise.reject(err));
});
});
});
}