UNPKG

@fabrix/spool-cart

Version:

Spool - eCommerce Spool for Fabrix

117 lines (116 loc) 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const common_1 = require("@fabrix/fabrix/dist/common"); const spool_sequelize_1 = require("@fabrix/spool-sequelize"); class VendorUploadResolver extends spool_sequelize_1.SequelizeResolver { batch(options, batch) { const self = this; options.limit = options.limit || 100; options.offset = options.offset || 0; options.regressive = options.regressive || false; const recursiveQuery = function (options) { let count = 0; return self.findAndCountAll(options) .then(results => { count = results.count; return batch(results.rows); }) .then(batched => { if (count >= (options.regressive ? options.limit : options.offset + options.limit)) { options.offset = options.regressive ? 0 : options.offset + options.limit; return recursiveQuery(options); } else { return Promise.resolve(); } }); }; return recursiveQuery(options); } } exports.VendorUploadResolver = VendorUploadResolver; class VendorUpload extends common_1.FabrixModel { static get resolver() { return VendorUploadResolver; } static config(app, Sequelize) { return { options: { underscored: true } }; } static schema(app, Sequelize) { return { upload_id: { type: Sequelize.STRING }, handle: { type: Sequelize.STRING, allowNull: false, set: function (val) { this.setDataValue('handle', app.services.ProxyCartService.handle(val)); } }, name: { type: Sequelize.STRING, set: function (val) { this.setDataValue('name', app.services.ProxyCartService.title(val)); } }, shipping_address_1: { type: Sequelize.STRING }, shipping_address_2: { type: Sequelize.STRING }, shipping_address_3: { type: Sequelize.STRING }, shipping_company: { type: Sequelize.STRING }, shipping_city: { type: Sequelize.STRING }, shipping_province: { type: Sequelize.STRING }, shipping_country: { type: Sequelize.STRING }, shipping_postal_code: { type: Sequelize.STRING }, billing_address_1: { type: Sequelize.STRING }, billing_address_2: { type: Sequelize.STRING }, billing_address_3: { type: Sequelize.STRING }, billing_company: { type: Sequelize.STRING }, billing_city: { type: Sequelize.STRING }, billing_province: { type: Sequelize.STRING }, billing_country: { type: Sequelize.STRING }, billing_postal_code: { type: Sequelize.STRING }, products: { type: Sequelize.JSONB, defaultValue: [] } }; } } exports.VendorUpload = VendorUpload;