mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
add group count query
This commit is contained in:
parent
6fa1ad3360
commit
5b66edb387
@ -312,6 +312,7 @@ export default shield(
|
||||
currentUser: allow,
|
||||
Group: isAuthenticated,
|
||||
GroupMembers: isAllowedSeeingGroupMembers,
|
||||
GroupCount: isAuthenticated,
|
||||
Post: allow,
|
||||
profilePagePosts: allow,
|
||||
Comment: allow,
|
||||
|
||||
@ -81,6 +81,39 @@ export default {
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
GroupCount: async (_object, params, context, _resolveInfo) => {
|
||||
const { isMember } = params
|
||||
const {
|
||||
user: { id: userId },
|
||||
} = context
|
||||
const session = context.driver.session()
|
||||
const readTxResultPromise = session.readTransaction(async (txc) => {
|
||||
let cypher
|
||||
if (isMember) {
|
||||
cypher = `MATCH (user:User)-[membership:MEMBER_OF]->(group:Group)
|
||||
WHERE user.id = $userId
|
||||
AND membership.role IN ['usual', 'admin', 'owner']
|
||||
RETURN toString(count(group)) AS count`
|
||||
} else {
|
||||
cypher = `MATCH (group:Group)
|
||||
OPTIONAL MATCH (user:User)-[membership:MEMBER_OF]->(group)
|
||||
WHERE user.id = $userId
|
||||
WITH group, membership
|
||||
WHERE group.groupType IN ['public', 'closed']
|
||||
OR membership.role IN ['usual', 'admin', 'owner']
|
||||
RETURN toString(count(group)) AS count`
|
||||
}
|
||||
const transactionResponse = await txc.run(cypher, { userId })
|
||||
return transactionResponse.records.map((record) => record.get('count'))
|
||||
})
|
||||
try {
|
||||
return parseInt(await readTxResultPromise)
|
||||
} catch (error) {
|
||||
throw new Error(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
},
|
||||
},
|
||||
Mutation: {
|
||||
CreateGroup: async (_parent, params, context, _resolveInfo) => {
|
||||
|
||||
@ -65,8 +65,8 @@ type Query {
|
||||
isMember: Boolean # if 'undefined' or 'null' then get all groups
|
||||
id: ID
|
||||
slug: String
|
||||
# first: Int # not implemented yet
|
||||
# offset: Int # not implemented yet
|
||||
first: Int # not implemented yet
|
||||
offset: Int # not implemented yet
|
||||
# orderBy: [_GroupOrdering] # not implemented yet
|
||||
# filter: _GroupFilter # not implemented yet
|
||||
): [Group]
|
||||
@ -79,6 +79,8 @@ type Query {
|
||||
# filter: _UserFilter # not implemented yet
|
||||
): [User]
|
||||
|
||||
GroupCount(isMember: Boolean): Int
|
||||
|
||||
# AvailableGroupTypes: [GroupType]!
|
||||
|
||||
# AvailableGroupActionRadii: [GroupActionRadius]!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user