Skip to content

Commit 7bd937b

Browse files
committed
[Assistants settings] Update data backend
1 parent 105d8aa commit 7bd937b

File tree

4 files changed

+26
-38
lines changed

4 files changed

+26
-38
lines changed

src/routes/settings/+layout.server.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/routes/settings/assistants/[assistantId]/+page.server.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public";
77
import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private";
88
import { z } from "zod";
99
import type { Assistant } from "$lib/types/Assistant";
10+
1011
async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
1112
const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) });
1213

@@ -21,6 +22,30 @@ async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
2122
return assistant;
2223
}
2324

25+
export async function load({ parent, params, locals }) {
26+
const data = await parent();
27+
28+
const assistantId = params.assistantId;
29+
30+
const assistant = data.settings.assistants.find((id) => id === assistantId);
31+
if (!assistant) {
32+
throw redirect(302, `${base}/assistant/${params.assistantId}`);
33+
}
34+
35+
let isReported = false;
36+
37+
const createdBy = locals.user?._id ?? locals.sessionId;
38+
if (createdBy) {
39+
const report = await collections.reports.findOne({
40+
createdBy,
41+
assistantId: new ObjectId(assistantId),
42+
});
43+
isReported = !!report;
44+
}
45+
46+
return { isReported };
47+
}
48+
2449
export const actions: Actions = {
2550
delete: async ({ params, locals }) => {
2651
let assistant;

src/routes/settings/assistants/[assistantId]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<CarbonCopy class="mr-1.5 inline text-xs" />Duplicate</button
108108
>
109109
</form>
110-
{#if !assistant?.reported}
110+
{#if !data.isReported}
111111
<button
112112
type="button"
113113
on:click={() => {

src/routes/settings/assistants/[assistantId]/+page.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)