Skip to content

Commit 6088cc1

Browse files
committed
refactor: update middleware types and eslint configuration
1 parent 81ad536 commit 6088cc1

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default [
2222
...tseslint.configs.recommended,
2323
{
2424
rules: {
25+
"@typescript-eslint/no-explicit-any": "warn",
2526
'@typescript-eslint/no-unused-vars': [
2627
'error',
2728
{

src/middlewares/can-access.middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { NextFunction, Request, Response } from "express";
1+
import type { NextFunction } from "express";
22
import { StatusCodes } from "http-status-codes";
33
import type { RoleType } from "../enums";
44
import { getUserById } from "../modules/user/user.services";
55
import { errorResponse } from "../utils/api.utils";
66
import type { JwtPayload } from "../utils/auth.utils";
7+
import type { RequestAny, ResponseAny } from "../openapi/magic-router";
78

89
export type CanAccessByType = "roles";
910

@@ -13,7 +14,7 @@ export type CanAccessOptions = {
1314

1415
export const canAccess =
1516
<T extends CanAccessByType>(by?: T, access?: CanAccessOptions[T][]) =>
16-
async (req: Request, res: Response, next?: NextFunction) => {
17+
async (req: RequestAny, res: ResponseAny, next?: NextFunction) => {
1718
try {
1819
const requestUser = req?.user as JwtPayload;
1920

src/middlewares/extract-jwt-schema.middleware.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { NextFunction, Request, Response } from "express";
1+
import type { NextFunction } from "express";
22
import { type JwtPayload, verifyToken } from "../utils/auth.utils";
3+
import type { RequestAny, ResponseAny } from "../openapi/magic-router";
34

45
export const extractJwt = async (
5-
req: Request,
6-
_: Response,
6+
req: RequestAny,
7+
_: ResponseAny,
78
next: NextFunction,
89
) => {
910
try {

src/middlewares/multer-s3.middleware.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import type { NextFunction, Request, Response } from "express";
1+
import type { NextFunction } from "express";
22
import { StatusCodes } from "http-status-codes";
33
import multer from "multer";
44
import multerS3 from "multer-s3";
55
import s3, { BUCKET_NAME } from "../lib/aws.service";
66
import { errorResponse } from "../utils/api.utils";
77
import { checkFiletype } from "../utils/common.utils";
8+
import type { RequestAny, ResponseAny } from "../openapi/magic-router";
89

910
const storageEngineProfile: multer.StorageEngine = multerS3({
1011
s3: s3,
1112
bucket: BUCKET_NAME,
1213
metadata: (_, file, cb) => {
1314
cb(null, { fieldName: file.fieldname });
1415
},
15-
key: (req: Request, file, cb) => {
16+
key: (req: RequestAny, file, cb) => {
1617
const key = `user-${req.user.id}/profile/${file.originalname}`;
1718

1819
if (checkFiletype(file)) {
@@ -24,8 +25,8 @@ const storageEngineProfile: multer.StorageEngine = multerS3({
2425
});
2526

2627
export const uploadProfile = (
27-
req: Request,
28-
res: Response,
28+
req: RequestAny,
29+
res: ResponseAny,
2930
next: NextFunction,
3031
) => {
3132
const upload = multer({

src/middlewares/validate-zod-schema.middleware.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import type { NextFunction, Request, Response } from "express";
1+
import type { NextFunction } from "express";
22
import { StatusCodes } from "http-status-codes";
33
import { ZodError, type ZodSchema } from "zod";
44
import type { RequestZodSchemaType } from "../types";
55
import { errorResponse } from "../utils/api.utils";
66
import { sanitizeRecord } from "../utils/common.utils";
7+
import type { RequestAny, ResponseAny } from "../openapi/magic-router";
78

89
export const validateZodSchema =
910
(payload: RequestZodSchemaType) =>
10-
(req: Request, res: Response, next?: NextFunction) => {
11+
(req: RequestAny, res: ResponseAny, next?: NextFunction) => {
1112
let error: ZodError | null = null;
1213

1314
for (const [key, value] of Object.entries(payload)) {

src/modules/user/user.router.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
handleCreateUser,
66
handleGetUsers,
77
} from "./user.controller";
8-
import { usersPaginatedSchema } from "./user.dto";
98
import { createUserSchema, getUsersSchema } from "./user.schema";
109

1110
export const USER_ROUTER_ROOT = "/users";
@@ -16,7 +15,6 @@ userRouter.get(
1615
"/",
1716
{
1817
requestType: { query: getUsersSchema },
19-
responseModel: usersPaginatedSchema,
2018
},
2119
canAccess(),
2220
handleGetUsers,

src/openapi/magic-router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type Method =
3535
| "options"
3636
| "trace";
3737

38-
export type IDontKnow = unknown | never;
38+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
39+
export type IDontKnow = unknown | never | any;
3940
export type MaybePromise = void | Promise<void>;
4041
export type RequestAny = Request<IDontKnow, IDontKnow, IDontKnow, IDontKnow>;
4142
export type ResponseAny = Response<IDontKnow, Record<string, unknown>>;

0 commit comments

Comments
 (0)