Skip to content

Commit

Permalink
feat: Add schema for querying users consistently in api
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonSiler committed Nov 19, 2024
1 parent 3274924 commit f0cd938
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/aux-records/RecordsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,46 @@ export interface RecordsServerOptions {
xpController?: XpController | null; // TODO: Determine whether or not this should be optional
}

/**
* A schema that represents a request to get an XP user by one of it's IDs.
*/
const GetXpUserById = z
.object({
userId: z.string().optional().nullable(),
xpId: z.string().optional().nullable(),
})
.refine(
(contractedUser) => {
if (!contractedUser) return true;
if (
contractedUser.userId ??
(undefined === undefined && contractedUser.xpId) ??
undefined === undefined
)
return false;
return true;
},
{
message: 'One of properties "userId", "xpId" are required',
path: ['userId', 'xpId'],
}
)
.refine(
(contractedUser) => {
if (!contractedUser) return true;
if (
typeof contractedUser.userId === 'string' &&
typeof contractedUser.xpId === 'string'
)
return false;
return true;
},
{
message: 'Properties userId and xpId are mutually exclusive.',
path: ['userId', 'xpId'],
}
);

/**
* Defines a class that represents a generic HTTP server suitable for Records HTTP Requests.
*/
Expand Down Expand Up @@ -2103,12 +2143,7 @@ export class RecordsServer {
getXpUserMeta: procedure()
.origins('api')
.http('GET', '/api/v2/xp/user')
.inputs(
z.object({
userId: z.string().optional().nullable(),
xpId: z.string().optional().nullable(),
})
)
.inputs(GetXpUserById)
.handler(async (input, context) => {
const authUser = await this._validateSessionKey(
context.sessionKey
Expand Down

0 comments on commit f0cd938

Please sign in to comment.