46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { InjectRepository } from "@nestjs/typeorm";
|
|
import { IsNull, Repository } from "typeorm";
|
|
|
|
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
|
import { GetSupportPlanListQueryDto } from "../DTO/get-support-plan-list-query.dto";
|
|
import { SupportPlan } from "../entities/support-plan.entity";
|
|
|
|
@Injectable()
|
|
export class SupportPlanRepository extends Repository<SupportPlan> {
|
|
constructor(@InjectRepository(SupportPlan) supportPlanRepo: Repository<SupportPlan>) {
|
|
super(supportPlanRepo.target, supportPlanRepo.manager, supportPlanRepo.queryRunner);
|
|
}
|
|
|
|
//***************************************** */
|
|
async getSupportPlansListAdmin(queryDto: GetSupportPlanListQueryDto) {
|
|
const { limit, skip } = PaginationUtils(queryDto);
|
|
const query = this.createQueryBuilder("supportPlan").where("supportPlan.deletedAt IS NULL");
|
|
|
|
if (queryDto.q) {
|
|
query.andWhere("supportPlan.name ILIKE :q OR supportPlan.description ILIKE :q", { q: `%${queryDto.q}%` });
|
|
}
|
|
|
|
if (queryDto.isActive !== undefined) {
|
|
query.andWhere("supportPlan.isActive = :isActive", { isActive: queryDto.isActive === 1 });
|
|
}
|
|
|
|
query.skip(skip).take(limit).orderBy("supportPlan.createdAt", "DESC");
|
|
return query.getManyAndCount();
|
|
}
|
|
|
|
async getSupportPlansListUser() {
|
|
return this.createQueryBuilder("supportPlan")
|
|
.leftJoinAndSelect("supportPlan.features", "features")
|
|
.where("supportPlan.isActive = :isActive", { isActive: true })
|
|
.andWhere("supportPlan.deletedAt IS NULL")
|
|
.orderBy("supportPlan.price", "ASC")
|
|
.addOrderBy("features.featureKey", "ASC")
|
|
.getMany();
|
|
}
|
|
//***************************************** */
|
|
async getSupportPlanById(id: string) {
|
|
return this.findOne({ where: { id, deletedAt: IsNull() }, relations: { features: true } });
|
|
}
|
|
}
|