UNPKG

@fabrix/spool-cart

Version:

Spool - eCommerce Spool for Fabrix

154 lines (153 loc) 4.51 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"); const enums_1 = require("../../enums"); const lodash_1 = require("lodash"); class CustomerUploadResolver extends spool_sequelize_1.SequelizeResolver { batch(options, batch) { const self = this; options.limit = options.limit || 100; options.offset = options.offset || 0; const recursiveQuery = function (opts) { let count = 0; return self.findAndCountAll(opts) .then(results => { count = results.count; return batch(results.rows); }) .then(batched => { if (count > opts.offset + opts.limit) { opts.offset = opts.offset + opts.limit; return recursiveQuery(opts); } else { return batched; } }); }; return recursiveQuery(options); } } exports.CustomerUploadResolver = CustomerUploadResolver; class CustomerUpload extends common_1.FabrixModel { static get resolver() { return CustomerUploadResolver; } static config(app, Sequelize) { return { options: { underscored: true } }; } static schema(app, Sequelize) { return { upload_id: { type: Sequelize.STRING }, account_balance: { type: Sequelize.INTEGER }, email: { type: Sequelize.STRING }, first_name: { type: Sequelize.STRING }, last_name: { type: Sequelize.STRING }, company: { type: Sequelize.STRING }, phone: { type: Sequelize.STRING }, 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 }, state: { type: Sequelize.ENUM, values: lodash_1.values(enums_1.CUSTOMER_STATE), defaultValue: enums_1.CUSTOMER_STATE.ENABLED }, type: { type: Sequelize.STRING, defaultValue: 'default' }, collections: { type: Sequelize.JSONB, defaultValue: [] }, tags: { type: Sequelize.JSONB, defaultValue: [] }, accounts: { type: Sequelize.JSONB, defaultValue: [] }, users: { type: Sequelize.JSONB, defaultValue: [] }, discounts: { type: Sequelize.JSONB, defaultValue: [] }, image: { type: Sequelize.STRING }, image_alt: { type: Sequelize.STRING } }; } } exports.CustomerUpload = CustomerUpload;