issue/2 #28

Merged
dbroqua merged 6 commits from issue/2 into master 2022-03-04 16:33:46 +01:00
2 changed files with 25 additions and 4 deletions
Showing only changes of commit e7858c9870 - Show all commits

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":