API: Add queries teamsByIds and teamAuthorization
This commit is contained in:
1 parent
e84685f690
commit
766ed5e8ef
3 files changed
+25
-3
No files matched your search
@@ -5,14 +5,19 @@ import TEAMS_FRAGMENT from '../../fragments/TeamsFragment'
|
||||
|
||||
export const teams = async (parent, args, ctx, info) => {
|
||||
logger.info('teams')
|
||||
console.log('teams')
|
||||
return ctx.db.query.teamsConnection({}, TEAMS_CONNECTIONS_FRAGMENT)
|
||||
}
|
||||
|
||||
export const teamsByIds = async (parent, { teamIds }, ctx, info) => {
|
||||
logger.info('teamsByIds')
|
||||
logger.info(teamIds)
|
||||
return ctx.db.query.teams({where: { id_in: teamIds } }, TEAMS_FRAGMENT)
|
||||
}
|
||||
|
||||
export const teamById = async (parent, { teamId }, ctx, info) => {
|
||||
logger.info('teamById')
|
||||
logger.info(teamId)
|
||||
return ctx.db.query.team({ where: { id: teamId } }, info)
|
||||
return ctx.db.query.team({ where: { id: teamId } }, TEAMS_FRAGMENT)
|
||||
}
|
||||
|
||||
export const teamByName = async (parent, { name }, ctx, info) => {
|
||||
@@ -29,6 +34,19 @@ export const teamWithRole = async (parent, { teamId, role }, ctx, info) => {
|
||||
return ctx.db.query.teamsConnection({where: {AND: [{id: teamId},{members_some:{role: role}}]}, first:1}, info)
|
||||
}
|
||||
|
||||
export const teamAuthorization = async (parent, { teamId, role }, ctx, info) => {
|
||||
const authId = ctx.request.headers.userid
|
||||
if (!authId) {
|
||||
throw new AuthenticationError()
|
||||
return
|
||||
}
|
||||
if(role == undefined || role == null){
|
||||
return ctx.db.query.teamsConnection({where:{ AND:{id:teamId,members_some:{member:{authId:authId}, role_in:['OWNER','ADMIN']}}}, first:1}, info)
|
||||
} else {
|
||||
return ctx.db.query.teamsConnection({where:{ AND:{id:teamId,members_some:{member:{authId:authId}, role:role}}}, first:1}, info)
|
||||
}
|
||||
}
|
||||
|
||||
export const teamsByOwner = async (parent, args, ctx, info) => {
|
||||
logger.info('teamsByOwner')
|
||||
const authId = ctx.request.headers.userid
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { logger } from '../../../logger'
|
||||
|
||||
import { member, owner } from './Member'
|
||||
import { teams, teamById, teamByName, teamBySlug, teamWithRole, teamsByOwner, teamsByRole } from './Team'
|
||||
import { teams, teamById, teamsByIds, teamByName, teamBySlug, teamWithRole, teamAuthorization, teamsByOwner, teamsByRole } from './Team'
|
||||
import{ fbByTeamMember } from './TeamMember'
|
||||
|
||||
export const resolvers = {
|
||||
@@ -9,9 +9,11 @@ export const resolvers = {
|
||||
member: (parent, arg, ctx, info) => member(parent, arg, ctx, info),
|
||||
teams: (parent, arg, ctx, info) => teams(parent, arg, ctx, info),
|
||||
teamById: (parent, arg, ctx, info) => teamById(parent, arg, ctx, info),
|
||||
teamsByIds: (parent, arg, ctx, info) => teamsByIds(parent, arg, ctx, info),
|
||||
teamByName: (parent, arg, ctx, info) => teamByName(parent, arg, ctx, info),
|
||||
teamBySlug: (parent, arg, ctx, info) => teamBySlug(parent, arg, ctx, info),
|
||||
teamWithRole: (parent, arg, ctx, info) => teamWithRole(parent, arg, ctx, info),
|
||||
teamAuthorization: (parent, arg, ctx, info) => teamAuthorization(parent, arg, ctx, info),
|
||||
teamsByOwner: (parent, arg, ctx, info) => teamsByOwner(parent, arg, ctx, info),
|
||||
teamsByRole: (parent, arg, ctx, info) => teamsByRole(parent, arg, ctx, info),
|
||||
owner: (parent, arg, ctx, info) => owner(parent, arg, ctx, info),
|
||||
|
||||
@@ -11,7 +11,9 @@ type Query {
|
||||
teamByName(name: String!): Team
|
||||
teamBySlug(slug: String!): Team
|
||||
teamById(teamId: String!): Team
|
||||
teamsByIds(teamIds: [ID!]): [Team]
|
||||
teamWithRole(teamId: String!, role: String!): Team
|
||||
teamAuthorization(teamId: String!, role: String): Team
|
||||
teamsByOwner: [Team!]! @isAuthenticated
|
||||
teamsByRole: [Team!]! @isAuthenticated
|
||||
fbByTeamMember: Team @isAuthenticated
|
||||
|
||||
Reference in new issue
Block a user