New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(eslint): pass #6 #1871
fix(eslint): pass #6 #1871
Changes from 1 commit
a03ac4c
2969129
bc45a04
90bd289
19e6903
e009346
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import type { Request, Response, NextFunction } from 'express'; | |
import { validateRequest } from 'zod-express'; | ||
import { z } from 'zod'; | ||
import persistController from './controllers/persist.controller.js'; | ||
import { logLevelValues } from '@nangohq/shared'; | ||
import { logLevelValues, logger } from '@nangohq/shared'; | ||
|
||
export const server = express(); | ||
server.use(express.json({ limit: '100mb' })); | ||
|
@@ -12,14 +12,14 @@ server.use((req: Request, res: Response, next: NextFunction) => { | |
const originalSend = res.send; | ||
res.send = function (body: any) { | ||
if (res.statusCode >= 400) { | ||
console.log(`[Persist] [Error] ${req.method} ${req.path} ${res.statusCode} '${JSON.stringify(body)}'`); | ||
logger.info(`[Persist] [Error] ${req.method} ${req.path} ${res.statusCode} '${JSON.stringify(body)}'`); | ||
} | ||
originalSend.call(this, body) as any; | ||
return this; | ||
}; | ||
next(); | ||
if (res.statusCode < 400) { | ||
console.log(`[Persist] ${req.method} ${req.path} ${res.statusCode}`); | ||
logger.info(`[Persist] ${req.method} ${req.path} ${res.statusCode}`); | ||
} | ||
}); | ||
|
||
|
@@ -39,7 +39,7 @@ server.post( | |
msg: z.string() | ||
}) | ||
}), | ||
persistController.saveActivityLog | ||
persistController.saveActivityLog.bind(persistController) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is bind necessary here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not necessary to make it work but because it's in a class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what would you recommend instead of using a class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. straight up function, if we had state it would be debatable but it's not the case and I would argue keeping state between api calls is dangerous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed. In this specific case the class in only used as a namespace mechanism |
||
); | ||
|
||
const validateRecordsRequest = validateRequest({ | ||
|
@@ -64,9 +64,9 @@ const validateRecordsRequest = validateRequest({ | |
}) | ||
}); | ||
const recordPath = '/environment/:environmentId/connection/:nangoConnectionId/sync/:syncId/job/:syncJobId/records'; | ||
server.post(recordPath, validateRecordsRequest, persistController.saveRecords); | ||
server.delete(recordPath, validateRecordsRequest, persistController.deleteRecords); | ||
server.put(recordPath, validateRecordsRequest, persistController.updateRecords); | ||
server.post(recordPath, validateRecordsRequest, persistController.saveRecords.bind(persistController)); | ||
server.delete(recordPath, validateRecordsRequest, persistController.deleteRecords.bind(persistController)); | ||
server.put(recordPath, validateRecordsRequest, persistController.updateRecords.bind(persistController)); | ||
|
||
server.use((_req: Request, res: Response, next: NextFunction) => { | ||
res.status(404); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how was it working before? or maybe it wasn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's just ignored by the regex compiler hence why it's unnecessary, cf: https://eslint.org/docs/latest/rules/no-useless-escape