invoice
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { EntityRepository } from "@mikro-orm/core";
|
||||
import { EntityRepository } from "@mikro-orm/postgresql";
|
||||
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { CompanyListQueryDto } from "../DTO/company-list-query.dto";
|
||||
@@ -9,17 +9,57 @@ export class CompanyRepository extends EntityRepository<Company> {
|
||||
async getCompaniesListForAdmin(queryDto: CompanyListQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
return await this.findAndCount(
|
||||
{
|
||||
const qb = this.createQueryBuilder("company")
|
||||
.select([
|
||||
"company.id",
|
||||
"company.name",
|
||||
"company.status",
|
||||
"company.isActive",
|
||||
"company.createdAt",
|
||||
"industry.id",
|
||||
"industry.title",
|
||||
"user.id",
|
||||
"user.firstName",
|
||||
"user.lastName",
|
||||
"(SELECT COUNT(*) FROM invoice WHERE invoice.company_id = company.id) as invoiceCount",
|
||||
])
|
||||
.leftJoin("company.industry", "industry")
|
||||
.leftJoin("company.user", "user")
|
||||
.where({
|
||||
deletedAt: null,
|
||||
...(queryDto.status && { status: queryDto.status }),
|
||||
...(queryDto.q && { name: { $ilike: `%${queryDto.q}%` } }),
|
||||
...(queryDto.industryId && { industry: { id: queryDto.industryId } }),
|
||||
...(queryDto.isActive !== undefined && { isActive: queryDto.isActive === 1 }),
|
||||
...(queryDto.registrationDate && { createdAt: { $gte: queryDto.registrationDate, $lte: queryDto.registrationDate } }),
|
||||
...(queryDto.name && { name: { $ilike: `%${queryDto.name}%` } }),
|
||||
},
|
||||
{ offset: skip, limit, orderBy: { createdAt: "DESC" } },
|
||||
);
|
||||
});
|
||||
|
||||
if (queryDto.q) {
|
||||
qb.andWhere({ name: { $ilike: `%${queryDto.q}%` } });
|
||||
}
|
||||
|
||||
if (queryDto.industryId) {
|
||||
qb.andWhere({ industry: { id: queryDto.industryId } });
|
||||
}
|
||||
|
||||
if (queryDto.registrationDate) {
|
||||
qb.andWhere({
|
||||
createdAt: {
|
||||
$gte: queryDto.registrationDate,
|
||||
$lte: queryDto.registrationDate,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (queryDto.name) {
|
||||
qb.andWhere({ name: { $ilike: `%${queryDto.name}%` } });
|
||||
}
|
||||
|
||||
qb.orderBy({ createdAt: "DESC" }).limit(limit).offset(skip);
|
||||
|
||||
return qb.getResultAndCount();
|
||||
|
||||
// // Transform the result to include invoiceCount as a number
|
||||
// const transformedCompanies = companies.map((company) => ({
|
||||
// ...company,
|
||||
// invoiceCount: parseInt(company.invoiceCount, 10),
|
||||
// }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user