chore: fix the purchased true for the danakservices
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import compression from "@fastify/compress";
|
||||
import { ClassSerializerInterceptor, Logger, ValidationPipe } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { NestFactory, Reflector } from "@nestjs/core";
|
||||
@@ -22,6 +23,8 @@ async function bootstrap() {
|
||||
|
||||
const app = await NestFactory.create<NestFastifyApplication>(AppModule, fastifyAdapter);
|
||||
|
||||
await app.register(compression, { encodings: ["gzip", "deflate"] });
|
||||
|
||||
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
||||
app.useGlobalInterceptors(new ResponseInterceptor(), new PaginationInterceptor(), new ClassSerializerInterceptor(app.get(Reflector)));
|
||||
app.useGlobalFilters(new HttpExceptionFilter());
|
||||
|
||||
@@ -109,21 +109,21 @@ export class CreateServiceDto {
|
||||
|
||||
@IsNotEmpty({ message: ServiceMessage.IMAGES_REQUIRED })
|
||||
@IsString({ each: true })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.IMAGES_SHOULD_BE_URL })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.IMAGES_SHOULD_BE_URL, each: true })
|
||||
@ApiProperty({ description: "The images of the service", example: ["https://example.com/image1.png", "https://example.com/image2.png"] })
|
||||
images: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: ServiceMessage.AUDIOS_REQUIRED })
|
||||
@IsString({ each: true })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.AUDIOS_SHOULD_BE_URL })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.AUDIOS_SHOULD_BE_URL, each: true })
|
||||
@ApiProperty({ description: "The audios of the service", example: ["https://example.com/audio1.mp3", "https://example.com/audio2.mp3"] })
|
||||
audios?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsNotEmpty({ message: ServiceMessage.VIDEOS_REQUIRED })
|
||||
@IsString({ each: true })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.VIDEOS_SHOULD_BE_URL })
|
||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.VIDEOS_SHOULD_BE_URL, each: true })
|
||||
@ApiProperty({ description: "The videos of the service", example: ["https://example.com/video1.mp4", "https://example.com/video2.mp4"] })
|
||||
videos?: string[];
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
|
||||
import { DataSource, FindOptionsWhere, In, IsNull, Not, QueryRunner } from "typeorm";
|
||||
import { DataSource, FindOptionsWhere, In, IsNull, LessThan, MoreThan, Not, QueryRunner } from "typeorm";
|
||||
|
||||
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||
import { CategoryMessage, CommonMessage, ServiceMessage } from "../../../common/enums/message.enum";
|
||||
@@ -718,19 +718,61 @@ export class DanakServicesService {
|
||||
/******************************************** */
|
||||
|
||||
private async checkUserPurchasedService(userId: string, serviceId: string, queryRunner?: QueryRunner) {
|
||||
const subscription = await (queryRunner ? queryRunner.manager : this.danakServicesRepository)
|
||||
.createQueryBuilder()
|
||||
.select("1")
|
||||
.from("user_subscription", "us")
|
||||
.innerJoin("subscription_plan", "sp", "us.planId = sp.id")
|
||||
.where("us.userId = :userId", { userId })
|
||||
.andWhere("sp.serviceId = :serviceId", { serviceId })
|
||||
.andWhere(`(us.status = '${SubscriptionStatus.ACTIVE}')`)
|
||||
.andWhere("us.endDate > NOW()")
|
||||
.andWhere("us.startDate < NOW()")
|
||||
.limit(1)
|
||||
.getRawOne();
|
||||
// const subscription = await (queryRunner ? queryRunner.manager : this.danakServicesRepository)
|
||||
// .createQueryBuilder()
|
||||
// .select("1")
|
||||
// .from("user_subscription", "us")
|
||||
// .innerJoin("subscription_plan", "sp", "us.planId = sp.id")
|
||||
// .where("us.userId = :userId", { userId })
|
||||
// .andWhere("sp.serviceId = :serviceId", { serviceId })
|
||||
// .andWhere(`(us.status = '${SubscriptionStatus.ACTIVE}')`)
|
||||
// .andWhere("us.endDate > NOW()")
|
||||
// .andWhere("us.startDate < NOW()")
|
||||
// .limit(1)
|
||||
// .getRawOne();
|
||||
|
||||
return !!subscription;
|
||||
if (!queryRunner) {
|
||||
const subscription = await this.danakServicesRepository.findOne({
|
||||
where: {
|
||||
id: serviceId,
|
||||
subscriptionPlans: {
|
||||
userSubscriptions: {
|
||||
user: { id: userId },
|
||||
status: SubscriptionStatus.ACTIVE,
|
||||
endDate: MoreThan(new Date()),
|
||||
startDate: LessThan(new Date()),
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: {
|
||||
subscriptionPlans: {
|
||||
userSubscriptions: {
|
||||
user: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return !!subscription;
|
||||
} else {
|
||||
const subscription = await queryRunner.manager.findOne(this.danakServicesRepository.target, {
|
||||
where: {
|
||||
id: serviceId,
|
||||
subscriptionPlans: {
|
||||
userSubscriptions: {
|
||||
user: { id: userId },
|
||||
status: SubscriptionStatus.ACTIVE,
|
||||
endDate: MoreThan(new Date()),
|
||||
startDate: LessThan(new Date()),
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: {
|
||||
subscriptionPlans: {
|
||||
userSubscriptions: { user: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return !!subscription;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user