add: bill module

This commit is contained in:
2026-02-16 23:46:59 +03:30
parent eaffe6f8b0
commit f9f397e92a
13 changed files with 398 additions and 1 deletions
+37
View File
@@ -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,
});
}
}