Some changes in structure + add album

This commit is contained in:
Damien Broqua 2022-02-15 11:03:20 +01:00
parent 3ebdc9c06a
commit f08e70eb7c
36 changed files with 883 additions and 165 deletions

85
src/middleware/Albums.js Normal file
View file

@ -0,0 +1,85 @@
import moment from "moment";
import Pages from "./Pages";
import { getAlbumDetails } from "../helpers";
import AlbumsModel from "../models/albums";
/**
* Classe permettant la gestion des albums d'un utilisateur
*/
class Albums extends Pages {
async getFormAddOne() {
const data = await getAlbumDetails(this.req.params.discogsId);
const {
id, // Integer
year, // - Integer
uri, // String
artists, // - Array<Object>
artists_sort, // String
labels, // - Array<Object>
series, // Array
companies, // - Array<Object>
formats, // - Array<Object>
title, // - String
country, // - String
released, // - Date
notes, // - String
identifiers, // - Array<Object>
videos, // - Array<Object>
genres, // - Array<String>
styles, // - Array<String>
tracklist, // - Array<Object>
extraartists, // - Array<Object>
images, // - Array<Object
thumb, // - String
} = data;
this.pageContent.page.values = "test";
this.setPageContent("values", {
id,
year,
uri,
artists,
artists_sort,
labels,
series,
companies,
formats,
title,
country,
released,
notes,
identifiers,
videos,
genres,
styles,
tracklist,
extraartists,
images,
thumb,
});
return true;
}
static async postAddOne(req) {
const { body, user } = req;
const data = {
...body,
discogsId: body.id,
User: user._id,
};
data.released = moment(data.released.replace("-00", "-01"));
delete data.id;
const album = new AlbumsModel(data);
return album.save();
}
}
export default Albums;

View file

@ -34,6 +34,10 @@ class Pages {
}
}
setPageContent(field, value) {
this.pageContent.page[field] = value;
}
/**
* Rendu de la page
* @return {Object}
@ -46,7 +50,7 @@ class Pages {
this.pageContent.params = this.req.params;
this.pageContent.user = this.user;
this.pageContent.config = config;
this.pageContent.getBaseUrl = getBaseUrl();
this.pageContent.getBaseUrl = getBaseUrl(this.req);
if (this.req.session.flash && this.req.session.flash.error) {
// eslint-disable-next-line prefer-destructuring