MusicTopus/src/routes/api/v1/search.js

33 lines
822 B
JavaScript

import express from "express";
import { ensureLoggedIn } from "connect-ensure-login";
import { sendResponse } from "../../../libs/format";
import { searchSong, getAlbumDetails } from "../../../helpers";
// eslint-disable-next-line new-cap
const router = express.Router();
router.route("/").get(ensureLoggedIn("/connexion"), async (req, res, next) => {
try {
const data = await searchSong(req.query.q);
sendResponse(req, res, data);
} catch (err) {
next(err);
}
});
router
.route("/:discogsId")
.get(ensureLoggedIn("/connexion"), async (req, res, next) => {
try {
const data = await getAlbumDetails(req.params.discogsId);
sendResponse(req, res, data);
} catch (err) {
next(err);
}
});
export default router;