UNPKG

@speakr/speakr-module-services

Version:
78 lines (71 loc) 2.59 kB
"use strict"; module.exports = { publicData, typeaheadPublicData }; function publicData(options) { if (Array.isArray(options.accounts)) { options.accounts = options.accounts.map(account => { return { id: account.id, active: account.active, parent_id: account.parent_id, platform: account.platform.name, validated: account.validated, current_username: account.current_username, platform_user_image: account.platform_user_image, platform_user_id: account.platform_user_id, fair_offer_price: account.fair_offer_price, min_offer_price: account.min_offer_price, deleted_at: account.deleted_at, networks: account.networks.map(network => network.name) }; }); } else { let account = options.accounts; options.accounts = { id: account.id, active: account.active, parent_id: account.parent_id, platform: account.platform.name, validated: account.validated, current_username: account.current_username, platform_user_image: account.platform_user_image, platform_user_id: account.platform_user_id, fair_offer_price: account.fair_offer_price, min_offer_price: account.min_offer_price, deleted_at: account.deleted_at, networks: account.networks.map(network => network.name) }; } return Promise.resolve(options); } function typeaheadPublicData(options) { return Promise.resolve( options.accounts.map(resAccount => { let account = resAccount.dataValues ? resAccount.dataValues : resAccount; let platform = account.platform.dataValues ? account.platform.dataValues : account.platform; let accountNetwork = account.accounts_networks.dataValues ? account.accounts_networks.dataValues : account.accounts_networks[0]; let innerNetwork = accountNetwork.network.dataValues ? accountNetwork.network.dataValues : accountNetwork.network; return { account_id: account.id, influencer_id: account.influencer_id, account_email: account.account_email, current_username: account.current_username, platform_user_image: account.platform_user_image, platform_user_id: account.platform_user_id, network_id_hash: innerNetwork.id_hash, external: accountNetwork.external, platform_id: platform.id, platform: platform.name, parent_id: account.parent_id }; // end return obj }) // end accounts.map ); // end Promise.resolve }