build-address added tested
This commit is contained in:
36
frontend/app/api/build-address/add/route.ts
Normal file
36
frontend/app/api/build-address/add/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { buildTypesAddSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = buildTypesAddSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation CreateBuildAddress($input: CreateBuildAddressInput!) {
|
||||
createBuildAddress(input: $input) {
|
||||
_id
|
||||
buildNumber
|
||||
doorNumber
|
||||
floorNumber
|
||||
commentAddress
|
||||
letterAddress
|
||||
shortLetterAddress
|
||||
latitude
|
||||
longitude
|
||||
street
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createBuildAddress, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
15
frontend/app/api/build-address/add/schema.ts
Normal file
15
frontend/app/api/build-address/add/schema.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildTypesAddSchema = z.object({
|
||||
buildNumber: z.string(),
|
||||
doorNumber: z.string(),
|
||||
floorNumber: z.string(),
|
||||
commentAddress: z.string(),
|
||||
letterAddress: z.string(),
|
||||
shortLetterAddress: z.string(),
|
||||
latitude: z.number(),
|
||||
longitude: z.number(),
|
||||
street: z.string().optional(),
|
||||
});
|
||||
|
||||
export type BuildTypesAdd = z.infer<typeof buildTypesAddSchema>;
|
||||
23
frontend/app/api/build-address/delete/route.ts
Normal file
23
frontend/app/api/build-address/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 DeleteBuildAddress($uuid: String!) { deleteBuildAddress(uuid: $uuid) }`;
|
||||
const variables = { uuid: uuid };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.deleteBuildAddress, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
43
frontend/app/api/build-address/list/route.ts
Normal file
43
frontend/app/api/build-address/list/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
'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 GetBuildAddresses($input: ListArguments!) {
|
||||
buildAddresses(input: $input) {
|
||||
totalCount
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
buildNumber
|
||||
doorNumber
|
||||
floorNumber
|
||||
commentAddress
|
||||
letterAddress
|
||||
shortLetterAddress
|
||||
latitude
|
||||
longitude
|
||||
street
|
||||
createdAt
|
||||
updatedAt
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
console.dir({ variables })
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.buildAddresses.data, totalCount: data.buildAddresses.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
39
frontend/app/api/build-address/update/route.ts
Normal file
39
frontend/app/api/build-address/update/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { UpdateBuildAddressSchema } 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 = UpdateBuildAddressSchema.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) {
|
||||
_id
|
||||
buildNumber
|
||||
doorNumber
|
||||
floorNumber
|
||||
commentAddress
|
||||
letterAddress
|
||||
shortLetterAddress
|
||||
latitude
|
||||
longitude
|
||||
street
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { uuid: uuid, input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateBuildAddress, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
15
frontend/app/api/build-address/update/schema.ts
Normal file
15
frontend/app/api/build-address/update/schema.ts
Normal file
@@ -0,0 +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 type UpdateBuildAddress = z.infer<typeof UpdateBuildAddressSchema>;
|
||||
30
frontend/app/api/build-types/add/route.ts
Normal file
30
frontend/app/api/build-types/add/route.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { buildTypesAddSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = buildTypesAddSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation CreateBuildType($input: CreateBuildTypesInput!) {
|
||||
createBuildType(input: $input) {
|
||||
type
|
||||
token
|
||||
typeToken
|
||||
description
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createBuildType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
10
frontend/app/api/build-types/add/schema.ts
Normal file
10
frontend/app/api/build-types/add/schema.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const buildTypesAddSchema = z.object({
|
||||
type: z.string(),
|
||||
token: z.string(),
|
||||
typeToken: z.string(),
|
||||
description: z.string().optional().default(''),
|
||||
});
|
||||
|
||||
export type BuildTypesAdd = z.infer<typeof buildTypesAddSchema>;
|
||||
23
frontend/app/api/build-types/delete/route.ts
Normal file
23
frontend/app/api/build-types/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 DeletePerson($uuid: String!) { deletePerson(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 });
|
||||
}
|
||||
|
||||
}
|
||||
37
frontend/app/api/build-types/list/route.ts
Normal file
37
frontend/app/api/build-types/list/route.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
'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 GetBuildTypes($input: ListArguments!) {
|
||||
buildTypes(input: $input) {
|
||||
totalCount
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
type
|
||||
token
|
||||
typeToken
|
||||
description
|
||||
createdAt
|
||||
updatedAt
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
}
|
||||
}
|
||||
}`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.buildTypes.data, totalCount: data.buildTypes.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
33
frontend/app/api/build-types/update/route.ts
Normal file
33
frontend/app/api/build-types/update/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { personUpdateSchema } 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 = personUpdateSchema.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
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { uuid: uuid, input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateBuildType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
22
frontend/app/api/build-types/update/schema.ts
Normal file
22
frontend/app/api/build-types/update/schema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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 type PeopleUpdate = z.infer<typeof personUpdateSchema>;
|
||||
39
frontend/app/api/people/add/route.ts
Normal file
39
frontend/app/api/people/add/route.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { personAddSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = personAddSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation CreatePerson($input: CreatePersonInput!) {
|
||||
createPerson(input: $input) {
|
||||
uuid
|
||||
firstName
|
||||
surname
|
||||
birthDate
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createPerson, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// export async function POST(request: Request) {
|
||||
|
||||
// const body = await request.json();
|
||||
// const validatedBody = userAddSchema.parse(body);
|
||||
// console.log("VALIDATED")
|
||||
// console.dir({ validatedBody })
|
||||
// return NextResponse.json({ data: validatedBody })
|
||||
// }
|
||||
22
frontend/app/api/people/add/schema.ts
Normal file
22
frontend/app/api/people/add/schema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const personAddSchema = z.object({
|
||||
firstName: z.string(),
|
||||
surname: z.string(),
|
||||
middleName: z.string().optional(),
|
||||
sexCode: z.string(),
|
||||
personRef: z.string().optional(),
|
||||
personTag: z.string().optional(),
|
||||
fatherName: z.string().optional(),
|
||||
motherName: z.string().optional(),
|
||||
countryCode: z.string(),
|
||||
nationalIdentityId: z.string(),
|
||||
birthPlace: z.string(),
|
||||
birthDate: z.string(),
|
||||
taxNo: z.string().optional(),
|
||||
birthname: z.string().optional(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
});
|
||||
|
||||
export type PeopleAdd = z.infer<typeof personAddSchema>;
|
||||
23
frontend/app/api/people/delete/route.ts
Normal file
23
frontend/app/api/people/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 DeletePerson($uuid: String!) { deletePerson(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 });
|
||||
}
|
||||
|
||||
}
|
||||
48
frontend/app/api/people/list/route.ts
Normal file
48
frontend/app/api/people/list/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
'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 GetPeople($input: ListArguments!) {
|
||||
people(input: $input) {
|
||||
totalCount
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
firstName
|
||||
surname
|
||||
middleName
|
||||
sexCode
|
||||
personRef
|
||||
personTag
|
||||
fatherName
|
||||
motherName
|
||||
countryCode
|
||||
nationalIdentityId
|
||||
birthPlace
|
||||
birthDate
|
||||
taxNo
|
||||
birthname
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.people.data, totalCount: data.people.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
34
frontend/app/api/people/update/route.ts
Normal file
34
frontend/app/api/people/update/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { personUpdateSchema } 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 = personUpdateSchema.parse(body);
|
||||
console.dir({ validatedBody });
|
||||
if (uuid === "") { return NextResponse.json({ error: "UUID is required" }, { status: 400 }) }
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`
|
||||
mutation updatePerson($uuid: String! $input: UpdatePersonInput!) {
|
||||
updatePerson(uuid: $uuid, input: $input) {
|
||||
uuid
|
||||
firstName
|
||||
surname
|
||||
sexCode
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { uuid: uuid, input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updatePerson, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
22
frontend/app/api/people/update/schema.ts
Normal file
22
frontend/app/api/people/update/schema.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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 type PeopleUpdate = z.infer<typeof personUpdateSchema>;
|
||||
Reference in New Issue
Block a user