akf-forum/routes/api/routes/threads.js

23 lines
622 B
JavaScript
Raw Normal View History

2022-04-03 22:03:47 +03:00
const { Thread } = require("../../../classes");
const ApiResponse = require("../ApiResponse");
const { Router } = require("express")
const app = Router();
app.get("/:id", (req, res) => {
const error = (status, error) =>
res.status(status).json(new ApiResponse(status, { error }))
const { id = null } = req.params;
if (!id) return error(400, "Missing id in query")
const thread = new Thread().getId(id);
if (!thread || thread.deleted) return error(404, "We have not got any thread declared as this id.");
res.status(200).json(new ApiResponse(200, thread));
});
module.exports = app;