-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update endpoints to allow forest data posting and fetching #2
Conversation
Endpoints, DTOs updated with 'type' parameter, to specify what kind of reports is being created/fetched
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.
At the very least, address the CodeQL issue pertaining to MongoDB filtering by following the instructions provided in the issue description.
Furthermore, I strongly suggest transforming the type into an enum and implementing validation through the ParseEnumPipe
. Considering the potential conflicts with reserved keywords in certain languages, it would be appreciated if you could consider renaming the variable from "type" to something else (e.g. "category").
src/admin/admin.service.ts
Outdated
@@ -22,8 +22,8 @@ export class AdminService { | |||
private readonly reportRepository: ReportRepository, | |||
) {} | |||
|
|||
async getAllReports(): Promise<FullReportDto[]> { | |||
const reports = await this.reportRepository.getAllReports(); | |||
async getAllReports(type: string): Promise<FullReportDto[]> { |
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 term "type" is a reserved keyword in certain programming languages, such as Python and Scala. While it is generally recommended to steer clear of using reserved keywords as variable names to prevent potential conflicts.
ba73abc
to
cd2d0f5
Compare
cd2d0f5
to
db429ba
Compare
0, | ||
e.filter((stat: { _id: string }) => stat._id == 'nepasitvirtino')[0] | ||
.count ?? 0, | ||
ReportService.filterStatistics(e, 'gautas'), |
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.
Please note that this change appears unrelated to the current pull request. For future reference, it's best to create a new pull request specifically for this bug fix.
private static filterStatistics(e: any, status: string): number { | ||
return e.filter((stat: { _id: string }) => stat._id == status).length > 0 | ||
? e.filter((stat: { _id: string }) => stat._id == status)[0].count ?? 0 | ||
: 0; |
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.
Let's keep it DRY. Also, consider utilizing Array.at (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at), which gracefully handles undefined values for non-existent array indices
Equal operator bug fix
Update status statistics logic
Endpoints, DTOs updated with 'type' parameter, to specify what kind of reports is being created/fetched