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

Update endpoints to allow forest data posting and fetching #2

Merged
merged 12 commits into from
Feb 13, 2024

Conversation

Ignas-rgb
Copy link
Contributor

Endpoints, DTOs updated with 'type' parameter, to specify what kind of reports is being created/fetched

Endpoints, DTOs updated with 'type' parameter, to specify what kind of reports is being created/fetched
@Ignas-rgb Ignas-rgb requested a review from vycius February 2, 2024 14:33
@Ignas-rgb Ignas-rgb added the feature New feature label Feb 2, 2024
Copy link
Member

@vycius vycius left a 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.controller.ts Outdated Show resolved Hide resolved
@@ -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[]> {
Copy link
Member

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.

src/report/dto/create-report.dto.ts Outdated Show resolved Hide resolved
0,
e.filter((stat: { _id: string }) => stat._id == 'nepasitvirtino')[0]
.count ?? 0,
ReportService.filterStatistics(e, 'gautas'),
Copy link
Member

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;
Copy link
Member

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

@Ignas-rgb Ignas-rgb merged commit 85dd4bf into main Feb 13, 2024
3 checks passed
@Ignas-rgb Ignas-rgb deleted the forest-data-integration branch February 13, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants