UNPKG

@tomei/product

Version:

NestJS package for product module

58 lines (53 loc) 1.5 kB
import { RepositoryBase, IRepositoryBase } from '@tomei/general'; import { ProductBrandModel } from '../../entities/product-brand.entity'; export class ProductBrandRepository extends RepositoryBase<ProductBrandModel> implements IRepositoryBase<ProductBrandModel> { constructor() { super(ProductBrandModel); } async findByPk(brand: string, transaction: any): Promise<ProductBrandModel> { try { const options = { where: { Brand: brand, }, transaction: transaction, }; const result = await ProductBrandModel.findOne(options); return result; } catch (error) { throw new Error(`An Error occured when fetching : ${error.message}`); } } async delete(brand: string, dbTransaction?: any) { try { const options = { where: { Brand: brand, }, transaction: dbTransaction, }; await ProductBrandModel.destroy(options); } catch (error) { throw new Error(`An Error occured when delete : ${error.message}`); } } async findAndCountAll(options?: any): Promise<{ rows: ProductBrandModel[]; count: number; }> { try { let tags: any; if (options) { tags = await ProductBrandModel.findAndCountAll(options); } else { tags = await ProductBrandModel.findAndCountAll(); } return tags; } catch (error) { throw new Error(`An Error occured when retriving : ${error.message}`); } } }