@fabrix/spool-cart
Version:
Spool - eCommerce Spool for Fabrix
35 lines (34 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@fabrix/fabrix/dist/common");
const lodash_1 = require("lodash");
const errors_1 = require("@fabrix/spool-sequelize/dist/errors");
class ShopService extends common_1.FabrixService {
publish(type, event, options = {}) {
if (this.app.services.EventsService) {
options.include = options.include || [{
model: this.app.models.EventItem.instance,
as: 'objects'
}];
return this.app.services.EventsService.publish(type, event, options);
}
this.app.log.debug('spool-events is not installed, please install it to use publish');
return Promise.resolve();
}
create(data, options) {
const Shop = this.app.models.Shop;
return Shop.create(data, options);
}
update(shop, data, options) {
const Shop = this.app.models.Shop;
return Shop.resolve(shop, { transaction: options.transaction || null })
.then(_shop => {
if (!_shop) {
throw new errors_1.ModelError('E_NOT_FOUND', `Shop ${shop} not found`);
}
const resShop = lodash_1.defaultsDeep(_shop, data);
return resShop.save({ transaction: options.transaction || null });
});
}
}
exports.ShopService = ShopService;