From 5ab3cbaa54642ada07085d1e0aa2e984dec1849a Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 29 May 2025 06:17:12 +0200 Subject: Allow unfree in nix flake, add mongodb-compass to devShell closure, basic mongo attempt, add test register route --- src/api/routes/auth/index.js | 1 + src/api/routes/auth/registerRoute.js | 14 ++++++++++++++ src/api/routes/index.js | 2 ++ src/api/routes/statusRoute.js | 5 ++++- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/api/routes/auth/index.js create mode 100644 src/api/routes/auth/registerRoute.js (limited to 'src/api/routes') diff --git a/src/api/routes/auth/index.js b/src/api/routes/auth/index.js new file mode 100644 index 0000000..8306697 --- /dev/null +++ b/src/api/routes/auth/index.js @@ -0,0 +1 @@ +export * from "./registerRoute.js"; diff --git a/src/api/routes/auth/registerRoute.js b/src/api/routes/auth/registerRoute.js new file mode 100644 index 0000000..b71c466 --- /dev/null +++ b/src/api/routes/auth/registerRoute.js @@ -0,0 +1,14 @@ +import { User } from "#db/schemas/userSchema.js"; + +export const registerRoute = { + route: "/auth/register", + async onGet(req, res) { + const result = await User.create({ + username: req.query.username, + password: req.query.password, + email: req.query.email, + }); + + res.send(result); + }, +}; diff --git a/src/api/routes/index.js b/src/api/routes/index.js index c35303f..147246e 100644 --- a/src/api/routes/index.js +++ b/src/api/routes/index.js @@ -1,2 +1,4 @@ export * from "./statusRoute.js"; export * from "./indexRoute.js"; + +export * from "./auth/index.js"; diff --git a/src/api/routes/statusRoute.js b/src/api/routes/statusRoute.js index a829f19..f1cdb99 100644 --- a/src/api/routes/statusRoute.js +++ b/src/api/routes/statusRoute.js @@ -1,9 +1,12 @@ +import { User } from "#db/schemas/userSchema.js"; + export const statusRoute = { route: "/status", - onGet(req, res) { + async onGet(req, res) { const status = { status: "ok", timestamp: new Date().toISOString(), + users: await User.countDocuments(), }; res.status(200).json(status); -- cgit 1.5.1