{"size": 766, "ext": "js", "max_stars_repo_path": "Programan/routes/api/albums.js", "max_stars_repo_name": "AcamicaDWFS-ONLINE-67/Clase_48_Base_datos_relacionales_II", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Programan/routes/api/albums.js", "max_issues_repo_name": "AcamicaDWFS-ONLINE-67/Clase_48_Base_datos_relacionales_II", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Programan/routes/api/albums.js", "max_forks_repo_name": "AcamicaDWFS-ONLINE-67/Clase_48_Base_datos_relacionales_II", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.3571428571, "max_line_length": 57, "alphanum_fraction": 0.6201044386}
const router = require("express").Router();
const { Album } = require("../../conexion");

router.get("/", async (request, response) => {
    const albums = await Album.findAll();
    response.send(albums);
});

router.post("/", async (request, response) => {
    const albums = await Album.create(request.body);
    response.json(albums);
});

router.put("/:albumId", async (request, response) => {
    await Album.update(request.body, {
        where: { id: request.params.albumId }
    });
    response.json({ success: "Album actualizado" });
});

router.delete("/:albumId", async (request, response) => {
    await Album.destroy({
        where: { id: request.params.albumId }
    });
    response.json({ success: "Album borrado" });
});

module.exports = router;