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