parts and areas tested
This commit is contained in:
38
frontend/app/api/builds-parts/add/route.ts
Normal file
38
frontend/app/api/builds-parts/add/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { buildPartsAddSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = buildPartsAddSchema.parse({ ...body.data, buildId: body.buildId });
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation CreateBuildParts($input: CreateBuildPartsInput!) {
|
||||
createBuildPart(input: $input) {
|
||||
buildId
|
||||
addressGovCode
|
||||
level
|
||||
no
|
||||
code
|
||||
grossSize
|
||||
netSize
|
||||
defaultAccessory
|
||||
humanLivability
|
||||
key
|
||||
directionId
|
||||
typeId
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createBuildPart, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
23
frontend/app/api/builds-parts/add/schema.ts
Normal file
23
frontend/app/api/builds-parts/add/schema.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildPartsAddSchema = z.object({
|
||||
buildId: z.string(),
|
||||
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().default(true),
|
||||
isConfirmed: z.boolean().default(false),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional()
|
||||
|
||||
});
|
||||
|
||||
export type BuildPartsAdd = z.infer<typeof buildPartsAddSchema>;
|
||||
23
frontend/app/api/builds-parts/delete/route.ts
Normal file
23
frontend/app/api/builds-parts/delete/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
|
||||
const searchParams = new URL(request.url).searchParams;
|
||||
const uuid = searchParams.get('uuid');
|
||||
if (!uuid) { return NextResponse.json({ error: 'UUID not found in search params' }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation DeleteBuildPart($uuid: String!) { deleteBuildPart(uuid: $uuid) }`;
|
||||
const variables = { uuid: uuid };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.deletePerson, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
47
frontend/app/api/builds-parts/list/route.ts
Normal file
47
frontend/app/api/builds-parts/list/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const { limit, skip, sort, filters } = body;
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
query BuildParts($input: ListArguments!) {
|
||||
buildParts(input: $input) {
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
addressGovCode
|
||||
no
|
||||
level
|
||||
code
|
||||
grossSize
|
||||
netSize
|
||||
defaultAccessory
|
||||
humanLivability
|
||||
key
|
||||
directionId
|
||||
typeId
|
||||
createdAt
|
||||
updatedAt
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
active
|
||||
isConfirmed
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.buildParts.data, totalCount: data.buildParts.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
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