-
Notifications
You must be signed in to change notification settings - Fork 0
Demo: add log of user data and public API route. #110
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
Conversation
PR Review ❌ Documentation drift: Update documentation for manual Docker validation after removal from CI. Generated by Firstmate to make sure you can focus on coding new features. |
const user = await exampleRepo.getById(id); | ||
logger.info(user.data); | ||
} |
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.
router.route("/user-data/:id").get( exampleController.getById) | ||
|
||
export default router; |
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.
The route /user-data/:id
does not use the grantAccessByPermissionMiddleware
, which is required for security purposes. You should modify the route to include this middleware as follows:
router.route("/user-data/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById);
This ensures that all routes check permissions properly.
(Based on guideline 'Check permissions with middleware')
export class NewService { | ||
|
||
async getById(id) { | ||
logger.info("Getting data by ID.") | ||
return await exampleRepo.getById(id); | ||
} | ||
|
||
async getDataFromRepo(id) { | ||
return await exampleRepo.getData(id); | ||
} |
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.
The new service functions getById
and getDataFromRepo
lack corresponding unit tests, which are essential for ensuring functionality and reliability. You should implement unit tests in the test folder to cover these functions, similar to the existing unit tests in test/test-user.js
. Here's a basic structure for your tests:
import NewService from '../src/services/newService.js';
describe('NewService', () => {
it('should get data by ID', async () => {
// Your test logic here
});
it('should get data from repo', async () => {
// Your test logic here
});
});
(Based on guideline 'Unit tests for service functions')
PR Review ❌ Logging issues: User data logged at info level; change to debug level. Generated by Firstmate to make sure you can focus on coding new features. |
async getUserData(id) { | ||
const user = await exampleRepo.getById(id); | ||
logger.info(user.data); | ||
} |
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.
router.route("/user-data/:id").get( exampleController.getById) | ||
|
||
export default router; |
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.
The route /user-data/:id
does not utilize the grantAccessByPermissionMiddleware
. You should add this middleware to ensure proper permission checks, like this:
+ router.route("/user-data/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById);
(Based on guideline 'Routes should check permissions')
import exampleRepo from "../repos/exampleRepo.js" | ||
import logger from "./utils/logger.js"; | ||
|
||
export class NewService { | ||
|
||
async getById(id) { | ||
logger.info("Getting data by ID.") | ||
return await exampleRepo.getById(id); | ||
} | ||
|
||
async getDataFromRepo(id) { | ||
return await exampleRepo.getData(id); | ||
} | ||
|
||
|
||
} | ||
|
||
export default new NewService(); |
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.
The newService.js
file lacks corresponding unit tests in the test folder. Implement unit tests to cover the functionality of the NewService
class, similar to how it's done in test/test-user.py
. Here's a basic structure for your test file:
import NewService from '../services/newService.js';
describe('NewService', () => {
test('should get data by ID', async () => {
// Your test implementation here
});
});
(Based on guideline 'Services should have unit tests')
💡 PR Summary generated by FirstMate
New API Route and Logging Enhancements
Changes:
New API Route:
/user-data/:id
endpoint inexampleRouter.js
to fetch user data.Logging Implementation:
ExampleService
to log user data retrieval.NewService
class with logging for data fetching operations.CI Workflow Update:
.github/workflows/firstmate.yaml
to runpnpm test
after package installation.TLDR: Introduced a new user data API route and logging for data retrieval; updated CI workflow to include tests. Focus on
exampleRouter.js
andexampleService.js
for new functionality.Generated by FirstMate and automatically updated on every commit.