-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(typo & linting): fixed minor typos in readme & linting errors
- Loading branch information
1 parent
f4d236c
commit 46e6572
Showing
6 changed files
with
93 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,92 @@ | ||
'use strict' | ||
const { AuthorizationError, ApolloError } = require('apollo-server-express') | ||
const appRoot = require('app-root-path') | ||
const { AuthorizationError, ApolloError } = require( 'apollo-server-express' ) | ||
const appRoot = require( 'app-root-path' ) | ||
const { | ||
createStream, | ||
getStream, | ||
updateStream, | ||
deleteStream, | ||
getUserStreams, | ||
getUserStreamsCount, | ||
getStreamUsers, | ||
grantPermissionsStream, | ||
revokePermissionsStream | ||
} = require('../../services/streams') | ||
const { validateServerRole, validateScopes, authorizeResolver } = require(`${appRoot}/modules/shared`) | ||
createStream, | ||
getStream, | ||
updateStream, | ||
deleteStream, | ||
getUserStreams, | ||
getUserStreamsCount, | ||
getStreamUsers, | ||
grantPermissionsStream, | ||
revokePermissionsStream | ||
} = require( '../../services/streams' ) | ||
const { validateServerRole, validateScopes, authorizeResolver } = require( `${appRoot}/modules/shared` ) | ||
|
||
module.exports = { | ||
Query: { | ||
async stream(parent, args, context, info) { | ||
await validateScopes(context.scopes, 'streams:read') | ||
await authorizeResolver(context.userId, args.id, 'stream:reviewer') | ||
|
||
let stream = await getStream({ streamId: args.id }) | ||
return stream | ||
} | ||
Query: { | ||
async stream( parent, args, context, info ) { | ||
await validateScopes( context.scopes, 'streams:read' ) | ||
await authorizeResolver( context.userId, args.id, 'stream:reviewer' ) | ||
|
||
let stream = await getStream( { streamId: args.id } ) | ||
return stream | ||
} | ||
}, | ||
Stream: { | ||
|
||
async collaborators( parent, args, context, info ) { | ||
let users = await getStreamUsers( { streamId: parent.id } ) | ||
return users | ||
} | ||
|
||
}, | ||
User: { | ||
|
||
async streams( parent, args, context, info ) { | ||
// Return only the user's public streams if parent.id !== context.userId | ||
let publicOnly = parent.id !== context.userId | ||
let totalCount = await getUserStreamsCount( { userId: parent.id, publicOnly } ) | ||
|
||
let { cursor, streams } = await getUserStreams( { userId: parent.id, limit: args.limit, cursor: args.cursor, publicOnly: publicOnly } ) | ||
return { totalCount, cursor: cursor, items: streams } | ||
} | ||
|
||
}, | ||
Mutation: { | ||
async streamCreate( parent, args, context, info ) { | ||
await validateServerRole( context, 'server:user' ) | ||
await validateScopes( context.scopes, 'streams:write' ) | ||
|
||
let id = await createStream( { ...args.stream, ownerId: context.userId } ) | ||
return id | ||
}, | ||
Stream: { | ||
|
||
async collaborators(parent, args, context, info) { | ||
let users = await getStreamUsers({ streamId: parent.id }) | ||
return users | ||
} | ||
async streamUpdate( parent, args, context, info ) { | ||
await validateServerRole( context, 'server:user' ) | ||
await validateScopes( context.scopes, 'streams:write' ) | ||
await authorizeResolver( context.userId, args.stream.id, 'stream:owner' ) | ||
|
||
await updateStream( { streamId: args.stream.id, name: args.stream.name, description: args.stream.description } ) | ||
return true | ||
}, | ||
User: { | ||
|
||
async streams(parent, args, context, info) { | ||
// Return only the user's public streams if parent.id !== context.userId | ||
let publicOnly = parent.id !== context.userId | ||
let totalCount = await getUserStreamsCount({ userId: parent.id, publicOnly }) | ||
async streamDelete( parent, args, context, info ) { | ||
await validateServerRole( context, 'server:user' ) | ||
await validateScopes( context.scopes, 'streams:write' ) | ||
await authorizeResolver( context.userId, args.id, 'stream:owner' ) | ||
|
||
await deleteStream( { streamId: args.id } ) | ||
return true | ||
}, | ||
|
||
let { cursor, streams } = await getUserStreams({ userId: parent.id, limit: args.limit, cursor: args.cursor, publicOnly: publicOnly }) | ||
return { totalCount, cursor: cursor, items: streams } | ||
} | ||
async streamGrantPermission( parent, args, context, info ) { | ||
await validateServerRole( context, 'server:user' ) | ||
await validateScopes( context.scopes, 'streams:write' ) | ||
await authorizeResolver( context.userId, args.streamId, 'stream:owner' ) | ||
|
||
if ( context.userId === args.userId ) throw new Error( 'You cannot set roles for yourself.' ) | ||
|
||
return await grantPermissionsStream( { streamId: args.streamId, userId: args.userId, role: args.role.toLowerCase( ) || 'read' } ) | ||
}, | ||
Mutation: { | ||
async streamCreate(parent, args, context, info) { | ||
await validateServerRole(context, 'server:user') | ||
await validateScopes(context.scopes, 'streams:write') | ||
|
||
let id = await createStream({...args.stream, ownerId: context.userId }) | ||
return id | ||
}, | ||
|
||
async streamUpdate(parent, args, context, info) { | ||
await validateServerRole(context, 'server:user') | ||
await validateScopes(context.scopes, 'streams:write') | ||
await authorizeResolver(context.userId, args.stream.id, 'stream:owner') | ||
|
||
await updateStream({ streamId: args.stream.id, name: args.stream.name, description: args.stream.description }) | ||
return true | ||
}, | ||
|
||
async streamDelete(parent, args, context, info) { | ||
await validateServerRole(context, 'server:user') | ||
await validateScopes(context.scopes, 'streams:write') | ||
await authorizeResolver(context.userId, args.id, 'stream:owner') | ||
|
||
await deleteStream({ streamId: args.id }) | ||
return true | ||
}, | ||
|
||
async streamGrantPermission(parent, args, context, info) { | ||
await validateServerRole(context, 'server:user') | ||
await validateScopes(context.scopes, 'streams:write') | ||
await authorizeResolver(context.userId, args.streamId, 'stream:owner') | ||
|
||
if (context.userId === args.userId) throw new Error('You cannot set roles for yourself.') | ||
|
||
return await grantPermissionsStream({ streamId: args.streamId, userId: args.userId, role: args.role.toLowerCase() || 'read' }) | ||
}, | ||
|
||
async streamRevokePermission(parent, args, context, info) { | ||
await validateServerRole(context, 'server:user') | ||
await validateScopes(context.scopes, 'streams:write') | ||
await authorizeResolver(context.userId, args.streamId, 'stream:owner') | ||
|
||
return await revokePermissionsStream({...args }) | ||
} | ||
|
||
async streamRevokePermission( parent, args, context, info ) { | ||
await validateServerRole( context, 'server:user' ) | ||
await validateScopes( context.scopes, 'streams:write' ) | ||
await authorizeResolver( context.userId, args.streamId, 'stream:owner' ) | ||
|
||
return await revokePermissionsStream( { ...args } ) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters