UNPKG

@speakr/speakr-module-services

Version:
38 lines (28 loc) 752 B
"use strict"; const db = require('../../db/'); module.exports = { allCartsByAccountId }; function allCartsByAccountId(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_carts.destroy({ where: {account_id: {$in: ids}} }) }) .then(() => Promise.resolve(options)) .catch((error) => { return Promise.reject({ code: 400, message: 'could not remove account from groups', purpose: 'something went wrong when an accounts groups were being deleted ' + error }) }); }