mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 20:49:02 +00:00
Add right sidebar
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -75,4 +75,7 @@ type Query {
|
||||
|
||||
myAlbums: [Album] @isAuthenticated
|
||||
album(id: ID): Album @isAuthenticated
|
||||
|
||||
myPhotos: [Photo] @isAuthenticated
|
||||
photo(id: ID): Photo @isAuthenticated
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user