your message

This commit is contained in:
root
2026-02-06 14:53:52 +00:00
parent c809d049fe
commit 3d488f22b7
47 changed files with 3127 additions and 425 deletions

View File

@ -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);
}
}

View File

@ -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],

View File

@ -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> {