Skip to content

Commit

Permalink
hotfix: toReversed polyfill
Browse files Browse the repository at this point in the history
5 minutes
  • Loading branch information
c0repwn3r committed Aug 20, 2024
1 parent cfa6174 commit ed71185
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/lib/autil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function reversed<T>(i: T[]): T[] {
return i.map((e, i, a)=> a[(a.length -1) -i]);
}
9 changes: 5 additions & 4 deletions src/routes/(hq)/[id]/training/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ulid } from "ulid";
import { superValidate } from "sveltekit-superforms/server";
import { requestSchema } from "./requestSchema";
import { zod } from "sveltekit-superforms/adapters";
import { reversed } from "$lib/autil";

export const load: PageServerLoad = async ({ parent, params }) => {
let { user } = await parent();
Expand Down Expand Up @@ -38,20 +39,20 @@ export const load: PageServerLoad = async ({ parent, params }) => {
where: { facilityId: params.id },
include: { TrainingPlanRegistration: true },
}),
sessions: (await prisma.trainingSession.findMany({
sessions: reversed(await prisma.trainingSession.findMany({
where: { studentId: user.id },
include: {
plan: true,
mentor: true,
},
})).toReversed(),
mentorSessions: (await prisma.trainingSession.findMany({
})),
mentorSessions: reversed(await prisma.trainingSession.findMany({
where: { mentorId: user.id },
include: {
plan: true,
student: true,
},
})).toReversed(),
})),
requestForm: await superValidate(zod(requestSchema)),
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { can } from "$lib/perms/can";
import { TRAIN } from "$lib/perms/permissions";
import { redirect } from "sveltekit-flash-message/server";
import prisma from "$lib/prisma";
import { reversed } from "$lib/autil";

export const load: PageServerLoad = async ({ params, cookies }) => {
if (!can(TRAIN)) {
Expand All @@ -29,12 +30,12 @@ export const load: PageServerLoad = async ({ params, cookies }) => {

return {
student,
sessions: (await prisma.trainingSession.findMany({
sessions: reversed(await prisma.trainingSession.findMany({
where: { studentId: params.studentId },
include: {
plan: true,
mentor: true,
},
})).toReversed(),
})),
};
};

0 comments on commit ed71185

Please sign in to comment.