feat: add support plan but not tested
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
|
||||
import { SupportPlanMessage } from "../../../common/enums/message.enum";
|
||||
import { CreateSupportPlanDto } from "../DTO/create-support-plan.dto";
|
||||
import { GetSupportPlanListQueryDto } from "../DTO/get-support-plan-list-query.dto";
|
||||
import { UpdateSupportPlanDto } from "../DTO/update-support-plan-feature.dto";
|
||||
import { SupportPlanRepository } from "../repositories/support-plan.repository";
|
||||
@Injectable()
|
||||
export class SupportPlansService {
|
||||
constructor(
|
||||
private readonly supportPlanRepo: SupportPlanRepository,
|
||||
// private readonly userSupportPlanRepo: UserSupportPlanRepository,
|
||||
) {}
|
||||
|
||||
async createSupportPlan(createSupportPlanDto: CreateSupportPlanDto) {
|
||||
const supportPlan = this.supportPlanRepo.create(createSupportPlanDto);
|
||||
await this.supportPlanRepo.save(supportPlan);
|
||||
return {
|
||||
message: SupportPlanMessage.SUPPORT_PLAN_CREATED,
|
||||
supportPlan,
|
||||
};
|
||||
}
|
||||
//***************************************** */
|
||||
async getSupportPlansList(queryDto: GetSupportPlanListQueryDto) {
|
||||
const [supportPlans, count] = await this.supportPlanRepo.getSupportPlansListAdmin(queryDto);
|
||||
return {
|
||||
supportPlans,
|
||||
count,
|
||||
paginate: true,
|
||||
};
|
||||
}
|
||||
//***************************************** */
|
||||
async getSupportPlanById(id: string) {
|
||||
const supportPlan = await this.supportPlanRepo.getSupportPlanById(id);
|
||||
if (!supportPlan) throw new BadRequestException(SupportPlanMessage.SUPPORT_PLAN_NOT_FOUND);
|
||||
|
||||
return {
|
||||
supportPlan,
|
||||
};
|
||||
}
|
||||
//***************************************** */
|
||||
async deleteSupportPlanById(id: string) {
|
||||
const supportPlan = await this.supportPlanRepo.getSupportPlanById(id);
|
||||
if (!supportPlan) throw new BadRequestException(SupportPlanMessage.SUPPORT_PLAN_NOT_FOUND);
|
||||
await this.supportPlanRepo.softDelete(id);
|
||||
|
||||
return {
|
||||
message: SupportPlanMessage.SUPPORT_PLAN_DELETED,
|
||||
};
|
||||
}
|
||||
//***************************************** */
|
||||
async updateSupportPlanById(id: string, updateSupportPlanDto: UpdateSupportPlanDto) {
|
||||
const supportPlan = await this.supportPlanRepo.getSupportPlanById(id);
|
||||
if (!supportPlan) throw new BadRequestException(SupportPlanMessage.SUPPORT_PLAN_NOT_FOUND);
|
||||
|
||||
await this.supportPlanRepo.save({ ...supportPlan, ...updateSupportPlanDto });
|
||||
|
||||
return {
|
||||
message: SupportPlanMessage.SUPPORT_PLAN_UPDATED,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user