fix: import the danakservice module in subscription module

This commit is contained in:
mahyargdz
2025-02-09 10:44:09 +03:30
parent bc96f62782
commit 75fef18317
7 changed files with 67 additions and 11 deletions
@@ -1,13 +1,48 @@
import { Injectable } from "@nestjs/common";
import { BadRequestException, Injectable } from "@nestjs/common";
import { ServiceMessage, SubscriptionMessage } from "../../../common/enums/message.enum";
import { DanakServicesService } from "../../danak-services/providers/danak-services.service";
import { CreateSubscriptionPlanDto } from "../DTO/create-subscription.dto";
import { SubscriptionsPlanRepository } from "../repositories/subscriptions.repository";
@Injectable()
export class SubscriptionsService {
constructor(private readonly subscriptionsPlanRepository: SubscriptionsPlanRepository) {}
constructor(
private readonly subscriptionsPlanRepository: SubscriptionsPlanRepository,
private readonly danakServices: DanakServicesService,
) {}
//************************************ */
async createSubscriptionsPlan(createDto: CreateSubscriptionPlanDto) {
console.log(this.subscriptionsPlanRepository, createDto);
const danakService = await this.danakServices.findServiceById(createDto.serviceId);
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
const existSubscription = await this.subscriptionsPlanRepository.findOneByName(createDto.name);
if (existSubscription) throw new BadRequestException(SubscriptionMessage.NAME_EXIST);
const subscription = this.subscriptionsPlanRepository.create(createDto);
await this.subscriptionsPlanRepository.save(subscription);
return {
message: SubscriptionMessage.CREATED,
subscription,
};
}
//************************************ */
async updateSubscriptionPlan(id: string, updateDto: CreateSubscriptionPlanDto) {
const danakService = await this.danakServices.findServiceById(updateDto.serviceId);
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
const subscription = await this.subscriptionsPlanRepository.findOneBy({ id });
if (!subscription) throw new BadRequestException(SubscriptionMessage.NOT_FOUND);
const existSubscription = await this.subscriptionsPlanRepository.findOneByName(updateDto.name, id);
if (existSubscription) throw new BadRequestException(SubscriptionMessage.NAME_EXIST);
await this.subscriptionsPlanRepository.update(id, updateDto);
await this.subscriptionsPlanRepository.save({ ...subscription, ...updateDto, service: danakService });
return {
message: SubscriptionMessage.UPDATED,
subscription,
};
}
}