Fix BooksController.createBookReference()

This commit is contained in:
Robbie Antenesse 2020-08-24 12:13:14 -06:00
parent 707c22dac7
commit 63c7d3676d
3 changed files with 15 additions and 17 deletions

View File

@ -105,10 +105,10 @@ class Inventaire {
}
});
const bookData = await json;
let bookData = await json;
if (typeof bookData.entities !== 'undefined' && typeof bookData.entities[uri] !== 'undefined') {
const bookData = Inventaire.handleEntity(bookData.entities[uri], this.lang);
bookData = Inventaire.handleEntity(bookData.entities[uri], this.lang);
bookData['covers'] = await this.getCovers(bookData.uri);
return bookData;

View File

@ -98,20 +98,18 @@ class BooksController {
const inventaire = new Inventaire(this.language);
const bookData = await inventaire.getBookData(uri);
return await bookReferencesModel.create({
values: {
name: bookData.name,
description: bookData.description,
sources: {
[source]: uri,
},
covers: bookData.covers.map(cover => {
return {
sourceId: uri,
url: cover.url,
};
}),
locale: this.language,
}
name: bookData.name,
description: bookData.description,
sources: {
[source]: uri,
},
covers: (bookData.covers ? bookData.covers : []).map(cover => {
return {
sourceId: uri,
url: cover.url,
};
}),
locale: this.language,
});
}
}

View File

@ -40,7 +40,7 @@ async function routes(fastify, options) {
}
const books = new BooksController(request.body.source, request.body.uri, request.language);
const newBookReference = await books.createBookReference(request.body.source, request.body.uri);
const newBookReference = await books.createBookReference(fastify.models.BookReference, request.body.source, request.body.uri);
console.log('created new bookreference', newBookReference);
return newBookReference.id;
});