add: bill module
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
import { FilterQuery } from "@mikro-orm/core";
|
||||
import { EntityRepository } from "@mikro-orm/postgresql";
|
||||
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { BillListQueryDto } from "../dto/bill-list-query.dto";
|
||||
import { Bill } from "../entities/bill.entity";
|
||||
|
||||
export class BillsRepository extends EntityRepository<Bill> {
|
||||
async getBillsList(queryDto: BillListQueryDto, businessId: string) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const where: FilterQuery<Bill> = {
|
||||
business: { id: businessId },
|
||||
};
|
||||
|
||||
if (queryDto.type) {
|
||||
where.type = queryDto.type;
|
||||
}
|
||||
|
||||
if (queryDto.since || queryDto.to) {
|
||||
where.createdAt = {};
|
||||
if (queryDto.since) {
|
||||
(where.createdAt as Record<string, unknown>).$gte = new Date(queryDto.since);
|
||||
}
|
||||
if (queryDto.to) {
|
||||
(where.createdAt as Record<string, unknown>).$lte = new Date(queryDto.to);
|
||||
}
|
||||
}
|
||||
|
||||
return this.findAndCount(where, {
|
||||
populate: ["invoices"],
|
||||
orderBy: { createdAt: "DESC" },
|
||||
limit,
|
||||
offset: skip,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user