mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
udpated structure of create portfolio api
This commit is contained in:
parent
50498afc3f
commit
6624690f39
1 changed files with 13 additions and 2 deletions
|
|
@ -20,9 +20,18 @@ const createPortfolioSchema = z.object({
|
|||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
let validatedBody;
|
||||
|
||||
try {
|
||||
validatedBody = createPortfolioSchema.parse(body);
|
||||
} catch (error) {
|
||||
console.error("Invalid input: ", error);
|
||||
return new NextResponse(JSON.stringify({ msg: "Invalid input" }), {
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const validatedBody = createPortfolioSchema.parse(body);
|
||||
const { userId, portfolioName, budget, goal, status, role } = validatedBody;
|
||||
|
||||
const creationDate = new Date();
|
||||
|
|
@ -52,6 +61,8 @@ export async function POST(request: NextRequest) {
|
|||
return new NextResponse(JSON.stringify(response[0]), { status: 201 });
|
||||
} 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