Skip to content

feat: [WIP] 🍰 Implement JoinGroup, GroupMember, SwitchGroupMemberRole Resolvers #5194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions backend/src/db/graphql/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ export const createGroupMutation = gql`
}
`

export const joinGroupMutation = gql`
mutation ($id: ID!, $userId: ID!) {
JoinGroup(id: $id, userId: $userId) {
id
name
slug
myRoleInGroup
}
}
`

export const switchGroupMemberRoleMutation = gql`
mutation ($id: ID!, $userId: ID!, $roleInGroup: GroupMemberRole!) {
SwitchGroupMemberRole(id: $id, userId: $userId, roleInGroup: $roleInGroup) {
id
name
slug
myRoleInGroup
}
}
`

// ------ queries

export const groupQuery = gql`
Expand Down Expand Up @@ -93,3 +115,14 @@ export const groupQuery = gql`
}
}
`

export const groupMemberQuery = gql`
query ($id: ID!, $first: Int, $offset: Int, $orderBy: [_UserOrdering], $filter: _UserFilter) {
GroupMember(id: $id, first: $first, offset: $offset, orderBy: $orderBy, filter: $filter) {
id
name
slug
myRoleInGroup
}
}
`
189 changes: 188 additions & 1 deletion backend/src/db/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import createServer from '../server'
import faker from '@faker-js/faker'
import Factory from '../db/factories'
import { getNeode, getDriver } from '../db/neo4j'
import { createGroupMutation } from './graphql/groups'
import {
createGroupMutation,
joinGroupMutation,
switchGroupMemberRoleMutation,
} from './graphql/groups'
import { createPostMutation } from './graphql/posts'
import { createCommentMutation } from './graphql/comments'

Expand Down Expand Up @@ -400,6 +404,62 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
}),
])
await Promise.all([
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g0',
userId: 'u2',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g0',
userId: 'u3',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g0',
userId: 'u4',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g0',
userId: 'u6',
},
}),
])
await Promise.all([
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u2',
roleInGroup: 'usual',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u4',
roleInGroup: 'admin',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u3',
roleInGroup: 'owner',
},
}),
])

authenticatedUser = await jennyRostock.toJson()
await Promise.all([
Expand All @@ -416,6 +476,77 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
}),
])
await Promise.all([
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g1',
userId: 'u1',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g1',
userId: 'u2',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g1',
userId: 'u5',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g1',
userId: 'u6',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g1',
userId: 'u7',
},
}),
])
await Promise.all([
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u1',
roleInGroup: 'usual',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u2',
roleInGroup: 'usual',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u5',
roleInGroup: 'admin',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u6',
roleInGroup: 'owner',
},
}),
])

authenticatedUser = await bobDerBaumeister.toJson()
await Promise.all([
Expand All @@ -432,6 +563,62 @@ const languages = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pl']
},
}),
])
await Promise.all([
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g2',
userId: 'u4',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g2',
userId: 'u5',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g2',
userId: 'u6',
},
}),
mutate({
mutation: joinGroupMutation,
variables: {
id: 'g2',
userId: 'u7',
},
}),
])
await Promise.all([
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u4',
roleInGroup: 'usual',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u5',
roleInGroup: 'usual',
},
}),
mutate({
mutation: switchGroupMemberRoleMutation,
variables: {
id: 'g0',
userId: 'u6',
roleInGroup: 'usual',
},
}),
])

// Create Posts

Expand Down
9 changes: 9 additions & 0 deletions backend/src/helpers/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@
export function gql(strings) {
return strings.join('')
}

// sometime we have to wait to check a db state by having a look into the db in a certain moment
// or we wait a bit to check if we missed to set an await somewhere
// see: https://www.sitepoint.com/delay-sleep-pause-wait/
export function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
// usage – 4 seconds for example
// await sleep(4 * 1000)
Loading