From 1eecdf3e968ec7820e2b3dd2d01c507e142fb478 Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Sat, 2 Jul 2022 21:03:37 +0100 Subject: [PATCH] feat: add schemas for new challenge database things --- common/src/lib/schemas.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/common/src/lib/schemas.ts b/common/src/lib/schemas.ts index 9b4f2e94a..7afb98e40 100644 --- a/common/src/lib/schemas.ts +++ b/common/src/lib/schemas.ts @@ -461,6 +461,15 @@ const PR_CHART_DOCUMENT = (game: Game) => (self: unknown) => { })(self); }; +const PR_CHALLENGE = { + chartID: "string", + authorID: p.isPositiveNonZeroInteger, + type: p.isIn("lamp", "score"), + + game: p.isIn(games), + playtype: isValidPlaytype, +}; + // Returns true on success, throws on failure. export type SchemaValidatorFunction = (self: unknown) => true; @@ -1084,6 +1093,15 @@ const PRE_SCHEMAS = { return p.isPositive(self); }, }), + + "challenge-wall": prSchemaFnWrap(PR_CHALLENGE), + "challenge-subs": prSchemaFnWrap({ + ...PR_CHALLENGE, + userID: p.isPositiveNonZeroInteger, + achieved: "boolean", + achievedAt: "?number", + }), + notifications: prSchemaFnWrap({ title: "string", notifID: "string", @@ -1107,10 +1125,25 @@ const PRE_SCHEMAS = { break; } - case "MILESTONE_CHANGED": + case "MILESTONE_CHANGED": { subSchema = { milestoneID: "string", }; + break; + } + + case "CHALLENGE_BEAT": { + subSchema = { + userID: p.isPositiveNonZeroInteger, + challenge: PR_CHALLENGE, + }; + break; + } + + case "CHALLENGE_RECEIVED": + subSchema = { + challenge: PR_CHALLENGE, + }; } const err = p(self, subSchema);