-
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?
Changes from all commits
91a7f84
f72ad28
4ee998e
f92b0be
df313ae
7e308e3
06d415e
4d24fe7
6c8bb82
ada877f
22d93c2
61b0769
6df8c7c
ca6558d
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.addColumn("DataSourceI18n", "priority", { | ||
type: Sequelize.DOUBLE, | ||
nullable: true, | ||
}); | ||
}, | ||
|
||
async down(queryInterface) { | ||
await queryInterface.removeColumn("DataSourceI18n", "priority"); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import AdminService from "@/backend/AdminService"; | ||
import { apiHandler } from "@/util/api"; | ||
import { NextResponse } from "next/server"; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Insufficient Locode Format Validation
Tell me moreWhat is the issue?The cityLocodes validation accepts any string without validating if it's a proper locode format. Why this mattersInvalid locode formats could cause downstream processing issues or data inconsistencies in the inventory creation process. Suggested change ∙ Feature PreviewAdd 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. |
||
emails: z.array(z.string().email()), // Comma separated list of emails to invite to the all of the created inventories | ||
years: z.array(z.number().int().positive()), // List of years to create inventories for (can be comma separated input, multiple select dropdown etc., so multiple years can be chosen) | ||
scope: z.enum(["gpc_basic", "gpc_basic_plus"]), // Scope selection (gpc_basic or gpc_basic_plus) | ||
gwp: z.enum(["AR5", "AR6"]), // GWP selection (AR5 or AR6) | ||
}); | ||
|
||
export const POST = apiHandler(async (req, { session }) => { | ||
const props = createBulkInventoriesRequest.parse(await req.json()); | ||
lemilonkh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result = await AdminService.createBulkInventories(props, session); | ||
return NextResponse.json(result); | ||
}); |
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.