Add right sidebar

This commit is contained in:
viktorstrate
2019-07-19 21:39:51 +02:00
parent 1d5ca69701
commit 034b85e1f7
9 changed files with 253 additions and 49 deletions

View File

@@ -39,6 +39,27 @@ const myAlbumQuery = function(args, ctx, info) {
return query
}
const myPhotoQuery = function(args, ctx, info) {
const query = cypherQuery(args, ctx, info)
const whereSplit = query[0].indexOf('RETURN')
query[0] = injectAt(
query[0],
whereSplit,
`MATCH (u:User { id: {userid} }) WHERE (u)-[:OWNS]->(:Album)-[:CONTAINS]->(photo) `
)
query[1].userid = ctx.user.id
query[0] = injectAt(
query[0],
query[0].indexOf('RETURN `photo` {') + 16,
query[0].indexOf('RETURN `photo` {}') == -1 ? ` .id, ` : ` .id `
)
return query
}
const Query = {
async myAlbums(root, args, ctx, info) {
let query = myAlbumQuery(args, ctx, info)
@@ -73,6 +94,39 @@ const Query = {
return result.records[0].get('album')
},
async myPhotos(root, args, ctx, info) {
let query = myPhotoQuery(args, ctx, info)
console.log(query)
const session = ctx.driver.session()
const result = await session.run(...query)
session.close()
return result.records.map(record => record.get('photo'))
},
async photo(root, args, ctx, info) {
const session = ctx.driver.session()
let query = myPhotoQuery(args, ctx, info)
const whereSplit = query[0].indexOf('RETURN')
query[0] = injectAt(query[0], whereSplit, ` AND photo.id = {id} `)
query[1].id = args.id
console.log(query)
const result = await session.run(...query)
session.close()
if (result.records.length == 0) {
throw new Error('Album was not found')
}
return result.records[0].get('photo')
},
}
function photoResolver(image) {

View File

@@ -75,4 +75,7 @@ type Query {
myAlbums: [Album] @isAuthenticated
album(id: ID): Album @isAuthenticated
myPhotos: [Photo] @isAuthenticated
photo(id: ID): Photo @isAuthenticated
}