builds backend initated
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { UpdateBuildAddressSchema } from './schema';
|
||||
import { UpdateBuildIbansSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
@@ -9,29 +9,26 @@ 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 = UpdateBuildAddressSchema.parse(body);
|
||||
const validatedBody = UpdateBuildIbansSchema.parse(body);
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation UpdateBuildAddress($uuid: String!, $input: UpdateBuildAddressInput!) {
|
||||
updateBuildAddress(uuid: $uuid, input: $input) {
|
||||
mutation UpdateBuildIban($uuid:String!,$input: UpdateBuildIbanInput!) {
|
||||
updateBuildIban(uuid: $uuid,input: $input) {
|
||||
_id
|
||||
buildNumber
|
||||
doorNumber
|
||||
floorNumber
|
||||
commentAddress
|
||||
letterAddress
|
||||
shortLetterAddress
|
||||
latitude
|
||||
longitude
|
||||
street
|
||||
uuid
|
||||
xcomment
|
||||
createdAt
|
||||
updatedAt
|
||||
expiryEnds
|
||||
expiryStarts
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { uuid: uuid, input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateBuildAddress, status: 200 });
|
||||
return NextResponse.json({ data: data.updateBuildIban, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const UpdateBuildAddressSchema = z.object({
|
||||
buildNumber: z.string().optional(),
|
||||
doorNumber: z.string().optional(),
|
||||
floorNumber: z.string().optional(),
|
||||
commentAddress: z.string().optional(),
|
||||
letterAddress: z.string().optional(),
|
||||
shortLetterAddress: z.string().optional(),
|
||||
latitude: z.number().optional(),
|
||||
longitude: z.number().optional(),
|
||||
street: z.string().optional(),
|
||||
export const UpdateBuildIbansSchema = z.object({
|
||||
|
||||
iban: z.string().optional(),
|
||||
startDate: z.string().optional(),
|
||||
stopDate: z.string().optional(),
|
||||
bankCode: z.string().optional(),
|
||||
xcomment: z.string().optional(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
|
||||
});
|
||||
|
||||
export type UpdateBuildAddress = z.infer<typeof UpdateBuildAddressSchema>;
|
||||
export type UpdateBuildIbans = z.infer<typeof UpdateBuildIbansSchema>;
|
||||
|
||||
Reference in New Issue
Block a user