Skip to content

Commit

Permalink
Removed groupRank (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaviRajput10 committed May 20, 2024
1 parent ca61e67 commit 9de0d56
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions apps/web/graphql/lessons/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function validateMediaContent(lessonData: LessonValidatorProps) {
}
}

type GroupLessonItem = Pick<Lesson, "lessonId" | "groupId" | "groupRank">;
type GroupLessonItem = Pick<Lesson, "lessonId" | "groupId">;
export const getGroupedLessons = async (
courseId: string,
domainId: mongoose.Types.ObjectId,
Expand All @@ -89,7 +89,6 @@ export const getGroupedLessons = async (
},
{
lessonId: 1,
groupRank: 1,
groupId: 1,
},
);
Expand All @@ -104,7 +103,8 @@ export const getGroupedLessons = async (
)
.sort(
(a: GroupLessonItem, b: GroupLessonItem) =>
a.groupRank - b.groupRank,
group.lessonsOrder.indexOf(a.lessonId) -
group.lessonsOrder.indexOf(b.lessonId),
),
);
}
Expand Down
2 changes: 0 additions & 2 deletions apps/web/graphql/lessons/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export const createLesson = async (
creatorId: ctx.user._id, // TODO: refactor this
courseId: course.courseId,
groupId: lessonData.groupId,
groupRank: -1,
requiresEnrollment: lessonData.requiresEnrollment,
});

Expand Down Expand Up @@ -235,7 +234,6 @@ export const getAllLessons = async (course: Course, ctx: GQLContext) => {
requiresEnrollment: 1,
courseId: 1,
groupId: 1,
groupRank: 1,
},
);

Expand Down
1 change: 0 additions & 1 deletion apps/web/graphql/lessons/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const lessonMetaType = new GraphQLObjectType({
},
courseId: { type: new GraphQLNonNull(GraphQLID) },
groupId: { type: new GraphQLNonNull(GraphQLID) },
groupRank: { type: new GraphQLNonNull(GraphQLID) },
},
});

Expand Down
2 changes: 0 additions & 2 deletions apps/web/models/Lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface Lesson {
requiresEnrollment: boolean;
published: boolean;
groupId: string;
groupRank: number;
}

const LessonSchema = new mongoose.Schema<Lesson>({
Expand All @@ -46,7 +45,6 @@ const LessonSchema = new mongoose.Schema<Lesson>({
requiresEnrollment: { type: Boolean, default: true },
published: { type: Boolean, required: true, default: false },
groupId: { type: String, required: true },
groupRank: { type: Number, required: true },
});

export default mongoose.models.Lesson || mongoose.model("Lesson", LessonSchema);
1 change: 0 additions & 1 deletion apps/web/pages/course/[slug]/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export async function getServerSideProps({ query, req }: any) {
requiresEnrollment,
courseId,
groupId,
groupRank
},
tags,
firstLesson
Expand Down
7 changes: 5 additions & 2 deletions packages/common-widgets/src/content/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export default function Widget({
groupId,
lessonId,
type,
groupRank,
requiresEnrollment
},
groups {
Expand Down Expand Up @@ -126,7 +125,11 @@ export default function Widget({
course.groups.map((group) => {
formattedCourse[group.name] = course.lessons
.filter((lesson: Lesson) => lesson.groupId === group.id)
.sort((a: any, b: any) => a.groupRank - b.groupRank);
.sort(
(a: any, b: any) =>
group.lessonsOrder.indexOf(a.lessonId) -
group.lessonsOrder.indexOf(b.lessonId),
);
});
setFormattedCourse(formattedCourse);
}
Expand Down

0 comments on commit 9de0d56

Please sign in to comment.