@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
31 lines (25 loc) • 605 B
JavaScript
;
const db = require('../../db');
module.exports = function (options) {
let ids;
let where = {
$or: [
{parent_id: options.accounts.id},
{id: options.accounts.id}
]
};
return db.accounts.findAll({where: where})
.then(accounts => {
ids = accounts.map(account => account.id);
return db.accounts_networks.update({
deleted: true, last_deleted_date: Date.now()
}, {
where: {account_id: {$in: ids}}}
)})
.then(() => {
return db.accounts_networks.destroy({
where: { account_id: {$in: ids } }
})
})
.then(() => Promise.resolve(options) );
};