@fabrix/spool-cart
Version:
Spool - eCommerce Spool for Fabrix
119 lines (118 loc) • 3.44 kB
JavaScript
"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 OrderUploadResolver 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.OrderUploadResolver = OrderUploadResolver;
class OrderUpload extends common_1.FabrixModel {
static get resolver() {
return OrderUploadResolver;
}
static config(app, Sequelize) {
return {
options: {
underscored: true
}
};
}
static schema(app, Sequelize) {
return {
upload_id: {
type: Sequelize.STRING
},
customer: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
status: {
type: Sequelize.STRING
},
order_items: {
type: Sequelize.JSONB,
defaultValue: []
},
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
},
tags: {
type: Sequelize.JSON,
defaultValue: []
},
note: {
type: Sequelize.TEXT
}
};
}
}
exports.OrderUpload = OrderUpload;