forked from dbroqua/MusicTopus
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import express from "express";
|
|
import { ensureLoggedIn } from "connect-ensure-login";
|
|
|
|
import { sendResponse } from "../../../libs/format";
|
|
import Albums from "../../../middleware/Albums";
|
|
|
|
// eslint-disable-next-line new-cap
|
|
const router = express.Router();
|
|
|
|
router
|
|
.route("/")
|
|
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
|
try {
|
|
const albums = new Albums(req);
|
|
const data = await albums.getAll();
|
|
|
|
sendResponse(req, res, data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
})
|
|
.post(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
|
try {
|
|
const data = await Albums.postAddOne(req);
|
|
|
|
sendResponse(req, res, data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
});
|
|
|
|
router
|
|
.route("/:itemId")
|
|
.delete(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
|
try {
|
|
const albums = new Albums(req);
|
|
const data = await albums.deleteOne();
|
|
|
|
sendResponse(req, res, data);
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
});
|
|
|
|
export default router;
|