parts and areas tested
This commit is contained in:
45
frontend/app/api/builds-parts/update/route.ts
Normal file
45
frontend/app/api/builds-parts/update/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { UpdateBuildPartsSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const searchUrl = new URL(request.url);
|
||||
const uuid = searchUrl.searchParams.get("uuid") || "";
|
||||
const body = await request.json();
|
||||
const validatedBody = UpdateBuildPartsSchema.parse(body);
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation UpdateBuildPart($uuid:String!, $input: UpdateBuildPartsInput!) {
|
||||
updateBuildPart(uuid: $uuid, input: $input) {
|
||||
_id
|
||||
buildId
|
||||
addressGovCode
|
||||
code
|
||||
directionId
|
||||
expiryEnds
|
||||
expiryStarts
|
||||
grossSize
|
||||
humanLivability
|
||||
isConfirmed
|
||||
key
|
||||
level
|
||||
netSize
|
||||
no
|
||||
active
|
||||
typeId
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { uuid: uuid, input: { ...validatedBody } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateBuildPart, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
frontend/app/api/builds-parts/update/schema.ts
Normal file
24
frontend/app/api/builds-parts/update/schema.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const UpdateBuildPartsSchema = z.object({
|
||||
|
||||
buildId: z.string().optional(),
|
||||
addressGovCode: z.string(),
|
||||
no: z.number(),
|
||||
level: z.number(),
|
||||
code: z.string(),
|
||||
grossSize: z.number(),
|
||||
netSize: z.number(),
|
||||
defaultAccessory: z.string(),
|
||||
humanLivability: z.boolean(),
|
||||
key: z.string(),
|
||||
directionId: z.string().optional(),
|
||||
typeId: z.string().optional(),
|
||||
active: z.boolean(),
|
||||
isConfirmed: z.boolean(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional()
|
||||
|
||||
});
|
||||
|
||||
export type UpdateBuildParts = z.infer<typeof UpdateBuildPartsSchema>;
|
||||
Reference in New Issue
Block a user