File size: 759 Bytes
df3243b
 
df4a841
df3243b
 
0d4cc32
df3243b
df4a841
 
 
 
a1a6daf
 
 
df4a841
0c3e3b2
df4a841
 
df3243b
9d36148
df4a841
0d4cc32
df4a841
df3243b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { collections } from "$lib/server/database";
import type { LayoutServerLoad } from "./$types";
import type { Report } from "$lib/types/Report";

export const load = (async ({ locals, parent }) => {
	const { assistants } = await parent();

	let reportsByUser: string[] = [];
	const createdBy = locals.user?._id ?? locals.sessionId;
	if (createdBy) {
		const reports = await collections.reports
			.find<
				Pick<Report, "contentId">
			>({ createdBy, object: "assistant" }, { projection: { _id: 0, contentId: 1 } })
			.toArray();
		reportsByUser = reports.map((r) => r.contentId.toString());
	}

	return {
		assistants: (await assistants).map((el) => ({
			...el,
			reported: reportsByUser.includes(el._id),
		})),
	};
}) satisfies LayoutServerLoad;