your message
This commit is contained in:
@ -32,9 +32,9 @@ export class CatalogController {
|
||||
@Post(':id/submit')
|
||||
@ApiBearerAuth()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Submit course for review / publish' })
|
||||
@ApiOperation({ summary: 'Submit course for moderation review' })
|
||||
async submitForReview(@Param('id') id: string, @CurrentUser() user: User): Promise<any> {
|
||||
return this.catalogService.publishCourse(id, user.id);
|
||||
return this.catalogService.submitForReview(id, user.id);
|
||||
}
|
||||
|
||||
@Patch(':id/verify')
|
||||
@ -43,4 +43,12 @@ export class CatalogController {
|
||||
async toggleVerify(@Param('id') id: string, @CurrentUser() user: User): Promise<any> {
|
||||
return this.catalogService.toggleVerification(id, user.id);
|
||||
}
|
||||
|
||||
@Post(':id/checkout')
|
||||
@ApiBearerAuth()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'Create one-time checkout session for paid course' })
|
||||
async checkoutCourse(@Param('id') id: string, @CurrentUser() user: User): Promise<any> {
|
||||
return this.catalogService.createCourseCheckout(id, user.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CatalogController } from './catalog.controller';
|
||||
import { CatalogService } from './catalog.service';
|
||||
import { PaymentsModule } from '../payments/payments.module';
|
||||
|
||||
@Module({
|
||||
imports: [PaymentsModule],
|
||||
controllers: [CatalogController],
|
||||
providers: [CatalogService],
|
||||
exports: [CatalogService],
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, ForbiddenException, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../common/prisma/prisma.service';
|
||||
import { CourseStatus } from '@coursecraft/database';
|
||||
import { PaymentsService } from '../payments/payments.service';
|
||||
|
||||
@Injectable()
|
||||
export class CatalogService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private paymentsService: PaymentsService
|
||||
) {}
|
||||
|
||||
async getPublishedCourses(options?: {
|
||||
page?: number;
|
||||
@ -92,21 +96,25 @@ export class CatalogService {
|
||||
}
|
||||
|
||||
async submitForReview(courseId: string, userId: string): Promise<any> {
|
||||
const course = await this.prisma.course.findUnique({ where: { id: courseId } });
|
||||
if (!course) {
|
||||
throw new NotFoundException('Course not found');
|
||||
}
|
||||
if (course.authorId !== userId) {
|
||||
throw new ForbiddenException('Only course author can submit for moderation');
|
||||
}
|
||||
|
||||
return this.prisma.course.update({
|
||||
where: { id: courseId, authorId: userId },
|
||||
data: { status: CourseStatus.PENDING_REVIEW },
|
||||
where: { id: courseId },
|
||||
data: {
|
||||
status: CourseStatus.PENDING_REVIEW,
|
||||
isPublished: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async publishCourse(courseId: string, userId: string): Promise<any> {
|
||||
return this.prisma.course.update({
|
||||
where: { id: courseId, authorId: userId },
|
||||
data: {
|
||||
status: CourseStatus.PUBLISHED,
|
||||
isPublished: true,
|
||||
publishedAt: new Date(),
|
||||
},
|
||||
});
|
||||
async createCourseCheckout(courseId: string, userId: string): Promise<any> {
|
||||
return this.paymentsService.createCourseCheckoutSession(userId, courseId);
|
||||
}
|
||||
|
||||
async toggleVerification(courseId: string, userId: string): Promise<any> {
|
||||
|
||||
Reference in New Issue
Block a user