diff --git a/api/request/src/index.ts b/api/request/src/index.ts index 686fbd9..86eca4e 100644 --- a/api/request/src/index.ts +++ b/api/request/src/index.ts @@ -1 +1,2 @@ export * from "./schema"; +export * from "./validation"; diff --git a/api/request/src/schema.ts b/api/request/src/schema.ts index 7816640..93447ee 100644 --- a/api/request/src/schema.ts +++ b/api/request/src/schema.ts @@ -3,6 +3,37 @@ import { IMovieDetails as IMovieDetailsBase } from "@autoplex-api/search"; +/** + * Basic user information schema + */ +export interface IUser { + id : number, + name : string, + isAdmin: boolean +} + +/** + * The JWT auth token structure + */ +export interface ITokenSchema extends IUser { + iat : number, + exp : number +} + +/** + * The general API response structure + */ +export interface IApiResponse { + status: string +} + +/** + * A generic data response from the API + */ +export interface IApiDataResponse extends IApiResponse { + data: T +} + interface IMovieRequestInfo { plexLink: string | null, ticketId: number | null diff --git a/api/request/src/validation.ts b/api/request/src/validation.ts new file mode 100644 index 0000000..e961bba --- /dev/null +++ b/api/request/src/validation.ts @@ -0,0 +1,90 @@ +export const ValidationConstraints = { + api: { + movie: { + search: { + query: { + presence: { + allowEmpty: false, + message: "The query cannot be blank" + } + }, + year: { + numericality: { + onlyInteger: true, + greaterThan: 0, + notGreaterThan: "Invalid year", + notValid: "Invalid year", + notInteger: "Invalid year" + } + } + } + } + }, + login: { + email: { + presence: { + allowEmpty: false, + message: "An email address is required" + } + }, + password: { + presence: { + allowEmpty: false, + message: "A password is required" + } + } + }, + register: { + token: { + presence: { + message: "A valid token is required to register" + }, + token: { + message: "A valid token is required to register" + } + }, + name: { + presence: { + allowEmpty: false, + message: "Your name is required" + }, + length: { + maximum: 50, + tooLong: "Your name cannot exceed 50 characters" + } + }, + email: { + presence: { + allowEmpty: false, + message: "Your email is required" + }, + length: { + maximum: 255, + tooLong: "An email address cannot exceed 255 characters" + }, + email: { + message: "A valid email address is required" + } + }, + password: { + presence: { + allowEmpty: false, + message: "A password is required" + }, + length: { + minimum: 8, + tooShort: "Password should be at least 8 characters" + } + }, + retypePassword: { + presence: { + allowEmpty: false, + message: "Re-type your password to confirm it" + }, + equality: { + attribute: "password", + message: "Passwords must match" + } + } + } +};