Skip to content

Commit

Permalink
feat(assistant): add option to feature assistants for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Aug 15, 2024
1 parent 1fada1e commit 8c75fa2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/routes/settings/(nav)/assistants/[assistantId]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,29 @@ export const actions: Actions = {

return { from: "unfeature", ok: true, message: "Assistant unfeatured" };
},

feature: async ({ params, locals }) => {
if (!locals.user?.isAdmin) {
return fail(403, { error: true, message: "Permission denied" });
}

const assistant = await collections.assistants.findOne({
_id: new ObjectId(params.assistantId),
});

if (!assistant) {
return fail(404, { error: true, message: "Assistant not found" });
}

const result = await collections.assistants.updateOne(
{ _id: assistant._id },
{ $set: { featured: true } }
);

if (result.modifiedCount === 0) {
return fail(500, { error: true, message: "Failed to feature assistant" });
}

return { from: "feature", ok: true, message: "Assistant featured" };
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import CarbonCopy from "~icons/carbon/copy-file";
import CarbonFlag from "~icons/carbon/flag";
import CarbonLink from "~icons/carbon/link";
import CarbonStar from "~icons/carbon/star";
import CopyToClipBoardBtn from "$lib/components/CopyToClipBoardBtn.svelte";
import ReportModal from "./ReportModal.svelte";
import IconInternet from "$lib/components/icons/IconInternet.svelte";
Expand Down Expand Up @@ -154,6 +155,12 @@
<CarbonTrash class="mr-1.5 inline text-xs" />Un-feature</button
>
</form>
{:else}
<form method="POST" action="?/feature" use:enhance>
<button type="submit" class="flex items-center text-green-600 underline">
<CarbonStar class="mr-1.5 inline text-xs" />Feature</button
>
</form>
{/if}
{/if}
</div>
Expand Down

0 comments on commit 8c75fa2

Please sign in to comment.