From 35b47bee733610c4d07384b091f8b8e97314189f Mon Sep 17 00:00:00 2001 From: Jade Chang Date: Sat, 6 Jan 2024 18:08:08 +0800 Subject: [PATCH 1/2] allow empty slug --- src/graphql/mutations/UpdateUser.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/graphql/mutations/UpdateUser.js b/src/graphql/mutations/UpdateUser.js index c9d48d07..517e094d 100644 --- a/src/graphql/mutations/UpdateUser.js +++ b/src/graphql/mutations/UpdateUser.js @@ -3,6 +3,7 @@ import client from 'util/client'; import User from 'graphql/models/User'; import { omit, omitBy } from 'lodash'; import { AvatarTypes } from 'util/user'; +import { errors } from 'graphql/models/SlugErrorEnum'; import { assertSlugIsValid } from 'graphql/queries/ValidateSlug'; import AvatarTypeEnum from 'graphql/models/AvatarTypeEnum'; @@ -42,7 +43,12 @@ export default { try { await assertSlugIsValid(slug, userId); } catch (e) { - throw new Error(`Invalid slug: ${e}`); + if (e === errors.EMPTY) { + // allow user to update slug to empty + doc.slug = ''; + } else { + throw new Error(`Invalid slug: ${e}`); + } } } From 4457be166a9f49b092a2f5d70928d680955f1409 Mon Sep 17 00:00:00 2001 From: Jade Chang Date: Sat, 6 Jan 2024 18:14:08 +0800 Subject: [PATCH 2/2] Check if slug is neither undefined nor null before validation --- src/graphql/mutations/UpdateUser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphql/mutations/UpdateUser.js b/src/graphql/mutations/UpdateUser.js index 517e094d..8984aa28 100644 --- a/src/graphql/mutations/UpdateUser.js +++ b/src/graphql/mutations/UpdateUser.js @@ -39,7 +39,7 @@ export default { throw new Error(`There's nothing to update`); // Ensure uniqueness of slug - if (slug !== undefined) { + if (slug !== undefined && slug !== null) { try { await assertSlugIsValid(slug, userId); } catch (e) {