.
This commit is contained in:
parent
0d871050d2
commit
47d8a7edc7
@ -28,7 +28,7 @@ const authorizeUser = (condition: (user: AuthUser) => boolean) => {
|
|||||||
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
return (req: AuthenticatedRequest, res: Response, next: NextFunction) => {
|
||||||
const user = req.user as AuthUser;
|
const user = req.user as AuthUser;
|
||||||
if (!user || !condition(user)) {
|
if (!user || !condition(user)) {
|
||||||
return generateExpressError(req, res, httpStatus.UNAUTHORIZED);
|
generateExpressError(req, res, httpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAuthContext(req, res, user);
|
setAuthContext(req, res, user);
|
||||||
@ -64,6 +64,6 @@ export const checkAdminOrSelf = [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return generateExpressError(req, res, httpStatus.UNAUTHORIZED);
|
generateExpressError(req, res, httpStatus.UNAUTHORIZED);
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@ -21,11 +21,7 @@ export const getDealerMiddleware = async (
|
|||||||
const { context } = res.locals as { context: ICommonContext };
|
const { context } = res.locals as { context: ICommonContext };
|
||||||
|
|
||||||
if (!user || !user.id) {
|
if (!user || !user.id) {
|
||||||
return handleError(
|
handleError(req, res, UseCaseError.create(UseCaseError.NOT_FOUND_ERROR, "User not found"));
|
||||||
req,
|
|
||||||
res,
|
|
||||||
UseCaseError.create(UseCaseError.NOT_FOUND_ERROR, "User not found")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerDealerRepository(context);
|
registerDealerRepository(context);
|
||||||
@ -39,7 +35,7 @@ export const getDealerMiddleware = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (dealerOrError.isFailure) {
|
if (dealerOrError.isFailure) {
|
||||||
return handleError(req, res, dealerOrError.error);
|
handleError(req, res, dealerOrError.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.context = {
|
res.locals.context = {
|
||||||
@ -50,7 +46,7 @@ export const getDealerMiddleware = async (
|
|||||||
next();
|
next();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
console.error("Error in getDealerMiddleware:", e as Error);
|
console.error("Error in getDealerMiddleware:", e as Error);
|
||||||
return handleError(req, res, e as UseCaseError);
|
handleError(req, res, e as UseCaseError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,5 +86,5 @@ function handleError(req: express.Request, res: express.Response, error?: IUseCa
|
|||||||
|
|
||||||
const infraError = InfrastructureError.create(infraErrorCode, message, error);
|
const infraError = InfrastructureError.create(infraErrorCode, message, error);
|
||||||
|
|
||||||
return generateExpressError(req, res, status, message, infraError);
|
generateExpressError(req, res, status, message, infraError);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user