UNPKG

@speakr/speakr-module-services

Version:
29 lines (25 loc) 627 B
'use strict'; const db = require('../../db'); module.exports = { byIdHash, byIdHashAndTrackUser }; function byIdHash(id_hash) { return db.line_items.destroy({ where: {id_hash: id_hash}}) .then((res) => res) .catch((err) => err); } function byIdHashAndTrackUser(id_hash, user_id_hash) { return db.line_items.findAll({ where: { id_hash: id_hash } }) .then(items => { const promises = items.map(item => { return item.updateAttributes({ deleted_by: user_id_hash }); }); return db.Sequelize.Promise.all(promises); }) .then(items => db.line_items.destroy({ where: { id_hash: id_hash }})) }