mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
integrated zod parameter verification into the PUT function for updating the settings on the portfolio settings page
This commit is contained in:
parent
d1352a730c
commit
b33fdfd34b
2 changed files with 27 additions and 2 deletions
|
|
@ -13,15 +13,38 @@ import {
|
||||||
propertyDetailsEpc,
|
propertyDetailsEpc,
|
||||||
property,
|
property,
|
||||||
} from "@/app/db/schema/property";
|
} from "@/app/db/schema/property";
|
||||||
import { eq, inArray } from "drizzle-orm";
|
import { eq, inArray, Name } from "drizzle-orm";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
const UpdateBodySchema = z.object({
|
||||||
|
name: z.optional(z.string()),
|
||||||
|
budget: z.optional(z.number()),
|
||||||
|
goal: z.optional(z.string()),
|
||||||
|
status: z.optional(z.string()),
|
||||||
|
});
|
||||||
|
|
||||||
export async function PUT(
|
export async function PUT(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
{ params }: { params: { portfolioId: string } }
|
{ params }: { params: { portfolioId: string } }
|
||||||
) {
|
) {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
|
let validatedBody;
|
||||||
|
|
||||||
|
try {
|
||||||
|
validatedBody = UpdateBodySchema.parse(body);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Invalid input: ", error);
|
||||||
|
return new NextResponse(JSON.stringify({ msg: "Invalid input" }), {
|
||||||
|
status: 400,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const portfolioId = params.portfolioId;
|
const portfolioId = params.portfolioId;
|
||||||
|
const name = validatedBody.name;
|
||||||
|
const budget = validatedBody.budget;
|
||||||
|
const goal = validatedBody.goal;
|
||||||
|
const status = validatedBody.status;
|
||||||
|
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(portfolio)
|
.update(portfolio)
|
||||||
|
|
@ -43,7 +66,7 @@ export async function DELETE(
|
||||||
|
|
||||||
// 1) Fetch the portfolio ids
|
// 1) Fetch the portfolio ids
|
||||||
// 2) Fetch the recommendation ids
|
// 2) Fetch the recommendation ids
|
||||||
// 3) Delete all entries from RecommendationMaterials for these recommendations
|
// 3) Delete all entries from RecommendationMaterials for these recommendationsP
|
||||||
// 4) Delete all entries from PlanRecommendations that reference plans in the portfolio
|
// 4) Delete all entries from PlanRecommendations that reference plans in the portfolio
|
||||||
// 5) Delete all Plans associated with the portfolio
|
// 5) Delete all Plans associated with the portfolio
|
||||||
// 6) Delete all Scenarios associated with the portfolio
|
// 6) Delete all Scenarios associated with the portfolio
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,8 @@ const updateSettings = async ({
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue