feat: clone course (#582)
* feat: clone course work * feat: clone and delete a course * feat: clone and delete a course * feat: clean up * feat: attending to reviews * feat: attended to revies
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { Hono } from 'hono';
|
||||
import { ZCourseClone, TCourseClone } from '$src/types/course';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { cloneCourse } from '$src/services/course/clone';
|
||||
import { authMiddleware } from '$src/middlewares/auth';
|
||||
import type { CloneCourseResponse, CloneCourseErrorResponse } from '$src/types/database';
|
||||
import type { User } from '@supabase/supabase-js';
|
||||
|
||||
type Variables = {
|
||||
user: User;
|
||||
};
|
||||
|
||||
export const cloneRouter = new Hono<{ Variables: Variables }>().post(
|
||||
'/',
|
||||
authMiddleware,
|
||||
zValidator('json', ZCourseClone),
|
||||
async (c) => {
|
||||
try {
|
||||
const validatedData = (c.req.valid as (key: 'json') => TCourseClone)('json');
|
||||
const { id, title, description, slug, organizationId } = validatedData;
|
||||
|
||||
// Get user from context (set by authMiddleware)
|
||||
const user = c.get('user');
|
||||
|
||||
// Clone the course
|
||||
const newCourse = await cloneCourse(id, title, user.id, description, slug, organizationId);
|
||||
|
||||
const successResponse: CloneCourseResponse = {
|
||||
success: true,
|
||||
course: newCourse
|
||||
};
|
||||
return c.json(successResponse, 200);
|
||||
} catch (error) {
|
||||
console.error('Error cloning course:', error);
|
||||
const errorResponse: CloneCourseErrorResponse = {
|
||||
error: 'Failed to clone course',
|
||||
details: error instanceof Error ? error.message : 'Unknown error'
|
||||
};
|
||||
return c.json(errorResponse, 500);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ZCertificateDownload, ZCourseDownloadContent } from '$src/types/course';
|
||||
import { TCourseClone,TCourseDownloadContent, TCertificateDownload, ZCertificateDownload, ZCourseDownloadContent } from '$src/types/course';
|
||||
|
||||
import { Hono } from 'hono';
|
||||
import { generateCertificate } from '$src/utils/certificate';
|
||||
@@ -6,11 +6,12 @@ import { generateCoursePdf } from '$src/utils/course';
|
||||
import { katexRouter } from '$src/routes/course/katex';
|
||||
import { lessonRouter } from '$src/routes/course/lesson';
|
||||
import { presignRouter } from '$src/routes/course/presign';
|
||||
import { cloneRouter } from '$src/routes/course/clone';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
|
||||
export const courseRouter = new Hono()
|
||||
.post('/download/certificate', zValidator('json', ZCertificateDownload), async (c) => {
|
||||
const validatedData = c.req.valid('json');
|
||||
const validatedData = (c.req.valid as (key: 'json') => TCertificateDownload)('json');
|
||||
|
||||
const result = await generateCertificate(validatedData);
|
||||
|
||||
@@ -30,7 +31,7 @@ export const courseRouter = new Hono()
|
||||
);
|
||||
})
|
||||
.post('/download/content', zValidator('json', ZCourseDownloadContent), async (c) => {
|
||||
const validatedData = c.req.valid('json');
|
||||
const validatedData = (c.req.valid as (key: 'json') => TCourseDownloadContent)('json');
|
||||
|
||||
const pdfBuffer = await generateCoursePdf(validatedData);
|
||||
|
||||
@@ -47,4 +48,5 @@ export const courseRouter = new Hono()
|
||||
})
|
||||
.route('/katex', katexRouter)
|
||||
.route('/lesson', lessonRouter)
|
||||
.route('/presign', presignRouter);
|
||||
.route('/presign', presignRouter)
|
||||
.route('/clone', cloneRouter);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Hono } from 'hono';
|
||||
import { ZLessonDownloadContent } from '$src/types/course/lesson';
|
||||
import { TLessonDownloadContent, ZLessonDownloadContent } from '$src/types/course/lesson';
|
||||
import { generateLessonPdf } from '$src/utils/lesson';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
|
||||
@@ -7,7 +7,7 @@ export const lessonRouter = new Hono().post(
|
||||
'/download/pdf',
|
||||
zValidator('json', ZLessonDownloadContent),
|
||||
async (c) => {
|
||||
const validatedData = c.req.valid('json');
|
||||
const validatedData = (c.req.valid as (key: 'json') => TLessonDownloadContent)('json');
|
||||
|
||||
const pdfBuffer = await generateLessonPdf(validatedData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user