UNPKG

@speakr/speakr-module-services

Version:
34 lines (29 loc) 638 B
"use strict"; const db = require('../../db/'); module.exports = { restoreCarts }; function restoreCarts(options) { const ids = Array.isArray(options.accounts) ? options.accounts.map(a => a.id) : [options.accounts.id]; return db.accounts_carts.findAll({ where: { account_id: { $in: ids } }, paranoid: false }) .then(carts => { const promises = carts.map(cart => { if(cart.deleted_at !== null) { return db.accounts_carts.restore({ where: { id: cart.id } }); } else { return cart; } }) return Promise.all(promises); }) .then(() => { return Promise.resolve(options); }) }