mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Changed validation of body structure
This commit is contained in:
parent
2775d732e7
commit
50498afc3f
1 changed files with 13 additions and 4 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { user } from "@/app/db/schema/users";
|
||||
import S3 from "aws-sdk/clients/s3";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
|
|
@ -18,11 +17,18 @@ export async function GET(request: NextRequest) {
|
|||
// For the moment, this api specifically handles uploads of csvs
|
||||
|
||||
const body = await request.json();
|
||||
let validatedBody;
|
||||
|
||||
try {
|
||||
const validatedBody = PresignedUrlBodySchema.parse(body);
|
||||
const { userId, portfolioId } = validatedBody;
|
||||
validatedBody = PresignedUrlBodySchema.parse(body);
|
||||
} catch (error) {
|
||||
console.error("Invalid input: ", error);
|
||||
return new NextResponse(JSON.stringify({ msg: "Invalid input" }), {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const s3 = new S3({
|
||||
signatureVersion: "v4",
|
||||
region: process.env.PRESIGN_AWS_REGION,
|
||||
|
|
@ -30,6 +36,7 @@ export async function GET(request: NextRequest) {
|
|||
secretAccessKey: process.env.PRESIGN_AWS_SECRET_KEY,
|
||||
});
|
||||
|
||||
const { userId, portfolioId } = validatedBody;
|
||||
const fileKey = generateS3Key(
|
||||
userId,
|
||||
portfolioId,
|
||||
|
|
@ -49,6 +56,8 @@ export async function GET(request: NextRequest) {
|
|||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error;
|
||||
return new NextResponse(JSON.stringify({ msg: "Insternal server error" }), {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue