From 35ee2834a3c3b2090b829315d901d3b6cb2d86d8 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Mon, 11 Oct 2021 18:45:25 +0200 Subject: [PATCH] graphql: Add a method to create a group --- schema.graphql | 1 + server/src/infra/graphql/mutation.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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,