-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(api): implement bulk inventory creation admin API endpoint #1159
base: develop
Are you sure you want to change the base?
Conversation
… data source route
…uerying For clarity of how they are prioritized in the loop
…ogging of sources
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
Category | Issue | Fix Detected |
---|---|---|
Incorrect String Type Check ▹ view | ||
Incorrect Error Array Type Definition ▹ view | ||
Overly Restrictive Population Check ▹ view | ||
Missing Type Enforcement for Priority Range ▹ view | ||
Inefficient Data Type for Priority Field ▹ view | ||
Insufficient Locode Format Validation ▹ view | ||
Inefficient Request Body Handling ▹ view |
Files scanned
File Path | Reviewed |
---|---|
app/src/app/api/v0/city/[city]/user/[user]/route.ts | ✅ |
app/src/app/api/v0/admin/bulk/route.ts | ✅ |
app/src/backend/AdminService.ts | ✅ |
app/src/app/api/v0/datasource/[inventoryId]/route.ts | ✅ |
app/src/backend/DataSourceService.ts | ✅ |
app/src/models/DataSourceI18n.ts | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Need a new review? Comment
/korbit-review
on this PR and I'll review your latest changes.Korbit Guide: Usage and Customization
Interacting with Korbit
- You can manually ask Korbit to review your PR using the
/korbit-review
command in a comment at the root of your PR.- You can ask Korbit to generate a new PR description using the
/korbit-generate-pr-description
command in any comment on your PR.- Too many Korbit comments? I can resolve all my comment threads if you use the
/korbit-resolve
command in any comment on your PR.- Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
- Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.
Customizing Korbit
- Check out our docs on how you can make Korbit work best for you and your team.
- Customize Korbit for your organization through the Korbit Console.
Current Korbit Configuration
General Settings
Setting Value Review Schedule Automatic excluding drafts Max Issue Count 10 Automatic PR Descriptions ✅ Issue Categories
Category Enabled Documentation ✅ Logging ✅ Error Handling ✅ Readability ✅ Design ✅ Performance ✅ Security ✅ Functionality ✅ Feedback and Support
Note
Korbit Pro is free for open source projects 🎉
Looking to add Korbit to your team? Get started with a free 2 week trial here
inventoryId: string, | ||
cityLocode: string, | ||
): Promise<{ locode: string; error: string }[]> { | ||
const errors: any[] = []; |
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 Error Array Type Definition 
Tell me more
What is the issue?
The errors array type in connectAllDataSources is defined as any[], but the function's return type and actual usage indicates it should be an array of objects with locode and error properties.
Why this matters
This type mismatch could lead to runtime errors if the wrong error structure is pushed to the array, as TypeScript's type checking is bypassed with 'any'.
Suggested change ∙ Feature Preview
Define a proper type for the errors array:
const errors: { locode: string; error: string }[] = [];
💬 Chat with Korbit by mentioning @korbit-ai.
app/src/backend/DataSourceService.ts
Outdated
inventory.year!, | ||
) as PopulationAttributes; | ||
// TODO allow country downscaling to work if there is no region population? | ||
if (!cityPopulation || !countryPopulation || !regionPopulation) { |
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.
Overly Restrictive Population Check 
Tell me more
What is the issue?
The code requires all population data (city, country, and region) to be present, but there's a TODO comment suggesting that country downscaling should work without region population.
Why this matters
This restrictive check prevents valid use cases where population-based downscaling could still work with just country data, reducing the functionality of the system unnecessarily.
Suggested change ∙ Feature Preview
Modify the check to allow country-based downscaling when region data is missing:
if (!cityPopulation || !countryPopulation) {
populationIssue = "missing-population";
} else {
countryPopulationScaleFactor = cityPopulation.population / countryPopulation.countryPopulation!;
if (regionPopulation) {
regionPopulationScaleFactor = cityPopulation.population / regionPopulation.regionPopulation!;
}
}
💬 Chat with Korbit by mentioning @korbit-ai.
import { z } from "zod"; | ||
|
||
const createBulkInventoriesRequest = z.object({ | ||
cityLocodes: z.array(z.string()), // List of city locodes |
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.
Insufficient Locode Format Validation 
Tell me more
What is the issue?
The cityLocodes validation accepts any string without validating if it's a proper locode format.
Why this matters
Invalid locode formats could cause downstream processing issues or data inconsistencies in the inventory creation process.
Suggested change ∙ Feature Preview
Add a regex pattern to validate locode format:
const LOCODE_PATTERN = /^[A-Z]{5}$/;
const createBulkInventoriesRequest = z.object({
cityLocodes: z.array(z.string().regex(LOCODE_PATTERN, "Invalid locode format")).min(1),
// ... rest of the schema
});
💬 Chat with Korbit by mentioning @korbit-ai.
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.
Great work 👍
import { NextResponse } from "next/server"; | ||
import { z } from "zod"; | ||
|
||
const createBulkInventoriesRequest = z.object({ |
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.
This could be moved to our validations.
Description by Korbit AI
What change is being made?
Implement a new API endpoint for bulk inventory creation aimed at admin users, incorporate priority handling for data sources, refactor DataSourceService to improve code reusability, and update the database schema to include a priority column in the DataSourceI18n model.
Why are these changes being made?
These changes enhance the system's functionality by allowing administrators to efficiently create multiple inventories at once, automatically determining the best data sources based on priority. The refactoring in DataSourceService improves code organization and maintainability, promoting future scalability, while the database schema update supports priority sorting for more precise data sourcing.