@tomei/product
Version:
NestJS package for product module
203 lines • 10.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProductJewelleryRepository = void 0;
const product_jewellery_entity_1 = require("../../entities/product-jewellery.entity");
const general_1 = require("@tomei/general");
const product_brand_entity_1 = require("../../entities/product-brand.entity");
const settings_category_entity_1 = require("../../entities/settings-category.entity");
const store_entity_1 = require("../../entities/store.entity");
const settings_group_entity_1 = require("../../entities/settings-group.entity");
const settings_collection_entity_1 = require("../../entities/settings-collection.entity");
const product_certificate_entity_1 = require("../../entities/product-certificate.entity");
const product_tag_entity_1 = require("../../entities/product-tag.entity");
const product_customize_option_entity_1 = require("../../entities/product-customize-option.entity");
const product_material_entity_1 = require("../../entities/product-material.entity");
const product_with_inventory_entity_1 = require("../../entities/product-with-inventory.entity");
const product_entity_1 = require("../../entities/product.entity");
class ProductJewelleryRepository extends general_1.RepositoryBase {
constructor() {
super(product_jewellery_entity_1.ProductJewelleryModel);
}
async findAllWithPagination(options) {
const { productQuery, rows = 10, offset = 0, transaction } = options;
if (!productQuery) {
throw new Error('productQuery is required');
}
if (!rows) {
throw new Error('rows is required');
}
if (offset === undefined || offset === null) {
throw new Error('offset is required');
}
const queryOptions = {
include: [
{
model: product_with_inventory_entity_1.ProductWithInventoryModel,
include: [
{
model: product_entity_1.ProductModel,
where: productQuery.whereProduct &&
Object.keys(productQuery.whereProduct).length !== 0
? productQuery.whereProduct
: null,
include: [
{
model: store_entity_1.StoreModel,
where: productQuery.StoreId
? {
StoreId: productQuery.StoreId,
}
: null,
},
{
model: settings_category_entity_1.SettingsCategoryModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
where: productQuery.CategoryCode
? {
Code: productQuery.CategoryCode,
}
: null,
},
{
model: settings_category_entity_1.SettingsCategoryModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
where: productQuery.CategoryCode
? {
Code: productQuery.CategoryCode,
}
: null,
},
{
model: settings_collection_entity_1.SettingsCollectionModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
where: productQuery.CollectionCode
? {
Code: productQuery.CollectionCode,
}
: null,
},
{
model: settings_group_entity_1.SettingsGroupModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
where: productQuery.GroupCode
? {
Code: productQuery.GroupCode,
}
: null,
},
{
model: product_certificate_entity_1.ProductCertificateModel,
where: productQuery.CertificateId
? {
CertificateId: productQuery.CertificateId,
}
: null,
},
{
model: product_tag_entity_1.ProductTagModel,
where: productQuery.TagId
? {
TagId: productQuery.TagId,
}
: null,
},
{
model: product_brand_entity_1.ProductBrandModel,
where: productQuery.Brand
? {
Brand: productQuery.Brand,
}
: null,
},
{
model: product_customize_option_entity_1.ProductCustomizeOptionModel,
where: productQuery.CustomizeOptionId
? {
CustomizeOptionId: productQuery.CustomizeOptionId,
}
: null,
},
{
model: product_material_entity_1.ProductMaterialModel,
where: productQuery.MaterialId
? {
MaterialId: productQuery.MaterialId,
}
: null,
},
],
},
],
},
],
transaction,
};
try {
const result = await product_jewellery_entity_1.ProductJewelleryModel.findAndCountAll(queryOptions);
return result;
}
catch (error) {
throw new Error(`An Error occured when fetching product jewelleries: ${error.message}`);
}
}
async findAll(transaction) {
const queryOptions = {
include: [
{
model: product_with_inventory_entity_1.ProductWithInventoryModel,
include: [
{
model: product_entity_1.ProductModel,
include: [
{
model: store_entity_1.StoreModel,
},
{
model: settings_category_entity_1.SettingsCategoryModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
},
{
model: settings_category_entity_1.SettingsCategoryModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
},
{
model: settings_collection_entity_1.SettingsCollectionModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
},
{
model: settings_group_entity_1.SettingsGroupModel,
attributes: ['Code', 'Name', 'Description', 'Status'],
},
{
model: product_certificate_entity_1.ProductCertificateModel,
},
{
model: product_tag_entity_1.ProductTagModel,
},
{
model: product_brand_entity_1.ProductBrandModel,
},
{
model: product_customize_option_entity_1.ProductCustomizeOptionModel,
},
{
model: product_material_entity_1.ProductMaterialModel,
},
],
},
],
},
],
transaction,
};
try {
const result = await product_jewellery_entity_1.ProductJewelleryModel.findAll(queryOptions);
return result;
}
catch (error) {
throw new Error(`An Error occured when fetching product jewellery: ${error.message}`);
}
}
}
exports.ProductJewelleryRepository = ProductJewelleryRepository;
//# sourceMappingURL=jewellery-product.repository.js.map