Skip to content

Commit

Permalink
feat(falcor): add delete a book in a world
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
itsjgf committed Oct 1, 2016
1 parent 5f2afae commit 9c0f3f9
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/falcor/worlds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,48 @@ export default ( db, req, res ) => {
}
,
},
{
route: 'worldsById[{keys:ids}].books.remove',
call: ( { ids: [ world_id ] }, [ {id} ] ) => db
::getBooksFromWorld(world_id,user._id)
.toArray()
.map(array => ({
length: array.length,
position: array.findIndex(element => element === id)
}))
.flatMap(({position,length}) => {
if(position === -1) {
throw new Error('Could not find the book to delete');
}
return db
::archiveDocument('books', id, user._id)
.flatMap((document) => {
if (document.archived !== true)
throw new Error('Could not delete the book');
return db
::archiveNode('Book', document._id, user._id)
.flatMap(node =>
db::archiveRelationship('IN', document._id,world_id, user._id)
)
.flatMap(() => {
return [
{
path: [ 'booksById', id ],
invalidated: true
},
{
path: [ 'worldsById', world_id, 'books', 'length' ],
value: length-1,
},
{
path: [ 'worldsById', world_id, 'books', { from: position, to: length } ],
invalidated: true,
},
]
})
})
})
},

/**
* Outlines
Expand Down

0 comments on commit 9c0f3f9

Please sign in to comment.