@tomei/product
Version:
NestJS package for product module
58 lines (53 loc) • 1.48 kB
text/typescript
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
import { ProductVariantModel } from '../../entities/product-variant.entity';
export class ProductVariantRepository
extends RepositoryBase<ProductVariantModel>
implements IRepositoryBase<ProductVariantModel>
{
constructor() {
super(ProductVariantModel);
}
async findByPk(
variantId: string,
transaction: any,
): Promise<ProductVariantModel> {
try {
const options = {
where: {
VariantId: variantId,
},
transaction,
};
const result = await ProductVariantModel.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 ProductVariantModel.destroy(options);
} catch (error) {
throw new Error(`An Error occured when delete : ${error.message}`);
}
}
async findAndCountAll(options?: any) {
try {
let variants: any;
if (options) {
variants = await ProductVariantModel.findAndCountAll(options);
} else {
variants = await ProductVariantModel.findAndCountAll();
}
return variants;
} catch (error) {
throw new Error(`An Error occured when retriving : ${error.message}`);
}
}
}