#2 {musictopus}

This commit is contained in:
Damien Broqua 2022-03-04 14:36:31 +01:00
parent 1f63c74ac3
commit e7858c9870
2 changed files with 25 additions and 4 deletions

View file

@ -18,9 +18,7 @@ class Albums extends Pages {
* @return {string}
*/
static async convertToCsv(rows) {
let data = "";
data +=
let data =
"Artiste;Titre;Genre;Styles;Pays;Année;Date de sortie;Format\n\r";
for (let i = 0; i < rows.length; i += 1) {
@ -50,7 +48,7 @@ class Albums extends Pages {
* Méthode permettant de convertir les rows en fichier xls
* @param {Array} rows
*
* @return {string}
* @return {Object}
*/
static async convertToXls(rows) {
const wb = new xl.Workbook();
@ -131,6 +129,26 @@ class Albums extends Pages {
return wb;
}
/**
* Méthode permettant de convertir les rows en csv pour importer dans MusicTopus
* @param {Array} rows
*
* @return {string}
*/
static async convertToMusicTopus(rows) {
let data = "itemId;createdAt;updatedAt\n\r";
for (let i = 0; i < rows.length; i += 1) {
const { discogsId, createdAt, updatedAt } = rows[i];
data += `${discogsId};${createdAt};${updatedAt}\n\r`;
}
data += "v1.0";
return data;
}
/**
* Méthode permettant d'ajouter un album dans une collection
* @param {Object} req
@ -234,6 +252,8 @@ class Albums extends Pages {
return Albums.convertToCsv(rows);
case "xls":
return Albums.convertToXls(rows);
case "musictopus":
return Albums.convertToMusicTopus(rows);
case "json":
default:
return {

View file

@ -17,6 +17,7 @@ router
switch (exportFormat) {
case "csv":
case "musictopus":
res.header("Content-Type", "text/csv");
return res.status(200).send(data);
case "xls":