UNPKG

@tomei/product

Version:

NestJS package for product module

58 lines (53 loc) 1.6 kB
import { RepositoryBase, IRepositoryBase } from '@tomei/general'; import { ProductVariantWithInventoryModel } from '../../entities/product-variant-with-inventory.entity'; export class ProductVariantWithInventoryRepository extends RepositoryBase<ProductVariantWithInventoryModel> implements IRepositoryBase<ProductVariantWithInventoryModel> { constructor() { super(ProductVariantWithInventoryModel); } async findByPk( variantId: string, transaction: any, ): Promise<ProductVariantWithInventoryModel> { try { const options = { where: { VariantId: variantId, }, transaction, }; const result = await ProductVariantWithInventoryModel.findOne(options); return result; } catch (error) { throw new Error(`An Error occured when fetching : ${error.message}`); } } async delete(variantId: string, transaction?: any) { try { const options = { where: { VariantId: variantId, }, transaction, }; await ProductVariantWithInventoryModel.destroy(options); } catch (error) { throw new Error(`An Error occured when delete : ${error.message}`); } } async findAndCountAll(options?: any) { try { let vwi: any; if (options) { vwi = await ProductVariantWithInventoryModel.findAndCountAll(options); } else { vwi = await ProductVariantWithInventoryModel.findAndCountAll(); } return vwi; } catch (error) { throw new Error(`An Error occured when retriving : ${error.message}`); } } }