UNPKG

larvitorder

Version:
84 lines 2.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OrderLib = exports.Orders = exports.Order = exports.Helpers = void 0; const larvitdbmigration_1 = require("larvitdbmigration"); const helpers_1 = require("./helpers"); const larvitutils_1 = require("larvitutils"); const order_1 = require("./order"); const orders_1 = require("./orders"); var helpers_2 = require("./helpers"); Object.defineProperty(exports, "Helpers", { enumerable: true, get: function () { return helpers_2.Helpers; } }); var order_2 = require("./order"); Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return order_2.Order; } }); var orders_2 = require("./orders"); Object.defineProperty(exports, "Orders", { enumerable: true, get: function () { return orders_2.Orders; } }); class OrderLib { constructor(options) { if (!options.db) throw new Error('Required option "db" is missing'); this.db = options.db; this.log = options.log ?? new larvitutils_1.Log(); this.lUtils = new larvitutils_1.Utils(); this.helpers = new helpers_1.Helpers({ db: this.db, lUtils: this.lUtils, log: this.log }); } async runDbMigrations() { const dbMigration = new larvitdbmigration_1.DbMigration({ dbType: 'mariadb', dbDriver: this.db, log: this.log, tableName: 'orders_db_version', migrationScriptPath: __dirname + '/../dbmigration', }); await dbMigration.run(); } async loadOrderFieldsToCache() { await this.helpers.loadOrderFieldsToCache(); await this.helpers.loadRowFieldsToCache(); } createOrder(options) { const order = new order_1.Order({ db: this.db, log: this.log, lUtils: this.lUtils, ...options, }); return order; } async loadOrder(uuid) { const order = new order_1.Order({ db: this.db, log: this.log, lUtils: this.lUtils, uuid, }); const loaded = await order.loadFromDb(); if (!loaded) { return undefined; } return order; } async getOrders(options = {}) { const orders = new orders_1.Orders({ db: this.db, log: this.log, lUtils: this.lUtils, helpers: this.helpers, ...options, }); return orders.get(); } async removeOrder(uuid) { const order = new order_1.Order({ db: this.db, log: this.log, lUtils: this.lUtils, uuid, }); await order.rm(); } async getFieldValues(options) { return await this.helpers.getFieldValues(options); } } exports.OrderLib = OrderLib; //# sourceMappingURL=index.js.map