Spaces:
Running
Running
Kevin CATHALY
commited on
add an endpoint to api to get an assistant by id (#1020)
Browse files
src/routes/api/assistant/[id]/+server.ts
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { collections } from "$lib/server/database";
|
2 |
+
import { ObjectId } from "mongodb";
|
3 |
+
|
4 |
+
export async function GET({ params }) {
|
5 |
+
const id = params.id;
|
6 |
+
const assistantId = new ObjectId(id);
|
7 |
+
|
8 |
+
const assistant = await collections.assistants.findOne({
|
9 |
+
_id: assistantId,
|
10 |
+
});
|
11 |
+
|
12 |
+
if (assistant) {
|
13 |
+
return Response.json(assistant);
|
14 |
+
} else {
|
15 |
+
return Response.json({ message: "Assistant not found" }, { status: 404 });
|
16 |
+
}
|
17 |
+
}
|