updated build add update delete
This commit is contained in:
@@ -19,7 +19,6 @@ export async function POST(request: Request) {
|
||||
typeToken
|
||||
type
|
||||
}
|
||||
collectionToken
|
||||
info {
|
||||
govAddressCode
|
||||
buildName
|
||||
|
||||
@@ -2,7 +2,6 @@ import { z } from "zod"
|
||||
|
||||
export const buildTypesAddSchema = z.object({
|
||||
buildType: z.string(),
|
||||
collectionToken: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function GET(request: Request) {
|
||||
const query = gql`mutation DeleteBuild($uuid: String!) { deleteBuild(uuid: $uuid) }`;
|
||||
const variables = { uuid: uuid };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.deletePerson, status: 200 });
|
||||
return NextResponse.json({ data: data.deleteBuild, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
|
||||
@@ -14,10 +14,10 @@ export async function POST(request: Request) {
|
||||
builds(input: $input) {
|
||||
data {
|
||||
_id
|
||||
collectionToken
|
||||
createdAt
|
||||
updatedAt
|
||||
buildType {
|
||||
_id
|
||||
token
|
||||
typeToken
|
||||
type
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { personUpdateSchema } from './schema';
|
||||
import { buildUpdateSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
@@ -9,17 +9,23 @@ 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 = personUpdateSchema.parse(body);
|
||||
const validatedBody = buildUpdateSchema.parse(body);
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation UpdateBuildType($uuid: String!, $input: UpdateBuildTypesInput!) {
|
||||
updateBuildType(uuid: $uuid, input: $input) {
|
||||
type
|
||||
token
|
||||
typeToken
|
||||
description
|
||||
mutation UpdateBuild($uuid: String!, $input: UpdateBuildInput!) {
|
||||
updateBuild(uuid: $uuid, input: $input) {
|
||||
buildType {
|
||||
_id
|
||||
}
|
||||
info {
|
||||
govAddressCode
|
||||
buildName
|
||||
buildNo
|
||||
maxFloor
|
||||
undergroundFloor
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const personUpdateSchema = z.object({
|
||||
firstName: z.string().optional(),
|
||||
surname: z.string().optional(),
|
||||
middleName: z.string().optional(),
|
||||
sexCode: z.string().optional(),
|
||||
personRef: z.string().optional(),
|
||||
personTag: z.string().optional(),
|
||||
fatherName: z.string().optional(),
|
||||
motherName: z.string().optional(),
|
||||
countryCode: z.string().optional(),
|
||||
nationalIdentityId: z.string().optional(),
|
||||
birthPlace: z.string().optional(),
|
||||
birthDate: z.string().optional(),
|
||||
taxNo: z.string().optional().optional(),
|
||||
birthname: z.string().optional().optional(),
|
||||
expiryStarts: z.string().optional().optional(),
|
||||
expiryEnds: z.string().optional().optional(),
|
||||
export const buildUpdateSchema = z.object({
|
||||
buildType: z.string(),
|
||||
info: z.object({
|
||||
govAddressCode: z.string(),
|
||||
buildName: z.string(),
|
||||
buildNo: z.string(),
|
||||
maxFloor: z.number(),
|
||||
undergroundFloor: z.number(),
|
||||
buildDate: z.string(),
|
||||
decisionPeriodDate: z.string(),
|
||||
taxNo: z.string(),
|
||||
liftCount: z.number(),
|
||||
heatingSystem: z.boolean(),
|
||||
coolingSystem: z.boolean(),
|
||||
hotWaterSystem: z.boolean(),
|
||||
blockServiceManCount: z.number(),
|
||||
securityServiceManCount: z.number(),
|
||||
garageCount: z.number(),
|
||||
managementRoomId: z.string().optional(),
|
||||
})
|
||||
// expiryStarts: z.string().optional(),
|
||||
// expiryEnds: z.string().optional(),
|
||||
});
|
||||
|
||||
export type PeopleUpdate = z.infer<typeof personUpdateSchema>;
|
||||
export type BuildUpdate = z.infer<typeof buildUpdateSchema>;
|
||||
|
||||
Reference in New Issue
Block a user