fix: import the danakservice module in subscription module
This commit is contained in:
@@ -123,6 +123,7 @@ export const enum ServiceMessage {
|
|||||||
AUTHOR_LENGTH = "نویسنده سرویس باید بین 3 تا 100 کاراکتر باشد",
|
AUTHOR_LENGTH = "نویسنده سرویس باید بین 3 تا 100 کاراکتر باشد",
|
||||||
SERVICE_NOT_EXIST = "سرویس مورد نظر یافت نشد",
|
SERVICE_NOT_EXIST = "سرویس مورد نظر یافت نشد",
|
||||||
NAME_EXIST = "سرویس با این نام قبلا ثبت شده است",
|
NAME_EXIST = "سرویس با این نام قبلا ثبت شده است",
|
||||||
|
SERVICE_NOT_FOUND_BY_ID = "سرویسی با این شناسه یافت نشد",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum AnnouncementMessage {
|
export const enum AnnouncementMessage {
|
||||||
@@ -281,4 +282,12 @@ export const enum SubscriptionMessage {
|
|||||||
NAME_LENGTH = "نام باید بین ۳ تا ۱۰۰ کاراکتر باشد",
|
NAME_LENGTH = "نام باید بین ۳ تا ۱۰۰ کاراکتر باشد",
|
||||||
IS_ACTIVE_REQUIRED = "وضعیت فعال بودن مورد نیاز است",
|
IS_ACTIVE_REQUIRED = "وضعیت فعال بودن مورد نیاز است",
|
||||||
IS_ACTIVE_SHOULD_BE_BOOLEAN = "وضعیت فعال بودن باید یک بولین باشد",
|
IS_ACTIVE_SHOULD_BE_BOOLEAN = "وضعیت فعال بودن باید یک بولین باشد",
|
||||||
|
SERVICE_REQUIRED = "سرویس مورد نیاز است",
|
||||||
|
SERVICE_MUST_BE_UUID = "شناسه سرویس باید یک UUID معتبر باشد",
|
||||||
|
PRICE_SHOULD_BE_POSITIVE = "قیمت باید عددی مثبت باشد",
|
||||||
|
PRICE_SHOULD_BE_GREATER_THAN_100_000 = "قیمت باید بیشتر از ۱۰۰,۰۰۰ تومان باشد",
|
||||||
|
NAME_EXIST = "نام اشتراک قبلا ثبت شده است",
|
||||||
|
CREATED = "اشتراک با موفقیت ایجاد شد",
|
||||||
|
NOT_FOUND = "اشتراک یافت نشد",
|
||||||
|
UPDATED = "اشتراک با موفقیت به روز رسانی شد",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger";
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
import { IsBoolean, IsInt, IsNotEmpty, IsString, Length } from "class-validator";
|
import { IsBoolean, IsInt, IsNotEmpty, IsString, IsUUID, Length, Min } from "class-validator";
|
||||||
|
|
||||||
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ export class CreateSubscriptionPlanDto {
|
|||||||
|
|
||||||
@IsNotEmpty({ message: SubscriptionMessage.PRICE_REQUIRED })
|
@IsNotEmpty({ message: SubscriptionMessage.PRICE_REQUIRED })
|
||||||
@IsInt({ message: SubscriptionMessage.PRICE_SHOULD_BE_INT })
|
@IsInt({ message: SubscriptionMessage.PRICE_SHOULD_BE_INT })
|
||||||
|
@Min(100_000, { message: SubscriptionMessage.PRICE_SHOULD_BE_GREATER_THAN_100_000 })
|
||||||
@ApiProperty({ description: "the price of the subscription plan", example: 10_000_000 })
|
@ApiProperty({ description: "the price of the subscription plan", example: 10_000_000 })
|
||||||
price: number;
|
price: number;
|
||||||
|
|
||||||
@@ -24,4 +25,9 @@ export class CreateSubscriptionPlanDto {
|
|||||||
@IsBoolean({ message: SubscriptionMessage.IS_ACTIVE_SHOULD_BE_BOOLEAN })
|
@IsBoolean({ message: SubscriptionMessage.IS_ACTIVE_SHOULD_BE_BOOLEAN })
|
||||||
@ApiProperty({ description: "the status of the subscription plan", example: true })
|
@ApiProperty({ description: "the status of the subscription plan", example: true })
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
|
||||||
|
@IsNotEmpty({ message: SubscriptionMessage.SERVICE_REQUIRED })
|
||||||
|
@IsUUID("4", { message: SubscriptionMessage.SERVICE_MUST_BE_UUID })
|
||||||
|
@ApiProperty({ description: "Service ID", example: "d290f1ee-6c54-4b01-90e6-d701748f0851" })
|
||||||
|
serviceId: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { DanakService } from "../../danak-services/entities/danak-service.entity
|
|||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class SubscriptionPlan extends BaseEntity {
|
export class SubscriptionPlan extends BaseEntity {
|
||||||
@Column({ type: "varchar", length: 150, nullable: false })
|
@Column({ type: "varchar", length: 150, nullable: false, unique: true })
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column({ type: "int", nullable: false })
|
@Column({ type: "int", nullable: false })
|
||||||
|
|||||||
@@ -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 { CreateSubscriptionPlanDto } from "../DTO/create-subscription.dto";
|
||||||
import { SubscriptionsPlanRepository } from "../repositories/subscriptions.repository";
|
import { SubscriptionsPlanRepository } from "../repositories/subscriptions.repository";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubscriptionsService {
|
export class SubscriptionsService {
|
||||||
constructor(private readonly subscriptionsPlanRepository: SubscriptionsPlanRepository) {}
|
constructor(
|
||||||
|
private readonly subscriptionsPlanRepository: SubscriptionsPlanRepository,
|
||||||
|
private readonly danakServices: DanakServicesService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
//************************************ */
|
||||||
async createSubscriptionsPlan(createDto: CreateSubscriptionPlanDto) {
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { InjectRepository } from "@nestjs/typeorm";
|
import { InjectRepository } from "@nestjs/typeorm";
|
||||||
import { Repository } from "typeorm";
|
import { Not, Repository } from "typeorm";
|
||||||
|
|
||||||
import { SubscriptionPlan } from "../entities/subscription.entity";
|
import { SubscriptionPlan } from "../entities/subscription.entity";
|
||||||
|
|
||||||
@@ -9,4 +9,8 @@ export class SubscriptionsPlanRepository extends Repository<SubscriptionPlan> {
|
|||||||
constructor(@InjectRepository(SubscriptionPlan) subscriptionPlanRepository: Repository<SubscriptionPlan>) {
|
constructor(@InjectRepository(SubscriptionPlan) subscriptionPlanRepository: Repository<SubscriptionPlan>) {
|
||||||
super(subscriptionPlanRepository.target, subscriptionPlanRepository.manager, subscriptionPlanRepository.queryRunner);
|
super(subscriptionPlanRepository.target, subscriptionPlanRepository.manager, subscriptionPlanRepository.queryRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findOneByName(name: string, id?: string): Promise<SubscriptionPlan | null> {
|
||||||
|
return this.findOneBy({ name, ...(id && { id: Not(id) }) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Controller } from "@nestjs/common";
|
import { Body, Controller, Post } from "@nestjs/common";
|
||||||
import { ApiOperation } from "@nestjs/swagger";
|
import { ApiOperation } from "@nestjs/swagger";
|
||||||
|
|
||||||
|
import { CreateSubscriptionPlanDto } from "./DTO/create-subscription.dto";
|
||||||
import { SubscriptionsService } from "./providers/subscriptions.service";
|
import { SubscriptionsService } from "./providers/subscriptions.service";
|
||||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||||
import { Roles } from "../../common/decorators/roles.decorator";
|
import { Roles } from "../../common/decorators/roles.decorator";
|
||||||
@@ -13,8 +14,8 @@ export class SubscriptionsController {
|
|||||||
@ApiOperation({ summary: "Create a subscription plan" })
|
@ApiOperation({ summary: "Create a subscription plan" })
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@Roles(RoleEnum.ADMIN)
|
@Roles(RoleEnum.ADMIN)
|
||||||
createSubscription() {
|
@Post("/plan")
|
||||||
console.log(this.subscriptionService);
|
createSubscription(@Body() createDto: CreateSubscriptionPlanDto) {
|
||||||
// return this.subscriptionService.createSubscriptionsPlan();
|
return this.subscriptionService.createSubscriptionsPlan(createDto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import { SubscriptionsService } from "./providers/subscriptions.service";
|
|||||||
import { SubscriptionsPlanRepository } from "./repositories/subscriptions.repository";
|
import { SubscriptionsPlanRepository } from "./repositories/subscriptions.repository";
|
||||||
import { UserSubscriptionsRepository } from "./repositories/user-subscriptions.repository";
|
import { UserSubscriptionsRepository } from "./repositories/user-subscriptions.repository";
|
||||||
import { SubscriptionsController } from "./subscriptions.controller";
|
import { SubscriptionsController } from "./subscriptions.controller";
|
||||||
|
import { DanakServicesModule } from "../danak-services/danak-services.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([SubscriptionPlan, UserSubscription])],
|
imports: [TypeOrmModule.forFeature([SubscriptionPlan, UserSubscription]), DanakServicesModule],
|
||||||
providers: [SubscriptionsService, SubscriptionsPlanRepository, UserSubscriptionsRepository],
|
providers: [SubscriptionsService, SubscriptionsPlanRepository, UserSubscriptionsRepository],
|
||||||
controllers: [SubscriptionsController],
|
controllers: [SubscriptionsController],
|
||||||
exports: [SubscriptionsService],
|
exports: [SubscriptionsService],
|
||||||
|
|||||||
Reference in New Issue
Block a user