Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracks #114

Merged
merged 69 commits into from
May 15, 2017
Merged

Tracks #114

merged 69 commits into from
May 15, 2017

Conversation

aibarbetta
Copy link
Member

@aibarbetta aibarbetta commented May 11, 2017

Closes #23

@@ -8,9 +8,13 @@ const findAllEntries = (tableName) => {

const findEntryWithId = (tableName, id) => {
logger.info(`Searching for entry ${id}`);
return db(tableName).where('id', id);
return db(tableName).where('id', id).first('*');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A createNewEntry seguro que no, si no cuando alguien cree mas de un entry (como en los tests) no tenes manera de ver que se creo mas alla de la primer entry. Con los otros casos puede que sea igual.


const findAllWithAttributes = (tableName, attributes) => {
logger.info(`Querying table ${tableName} for entries with attributes ${JSON.stringify(attributes, null, 4)}`);
return db(tableName).where(attributes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pero hay que ser consistente y seguir abstrallendonos de knex (? 👮

.then((insertedTrack) => {
logger.info(`Inserted track: ${JSON.stringify(insertedTrack, null, 4)}`);
return artistHandler.selectAllArtistsIdsWithNames(track.artists)
.then(ids => artistTrackHandler.insertAssociations(insertedTrack[0].id, ids))
return artistTrackHandler.insertAssociations(insertedTrack[0].id, body.artists)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que pasa si se inserta mas de un track? (Por ej, en los tests)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yyyy pero para los tests habria que hacer otra funcion si es que necesitamos, no tendriamos que codear pensando en los tests. Si hay algun caso de uso en el que te puedan dar de alta mas de un track en un mismo request si, pero segun la doc creo que no 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eso te iba a decir, hay que abrir un issue para crearle al handler funciones especificas para los tests y no crear conflictos con el comportamiento esperado por la doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Burocracia ftw!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abrilo y vamos comentando las que necesitaria

return generalHandler.updateEntryWithId(tables.tracks, id, track)
.then((updatedTrack) => {
logger.info(`Updated track: ${JSON.stringify(updatedTrack, null, 4)}`);
return artistTrackHandler.updateAssociations(updatedTrack[0].id, body.artists)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ídem insertedTrack, aunque no vi que hagamos un update de a varios en los tests aún.

})
.then((result) => {
if (result.length) {
logger.info(`User ${userId} already liked track ${trackId}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conviene poner esto como un warn

};
};

const formatAlbumFromTrackJson = (album) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sisi me parece perfecto

};

const formatAlbumFromTrackJson = (album) => {
// TODO: catch null artist earlier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si el id del artista que se pasa al crear un track no existe, la asociación se crea igual y cuando pedís todos los artists con los id's del track te llega un array vacío.
En definitiva, esto viene por otro quilombo: no estamos chequeando que los artists que nos pasa el nuevo track existan.

db.general.findEntryWithId(tables.tracks, req.params.id)
.then((track) => {
if (!respond.entryExists(req.params.id, track, res)) return;
const getArtistsInfo = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👮👮👮👮👮

(bien ahí igual, me olvide de moverlas despues de chequear que funcionen)

Promise.all(getters)
.then((results) => {
logger.info(`Results: ${JSON.stringify(results, null, 4)}`);
logger.info(`Pre fetch Track: ${JSON.stringify(track, null, 4)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me olvide de volarlos 😅

"initialTrack": {
"name": "Despacito",
"duration": 240,
"artists": ["Luis Fonsi", "Papa Baute"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se actualizo la creación de asociaciones junto con este cambio? Antes se buscaba el id del artista según el nombre y después se lo insertaba en la tabla de asociación.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si, mas arriba comente que la funcion que buscaba los ids de artistas con x nombre ya no se usa. Mire la doc y llegan ids directo.

@aibarbetta aibarbetta merged commit 897068d into develop May 15, 2017
@aibarbetta aibarbetta deleted the tracks branch May 15, 2017 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants