Skip to content

Commit

Permalink
Add authenticator and index route to swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroavpereira committed Aug 29, 2024
1 parent fda3961 commit 1c8c406
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 13 additions & 1 deletion controllers/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ const Collection = require("../models/Collection");
const Room = require("../models/Room");
const Swap = require("../models/Swap");

const showMine = async (req, res) => {
try {
const user_id = req.user_id;

const swaps = await Swap.findByUserId(user_id);

res.status(200).json(swaps);
} catch (err) {
res.status(500).json({ error: err.message });
}
};

const create = async (req, res) => {
try {
const { collection_id } = req.body;
Expand Down Expand Up @@ -88,4 +100,4 @@ const destroy = async (req, res) => {
}
};

module.exports = { create, accept, reject, complete, destroy };
module.exports = { create, accept, reject, complete, destroy, showMine };
5 changes: 5 additions & 0 deletions routes/swaps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const { Router } = require("express");

const { authenticator } = require("../middleware/authenticator");

const swapsController = require("../controllers/swaps");

const swapsRouter = Router();

swapsRouter.use(authenticator);

swapsRouter.get("/".swapsController.showMine);
swapsRouter.post("/", swapsController.create);
swapsRouter.patch("/accept/:swap_id", swapsController.accept);
swapsRouter.patch("/reject/:swap_id", swapsController.reject);
Expand Down

0 comments on commit 1c8c406

Please sign in to comment.