-
Notifications
You must be signed in to change notification settings - Fork 273
refactor: optimize nickname update logic in Discord actions #2487
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
base: develop
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -100,8 +100,10 @@ const getRangeProgressData = async (queryParams) => { | |
async function getProgressByDate(pathParams, queryParams) { | ||
const { type, typeId, date } = pathParams; | ||
const { dev } = queryParams; | ||
/* eslint-disable security/detect-object-injection */ | ||
await assertUserOrTaskExists({ [TYPE_MAP[type]]: typeId }); | ||
const query = buildQueryToSearchProgressByDay({ [TYPE_MAP[type]]: typeId, date }); | ||
/* eslint-enable security/detect-object-injection */ | ||
Comment on lines
101
to
+106
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. Unsafe Dynamic Type Mapping
Tell me moreWhat is the issue?The code uses dynamic property access with TYPE_MAP[type] and disables security linting, indicating a potential design flaw in type handling. Why this mattersUsing dynamic property access and disabling security checks makes the code more vulnerable and harder to maintain. A more type-safe approach would improve code reliability and security. Suggested change ∙ Feature Previewconst typeMappers = {
user: (typeId) => ({ userId: typeId }),
task: (typeId) => ({ taskId: typeId })
};
if (!typeMappers[type]) {
throw new Error('Invalid type');
}
const mappedParams = typeMappers[type](typeId);
await assertUserOrTaskExists(mappedParams);
const query = buildQueryToSearchProgressByDay({ ...mappedParams, date }); Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
const result = await query.get(); | ||
if (!result.size) { | ||
throw new NotFound(PROGRESS_DOCUMENT_NOT_FOUND); | ||
|
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.
Incorrect success condition for nickname updates
Tell me more
What is the issue?
The condition
response?.message
only checks for the existence of a message property, not whether the nickname update was actually successful.Why this matters
This could lead to counting failed operations as successful updates if the Discord API returns an error message in the response.message field, resulting in inaccurate reporting of update statistics.
Suggested change ∙ Feature Preview
Check for a proper success indicator instead of just the presence of a message. For example:
Or verify the actual structure of the
setUserDiscordNickname
response to determine the correct success condition.Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.