Skip to content

Commit 5f2afae

Browse files
committed
feat(falcor): add create a new book in a world
Closes #10
1 parent 5d2074f commit 5f2afae

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/falcor/transforms/books.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export function getBooksLength(worldID) {
5555
export function getWorldByBook(bookId) {
5656
const query = `
5757
match (b:Book)-[rel:IN]->(w:World)
58-
WHERE rel.archived = false and b._id = "${bookId}"
58+
WHERE rel.archived = false and b._id = {bookId}
5959
return w._id as id
6060
`;
61-
return this.flatMap(db => db.neo.run(query))
61+
return this.flatMap(db => db.neo.run(query,{bookId}))
6262
.map(record =>
6363
record.get('id')
6464
)

src/falcor/transforms/worlds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function createRelationFromBookToWorld(bookId, worldId, creator){
127127
const query = `
128128
MERGE (w:World {_id: {worldId} })
129129
MERGE (b:Book {_id: {bookId} })
130-
MERGE (b)-[rel:IN]-(w)
130+
MERGE (b)-[rel:IN]->(w)
131131
SET rel.archived = false, b.archived = false,
132132
rel.created_at = timestamp(), rel.creator = {creator}
133133
return rel as rel`;

src/falcor/worlds/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export default ( db, req, res ) => {
203203
)
204204
)
205205
},
206-
207206
{
208207
route: 'worldsById[{keys:ids}].books.length',
209208
get: ({ids}) => {
@@ -219,6 +218,28 @@ export default ( db, req, res ) => {
219218
})
220219
}
221220
},
221+
{
222+
route: 'worldsById[{keys:ids}].books.push',
223+
call: ( { ids: [ id ] }, [ {title} ] ) => {
224+
return db
225+
::getWorldsNext([id], user._id)
226+
.flatMap(world => db
227+
::createBook(world._id, title, user._id)
228+
.flatMap(book => db
229+
::getBooksFromWorld(world._id, user._id).count()
230+
.flatMap(count => {
231+
return [
232+
{path: ["booksById", book._id, "_id"], value: book._id},
233+
{path: ["booksById", book._id, "title"], value: book.title},
234+
{path: ["worldsById", world._id, "books", count - 1], value: $ref(['booksById', book._id])},
235+
{path: ["worldsById", world._id, "books", "length"], value: count},
236+
]
237+
})
238+
)
239+
)
240+
}
241+
,
242+
},
222243

223244
/**
224245
* Outlines

0 commit comments

Comments
 (0)