fix: import the danakservice module in subscription module
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user