mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-01 03:25:04 +03:00
23 lines
622 B
JavaScript
23 lines
622 B
JavaScript
|
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;
|