mirror of
https://github.com/zoriya/flood.git
synced 2026-06-02 11:06:35 +00:00
server: consolidate services null checks to middleware
This commit is contained in:
@@ -6,14 +6,24 @@ declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Express {
|
||||
interface Request {
|
||||
services?: ReturnType<typeof services['getAllServices']>;
|
||||
services: ReturnType<typeof services['getAllServices']>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (req: Request, _res: Response, next: NextFunction) => {
|
||||
if (req.user != null) {
|
||||
req.services = services.getAllServices(req.user);
|
||||
const failedInitializeResponse = (res: Response): Response => {
|
||||
return res.status(500).json({message: 'Flood server failed to initialze.'});
|
||||
};
|
||||
|
||||
export default (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.user == null) {
|
||||
return failedInitializeResponse(res);
|
||||
}
|
||||
|
||||
req.services = services.getAllServices(req.user);
|
||||
if (req.services?.clientGatewayService == null) {
|
||||
return failedInitializeResponse(res);
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user