Compare commits

..

3 commits

Author SHA1 Message Date
hippoz
3bc166bfb0
add route to get all channels 2022-04-07 13:35:36 +03:00
hippoz
2956bf10fc
move json middleware use call into server object 2022-04-06 21:27:52 +03:00
hippoz
144a46fa3c
remove unused variable 2022-04-06 21:22:55 +03:00
4 changed files with 18 additions and 7 deletions

View file

@ -6,8 +6,6 @@ import { errors } from "../../../errors";
const router = express.Router();
router.use(express.json());
router.post(
"/",
authenticateRoute(),
@ -81,7 +79,6 @@ router.delete(
return res.status(400).json({ ...errors.INVALID_DATA, errors: validationErrors.array() });
}
const { name } = req.body;
const { id } = req.params;
const permissionCheckResult = await query("SELECT owner_id FROM channels WHERE id = $1", [id]);
@ -125,4 +122,14 @@ router.get(
}
);
router.get(
"/",
authenticateRoute(),
async (req, res) => {
const result = await query("SELECT id, name, owner_id FROM channels");
return res.status(200).send(result.rows);
}
);
export default router;

View file

@ -7,8 +7,6 @@ import { authenticateRoute, signToken } from "../../../auth";
const router = express.Router();
router.use(express.json());
router.post(
"/register",
body("username").isLength({ min: 3, max: 32 }).isAlphanumeric("en-US", { ignore: " _-" }),

View file

@ -1,8 +1,9 @@
import { Application } from "express";
import { Application, json } from "express";
import usersRouter from "./routes/api/v1/users";
import channelsRouter from "./routes/api/v1/channels";
export default function(app: Application) {
app.use(json());
app.use("/api/v1/users", usersRouter);
app.use("/api/v1/channels", channelsRouter);
};

View file

@ -28,7 +28,7 @@ content-type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU
{
"name": "my channel"
"name": "another channel"
}
###
@ -52,3 +52,8 @@ Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6M
GET http://localhost:3000/api/v1/channels/1 HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU
###
GET http://localhost:3000/api/v1/channels HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidHlwZSI6MSwiaWF0IjoxNjQ5MTg3MDc5LCJleHAiOjE2NDkzNTk4Nzl9.tVzJWnBP7IFhA88XRwByKGXQ4cihWdJSoxUkrWHkIVU