Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | 39x 8x 39x 39x | import { z } from "zod";
import { ApiError, ApiResult } from "shared/types/api/errors";
import { SignupMessage } from "shared/types/models/signupMessage";
import { UserProgramItems } from "shared/types/models/user";
import {
PASSWORD_LENGTH_MAX,
PASSWORD_LENGTH_MIN,
USERNAME_LENGTH_MAX,
USERNAME_LENGTH_MIN,
} from "shared/constants/validation";
import { EventLogItem } from "shared/types/models/eventLog";
// GET user
interface GetUserResult extends ApiResult {
programItems: UserProgramItems;
serial: string;
groupCode: string;
isGroupCreator: boolean;
username: string;
eventLogItems: EventLogItem[];
email: string;
}
interface GetUserError extends ApiError {
errorId: "unknown";
}
export type GetUserResponse = GetUserResult | GetUserError;
// POST user
export const PostUserRequestSchema = z.object({
username: z.string().trim().min(USERNAME_LENGTH_MIN).max(USERNAME_LENGTH_MAX),
password: z.string().trim().min(PASSWORD_LENGTH_MIN).max(PASSWORD_LENGTH_MAX),
// Local account creation always requires a registration code
serial: z
.string()
.min(1)
.transform((val) => val.replaceAll("-", "")), // remove dashes
});
export type PostUserRequest = z.infer<typeof PostUserRequestSchema>;
interface PostUserResult extends ApiResult {
username: string;
}
interface PostUserError extends ApiError {
errorId: "unknown" | "invalidSerial" | "usernameNotFree";
}
export type PostUserResponse = PostUserResult | PostUserError;
// POST update user password
export const PostUpdateUserPasswordRequestSchema = z.object({
usernameToUpdate: z.string(),
password: z.string().trim().min(PASSWORD_LENGTH_MIN).max(PASSWORD_LENGTH_MAX),
});
export type PostUpdateUserPasswordRequest = z.infer<
typeof PostUpdateUserPasswordRequestSchema
>;
export interface PostUpdateUserPasswordResult extends ApiResult {
username: string;
}
export interface PostUpdateUserPasswordError extends ApiError {
errorId: "unknown" | "notAllowed";
}
export type PostUpdateUserPasswordResponse =
| PostUpdateUserPasswordResult
| PostUpdateUserPasswordError;
// GET user by serial
export const GetUserBySerialRequestSchema = z.object({
searchTerm: z.string(),
});
export type GetUserBySerialRequest = z.infer<
typeof GetUserBySerialRequestSchema
>;
interface GetUserBySerialResult extends ApiResult {
serial: string;
username: string;
createdAt: string;
}
interface GetUserBySerialError extends ApiError {
errorId: "unknown" | "kompassiLogin";
}
export type GetUserBySerialResponse =
| GetUserBySerialResult
| GetUserBySerialError;
// GET signup messages
export interface GetSignupMessagesResult extends ApiResult {
signupMessages: SignupMessage[];
}
interface GetSignupMessagesError extends ApiError {
errorId: "unknown";
}
export type GetSignupMessagesResponse =
| GetSignupMessagesResult
| GetSignupMessagesError;
|