import { FastifyRequest } from "fastify";
|
|
import validate from "validate.js";
|
|
import { RegisterToken } from "@server/database/entities";
|
|
import { hasAllProperties } from "@server/util";
|
|
import { constraints } from "@common/validation";
|
|
import Request from "./Request";
|
|
|
|
interface IRegisterFormBody {
|
|
token: string,
|
|
name: string,
|
|
email: string,
|
|
password: string,
|
|
retypePassword: string
|
|
}
|
|
|
|
export default class RegisterRequest extends Request
|
|
{
|
|
/**
|
|
* Validate the request
|
|
*/
|
|
public validate(request: FastifyRequest) {
|
|
// let body = <IRegisterFormBody>request.body;
|
|
// if (!RegisterToken.isValid(body.token)) {
|
|
// return {
|
|
// "token": "Invalid token"
|
|
// }
|
|
// }
|
|
console.log("Validating a request");
|
|
return validate.async(request.body, {
|
|
token: constraints.token,
|
|
name: constraints.name,
|
|
email: constraints.email,
|
|
password: constraints.password,
|
|
retypePassword: constraints.retypePassword
|
|
}, <any>{ fullMessages: false });
|
|
}
|
|
}
|