Skip to content
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

Demo - [Guidelines] - Public API route + logging user data + no unit test for new service #104

Closed
wants to merge 3 commits into from

Conversation

wvl94
Copy link
Contributor

@wvl94 wvl94 commented Nov 5, 2024

💡 PR Summary generated by FirstMate

Overview: Introduced a new public API route for user data and added logging functionality.

Changes:
New API Route:

  • Added /user-data/:id endpoint in exampleRouter.js to fetch user data.

Logging Enhancements:

  • Integrated logging in ExampleService and NewService to track user data retrieval.

Workflow Updates:

  • Updated .github/workflows/firstmate.yaml to include pnpm test after package installation.

TLDR: New public API route for user data with logging added; review the router and service changes for functionality.

Generated by FirstMate and automatically updated on every commit.

Copy link

firstmatebot bot commented Nov 5, 2024

PR Review

⚠️ It seems that you can still improve the quality of your PR:

    ❌ Code quality & structure: Method name 'getExcetutedDocuments' contains a typo; should be 'getExecutedDocuments' for consistency.
    ❌ Coding standards: Avoid logging sensitive user data; use debug level or mask information in getUserData.
    ❌ Logging best-practices: Avoid logging sensitive data at info level in getUserData; use debug or mask data.
    ❌ Security & access control: Ensure all routes, including /user-data/:id, use grantAccessByPermissionMiddleware for proper permissions.

Generated by Firstmate to make sure you can focus on coding new features.

Comment on lines +10 to +12
async getExcetutedDocuments(id) {
return await exampleRepo.getById(id)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

The method name getExcetutedDocuments contains a typo; it should be getExecutedDocuments for consistency and clarity. Additionally, consider implementing retries for external API calls in this method to enhance reliability. Here's a simple example of how to implement retries:

async getExecutedDocuments(id, retries = 3) {
    try {
        return await exampleRepo.getById(id);
    } catch (error) {
        if (retries > 0) {
            return this.getExecutedDocuments(id, retries - 1);
        }
        throw error;
    }
}

Comment on lines +10 to +12
async getExcetutedDocuments(id) {
return await exampleRepo.getById(id)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

The method name getExcetutedDocuments contains a spelling mistake; it should be corrected to getExecutedDocuments. Additionally, consider implementing retries for the external API calls in getUserData to enhance reliability. Here's how you can implement a simple retry mechanism:

async function retry(fn, retries = 3) {
    for (let i = 0; i < retries; i++) {
        try {
            return await fn();
        } catch (error) {
            if (i === retries - 1) throw error;
        }
    }
}

Comment on lines +15 to +17
const user = await exampleRepo.getById(id);
logger.info(user.data);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

Logging sensitive user data with logger.info(user.data) in getUserData can lead to privacy issues. Instead, consider using a debug level for logging or mask the sensitive information before logging. For example, you could do:

logger.debug({ id: user.id, name: user.name }); // Mask sensitive data

Comment on lines +15 to +17
const user = await exampleRepo.getById(id);
logger.info(user.data);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

Logging user data at the info level in getUserData may expose sensitive information. Instead, use a debug level for logging or mask the sensitive data before logging. For example, you could modify the logging line as follows:

- logger.info(user.data);
+ logger.debug({ id: user.id, name: user.name }); // Masking sensitive data

Comment on lines +12 to +13
router.route("/user-data/:id").get( exampleController.getById)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alt text

The route '/user-data/:id' lacks the 'grantAccessByPermissionMiddleware', which can lead to unauthorized access. You should add the middleware to ensure proper permission checks like this:

+ router.route("/user-data/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.USER_DATA]), exampleController.getById)

This will help secure the route according to the guidelines.

@wvl94 wvl94 closed this Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant