Browse Source

Transfer old common library code to the request API package

dev
David Ludwig 4 years ago
parent
commit
db21241355
3 changed files with 122 additions and 0 deletions
  1. +1
    -0
      api/request/src/index.ts
  2. +31
    -0
      api/request/src/schema.ts
  3. +90
    -0
      api/request/src/validation.ts

+ 1
- 0
api/request/src/index.ts View File

@ -1 +1,2 @@
export * from "./schema";
export * from "./validation";

+ 31
- 0
api/request/src/schema.ts View File

@ -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<T> extends IApiResponse {
data: T
}
interface IMovieRequestInfo {
plexLink: string | null,
ticketId: number | null


+ 90
- 0
api/request/src/validation.ts View File

@ -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"
}
}
}
};

Loading…
Cancel
Save