@tomei/rental
Version:
Tomei Rental Package
55 lines (49 loc) • 1.42 kB
text/typescript
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
import { RentalPriceModel } from '../../models/rental-price.entity';
export class RentalPriceRepository
extends RepositoryBase<RentalPriceModel>
implements IRepositoryBase<RentalPriceModel>
{
constructor() {
super(RentalPriceModel);
}
async findByPk(
id: string,
transaction?: any,
): Promise<RentalPriceModel | null> {
try {
const result = await RentalPriceModel.findByPk(id, {
transaction: transaction,
});
return result;
} catch (error) {
throw new Error(`An Error occured when fetching : ${error.message}`);
}
}
async delete(RentalPriceId: string, dbTransaction?: any) {
try {
const options = {
where: {
RentalPriceId: RentalPriceId,
},
transaction: dbTransaction,
};
await RentalPriceModel.destroy(options);
} catch (error) {
throw new Error(`An Error occured when delete : ${error.message}`);
}
}
async findAndCountAll(options?: any) {
try {
let RentalPrices: any;
if (options) {
RentalPrices = await RentalPriceModel.findAndCountAll(options);
} else {
RentalPrices = await RentalPriceModel.findAndCountAll();
}
return RentalPrices;
} catch (error) {
throw new Error(`An Error occured when retriving : ${error.message}`);
}
}
}