|
|
@ -1,11 +1,12 @@ |
|
|
|
import { FastifyRequest, FastifyReply } from "fastify"; |
|
|
|
import { MiddlewareRequest } from "../middleware"; |
|
|
|
|
|
|
|
export default class Request |
|
|
|
export default class Request<T = unknown> |
|
|
|
{ |
|
|
|
/** |
|
|
|
* Handle the incoming request |
|
|
|
*/ |
|
|
|
public async handle(request: FastifyRequest, reply: FastifyReply) { |
|
|
|
public async handle(request: MiddlewareRequest<T>, reply: FastifyReply) { |
|
|
|
if (!this.isAuthorized(request)) { |
|
|
|
reply.status(403); |
|
|
|
return { |
|
|
@ -34,21 +35,21 @@ export default class Request |
|
|
|
/** |
|
|
|
* Check if the user is authorized to make this request |
|
|
|
*/ |
|
|
|
public isAuthorized(request: FastifyRequest) { |
|
|
|
public isAuthorized(request: MiddlewareRequest<T>) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Check the format of the given request |
|
|
|
*/ |
|
|
|
public checkFormat(request: FastifyRequest) { |
|
|
|
public checkFormat(request: MiddlewareRequest<T>) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Validate the request and return any errors |
|
|
|
*/ |
|
|
|
public async validate(request: FastifyRequest): Promise<any|undefined> { |
|
|
|
public async validate(request: MiddlewareRequest<T>): Promise<any|undefined> { |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
} |
|
|
|