Initial content
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initializeCatalogModels = void 0;
|
||||
const sequelize_1 = require("sequelize");
|
||||
const catalog_models_1 = require("./catalog_models");
|
||||
const primaryKey = {
|
||||
id: { type: sequelize_1.DataTypes.INTEGER, autoIncrement: true, primaryKey: true }
|
||||
};
|
||||
const initializeCatalogModels = (sequelize) => {
|
||||
catalog_models_1.ProductModel.init({
|
||||
...primaryKey,
|
||||
name: { type: sequelize_1.DataTypes.STRING },
|
||||
description: { type: sequelize_1.DataTypes.STRING },
|
||||
price: { type: sequelize_1.DataTypes.DECIMAL(10, 2) }
|
||||
}, { sequelize });
|
||||
catalog_models_1.CategoryModel.init({
|
||||
...primaryKey,
|
||||
name: { type: sequelize_1.DataTypes.STRING }
|
||||
}, { sequelize });
|
||||
catalog_models_1.SupplierModel.init({
|
||||
...primaryKey,
|
||||
name: { type: sequelize_1.DataTypes.STRING }
|
||||
}, { sequelize });
|
||||
catalog_models_1.ProductModel.belongsTo(catalog_models_1.CategoryModel, { foreignKey: "categoryId", as: "category" });
|
||||
catalog_models_1.ProductModel.belongsTo(catalog_models_1.SupplierModel, { foreignKey: "supplierId", as: "supplier" });
|
||||
catalog_models_1.CategoryModel.hasMany(catalog_models_1.ProductModel, { foreignKey: "categoryId", as: "products" });
|
||||
catalog_models_1.SupplierModel.hasMany(catalog_models_1.ProductModel, { foreignKey: "supplierId", as: "products" });
|
||||
};
|
||||
exports.initializeCatalogModels = initializeCatalogModels;
|
||||
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SupplierModel = exports.CategoryModel = exports.ProductModel = void 0;
|
||||
const sequelize_1 = require("sequelize");
|
||||
class ProductModel extends sequelize_1.Model {
|
||||
}
|
||||
exports.ProductModel = ProductModel;
|
||||
class CategoryModel extends sequelize_1.Model {
|
||||
}
|
||||
exports.CategoryModel = CategoryModel;
|
||||
class SupplierModel extends sequelize_1.Model {
|
||||
}
|
||||
exports.SupplierModel = SupplierModel;
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initializeModels = exports.SupplierModel = exports.CategoryModel = exports.ProductModel = void 0;
|
||||
const catalog_helpers_1 = require("./catalog_helpers");
|
||||
var catalog_models_1 = require("./catalog_models");
|
||||
Object.defineProperty(exports, "ProductModel", { enumerable: true, get: function () { return catalog_models_1.ProductModel; } });
|
||||
Object.defineProperty(exports, "CategoryModel", { enumerable: true, get: function () { return catalog_models_1.CategoryModel; } });
|
||||
Object.defineProperty(exports, "SupplierModel", { enumerable: true, get: function () { return catalog_models_1.SupplierModel; } });
|
||||
const initializeModels = (sequelize) => {
|
||||
(0, catalog_helpers_1.initializeCatalogModels)(sequelize);
|
||||
};
|
||||
exports.initializeModels = initializeModels;
|
||||
Reference in New Issue
Block a user