diff --git a/schema.graphql b/schema.graphql index d41d6e7..71ae663 100644 --- a/schema.graphql +++ b/schema.graphql @@ -5,6 +5,7 @@ input EqualityConstraint { type Mutation { createUser(user: CreateUserInput!): User! + createGroup(name: String!): Group! updateUser(user: UpdateUserInput!): Success! updateGroup(group: UpdateGroupInput!): Success! addUserToGroup(userId: String!, groupId: Int!): Success! diff --git a/server/src/infra/graphql/mutation.rs b/server/src/infra/graphql/mutation.rs index f9e71dd..f5089af 100644 --- a/server/src/infra/graphql/mutation.rs +++ b/server/src/infra/graphql/mutation.rs @@ -83,6 +83,21 @@ impl Mutation { .map(Into::into)?) } + async fn create_group( + context: &Context, + name: String, + ) -> FieldResult> { + if !context.validation_result.is_admin { + return Err("Unauthorized group creation".into()); + } + let group_id = context.handler.create_group(&name).await?; + Ok(context + .handler + .get_group_details(group_id) + .await + .map(Into::into)?) + } + async fn update_user( context: &Context, user: UpdateUserInput,