fix: api alias path
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { ZCourseClone, TCourseClone } from '$src/types/course';
|
import { ZCourseClone, TCourseClone } from '@api/types/course';
|
||||||
import { zValidator } from '@hono/zod-validator';
|
import { zValidator } from '@hono/zod-validator';
|
||||||
import { cloneCourse } from '$src/services/course/clone';
|
import { cloneCourse } from '@api/services/course/clone';
|
||||||
import { authMiddleware } from '$src/middlewares/auth';
|
import { authMiddleware } from '@api/middlewares/auth';
|
||||||
import type { CloneCourseResponse, CloneCourseErrorResponse } from '$src/types/database';
|
import type { CloneCourseResponse, CloneCourseErrorResponse } from '@api/types/database';
|
||||||
import type { User } from '@supabase/supabase-js';
|
import type { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
type Variables = {
|
type Variables = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { getSupabase } from '$src/utils/supabase';
|
import { getSupabase } from '@api/utils/supabase';
|
||||||
import type { Course, Lesson, LessonSection, GroupMember } from '$src/types/database';
|
import type { Course, Lesson, LessonSection, GroupMember } from '@api/types/database';
|
||||||
import type { PostgrestError } from '@supabase/supabase-js';
|
import type { PostgrestError } from '@supabase/supabase-js';
|
||||||
|
|
||||||
const supabase = getSupabase();
|
const supabase = getSupabase();
|
||||||
@@ -145,10 +145,7 @@ async function cloneGroupAndBasicCourse(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cloneLessonSections(
|
async function cloneLessonSections(sections: LessonSection[], courseId: string): Promise<CloneSectionsResponse> {
|
||||||
sections: LessonSection[],
|
|
||||||
courseId: string
|
|
||||||
): Promise<CloneSectionsResponse> {
|
|
||||||
if (!sections || sections.length === 0) {
|
if (!sections || sections.length === 0) {
|
||||||
return { newSections: [], sectionIdMap: undefined };
|
return { newSections: [], sectionIdMap: undefined };
|
||||||
}
|
}
|
||||||
@@ -161,10 +158,7 @@ async function cloneLessonSections(
|
|||||||
course_id: courseId
|
course_id: courseId
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { data: newSections } = await supabase
|
const { data: newSections } = await supabase.from('lesson_section').insert(clonedSections).select();
|
||||||
.from('lesson_section')
|
|
||||||
.insert(clonedSections)
|
|
||||||
.select();
|
|
||||||
|
|
||||||
// Map old section IDs to new section IDs
|
// Map old section IDs to new section IDs
|
||||||
const sectionIdMap = new Map<string, string>();
|
const sectionIdMap = new Map<string, string>();
|
||||||
@@ -350,9 +344,7 @@ export async function cloneCourse(
|
|||||||
// @ts-ignore - lessons comes from the query
|
// @ts-ignore - lessons comes from the query
|
||||||
if (course.lessons && course.lessons.length > 0) {
|
if (course.lessons && course.lessons.length > 0) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const orphanedLessons = course.lessons.filter(
|
const orphanedLessons = course.lessons.filter((lesson: Lesson) => !lesson.section_id || !sectionIdMap);
|
||||||
(lesson: Lesson) => !lesson.section_id || !sectionIdMap
|
|
||||||
);
|
|
||||||
allLessons = [...allLessons, ...orphanedLessons];
|
allLessons = [...allLessons, ...orphanedLessons];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user