Skip to content

Commit

Permalink
[Assistants settings] Update data backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mishig25 committed Feb 23, 2024
1 parent 105d8aa commit 7bd937b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 38 deletions.
23 changes: 0 additions & 23 deletions src/routes/settings/+layout.server.ts

This file was deleted.

25 changes: 25 additions & 0 deletions src/routes/settings/assistants/[assistantId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PUBLIC_ORIGIN, PUBLIC_SHARE_PREFIX } from "$env/static/public";
import { WEBHOOK_URL_REPORT_ASSISTANT } from "$env/static/private";
import { z } from "zod";
import type { Assistant } from "$lib/types/Assistant";

async function assistantOnlyIfAuthor(locals: App.Locals, assistantId?: string) {
const assistant = await collections.assistants.findOne({ _id: new ObjectId(assistantId) });

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

export async function load({ parent, params, locals }) {
const data = await parent();

const assistantId = params.assistantId;

const assistant = data.settings.assistants.find((id) => id === assistantId);
if (!assistant) {
throw redirect(302, `${base}/assistant/${params.assistantId}`);
}

let isReported = false;

const createdBy = locals.user?._id ?? locals.sessionId;
if (createdBy) {
const report = await collections.reports.findOne({
createdBy,
assistantId: new ObjectId(assistantId),
});
isReported = !!report;
}

return { isReported };
}

export const actions: Actions = {
delete: async ({ params, locals }) => {
let assistant;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/assistants/[assistantId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<CarbonCopy class="mr-1.5 inline text-xs" />Duplicate</button
>
</form>
{#if !assistant?.reported}
{#if !data.isReported}
<button
type="button"
on:click={() => {
Expand Down
14 changes: 0 additions & 14 deletions src/routes/settings/assistants/[assistantId]/+page.ts

This file was deleted.

0 comments on commit 7bd937b

Please sign in to comment.