Scheduling infrastructure for absolutely everyone.
feat: Add user's avatar to POST and PATCH requests in users endpoints (#11187)
Hamza Fouade94c030c45c4
diff --git a/apps/api/lib/utils/isValidBase64Image.ts b/apps/api/lib/utils/isValidBase64Image.tsnew file mode 100644index 00000000000..8c69df55067--- /dev/null+++ b/apps/api/lib/utils/isValidBase64Image.ts@@ -0,0 +1,4 @@+export function isValidBase64Image(input: string): boolean {+ const regex = /^data:image\/[^;]+;base64,(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;+ return regex.test(input);+}diff --git a/apps/api/lib/validations/user.ts b/apps/api/lib/validations/user.tsindex de9e22a976d..09d389e41a3 100644--- a/apps/api/lib/validations/user.ts+++ b/apps/api/lib/validations/user.ts@@ -4,6 +4,7 @@ import { checkUsername } from "@calcom/lib/server/checkUsername";import { _UserModel as User } from "@calcom/prisma/zod";import { iso8601 } from "@calcom/prisma/zod-utils";+import { isValidBase64Image } from "~/lib/utils/isValidBase64";import { timeZone } from "~/lib/validations/shared/timeZone";// @note: These are the ONLY values allowed as weekStart. So user don't introduce bad data.@@ -106,6 +107,7 @@ const schemaUserEditParams = z.object({.optional().nullable(),locale: z.nativeEnum(locales).optional().nullable(),+ avatar: z.string().refine(isValidBase64Image).optional(),});// @note: These are the values that are editable via PATCH method on the user Model,@@ -128,6 +130,7 @@ const schemaUserCreateParams = z.object({.nullable(),locale: z.nativeEnum(locales).optional(),createdDate: iso8601.optional(),+ avatar: z.string().refine(isValidBase64Image).optional(),});// @note: These are the values that are editable via PATCH method on the user Model,diff --git a/apps/api/pages/api/users/[userId]/_patch.ts b/apps/api/pages/api/users/[userId]/_patch.tsindex 84f6ffb45be..ff917c2048d 100644--- a/apps/api/pages/api/users/[userId]/_patch.ts+++ b/apps/api/pages/api/users/[userId]/_patch.ts@@ -65,6 +65,9 @@ import { schemaUserEditBodyParams, schemaUserReadPublic } from "~/lib/validation* locale:* description: The user's locale. Acceptable values are one of [EN, FR, IT, RU, ES, DE, PT, RO, NL, PT_BR, ES_419, KO, JA, PL, AR, IW, ZH_CH, ZH_TW, CS, SR, SV, VI]* type: string+ * avatar:+ * description: The user's avatar, in base64 format+ * type: string* examples:* user:* summary: An example of USERdiff --git a/apps/api/pages/api/users/_post.ts b/apps/api/pages/api/users/_post.tsindex 15c68aa31d0..bcc4f243152 100644--- a/apps/api/pages/api/users/_post.ts+++ b/apps/api/pages/api/users/_post.ts@@ -60,6 +60,9 @@ import { schemaUserCreateBodyParams } from "~/lib/validations/user";* locale:* description: The new user's locale. Acceptable values are one of [EN, FR, IT, RU, ES, DE, PT, RO, NL, PT_BR, ES_419, KO, JA, PL, AR, IW, ZH_CH, ZH_TW, CS, SR, SV, VI]* type: string+ * avatar:+ * description: The user's avatar, in base64 format+ * type: string* examples:* user:* summary: An example of USER