Skip to content

Commit 8c75fa2

Browse files
committed
feat(assistant): add option to feature assistants for admins
1 parent 1fada1e commit 8c75fa2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,29 @@ export const actions: Actions = {
197197

198198
return { from: "unfeature", ok: true, message: "Assistant unfeatured" };
199199
},
200+
201+
feature: async ({ params, locals }) => {
202+
if (!locals.user?.isAdmin) {
203+
return fail(403, { error: true, message: "Permission denied" });
204+
}
205+
206+
const assistant = await collections.assistants.findOne({
207+
_id: new ObjectId(params.assistantId),
208+
});
209+
210+
if (!assistant) {
211+
return fail(404, { error: true, message: "Assistant not found" });
212+
}
213+
214+
const result = await collections.assistants.updateOne(
215+
{ _id: assistant._id },
216+
{ $set: { featured: true } }
217+
);
218+
219+
if (result.modifiedCount === 0) {
220+
return fail(500, { error: true, message: "Failed to feature assistant" });
221+
}
222+
223+
return { from: "feature", ok: true, message: "Assistant featured" };
224+
},
200225
};

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import CarbonCopy from "~icons/carbon/copy-file";
1212
import CarbonFlag from "~icons/carbon/flag";
1313
import CarbonLink from "~icons/carbon/link";
14+
import CarbonStar from "~icons/carbon/star";
1415
import CopyToClipBoardBtn from "$lib/components/CopyToClipBoardBtn.svelte";
1516
import ReportModal from "./ReportModal.svelte";
1617
import IconInternet from "$lib/components/icons/IconInternet.svelte";
@@ -154,6 +155,12 @@
154155
<CarbonTrash class="mr-1.5 inline text-xs" />Un-feature</button
155156
>
156157
</form>
158+
{:else}
159+
<form method="POST" action="?/feature" use:enhance>
160+
<button type="submit" class="flex items-center text-green-600 underline">
161+
<CarbonStar class="mr-1.5 inline text-xs" />Feature</button
162+
>
163+
</form>
157164
{/if}
158165
{/if}
159166
</div>

0 commit comments

Comments
 (0)