@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
28 lines (23 loc) • 588 B
JavaScript
;
const db = require('../../db');
module.exports = function (options) {
let where = {
$or: [
{parent_id: options.accounts.id},
{id: options.accounts.id}
]
};
return db.accounts.findAll({where: where})
.then(accounts => {
let ids = accounts.map(account => account.id);
return db.accounts_networks.findAll({
where: {account_id: {$in: ids}}
})
})
.then(accounts_networks => {
return db.metrics.destroy({
where: { accounts_networks_id: { $in: accounts_networks.map(an => an.id) }}
})
})
.then(() => Promise.resolve(options) );
};