user type graphql added
This commit is contained in:
0
frontend/app/api/living-space/a.txt
Normal file
0
frontend/app/api/living-space/a.txt
Normal file
21
frontend/app/api/user-types/add/route.ts
Normal file
21
frontend/app/api/user-types/add/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
'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 CreateUserType($input: CreateUserTypesInput!) { createUserType(input: $input) { _id }}`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createUserType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
23
frontend/app/api/user-types/add/schema.ts
Normal file
23
frontend/app/api/user-types/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/user-types/delete/route.ts
Normal file
23
frontend/app/api/user-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 DeleteUserType($uuid: String!) { deleteUserType(uuid: $uuid) }`;
|
||||
const variables = { uuid: uuid };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.deleteUserType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
|
||||
}
|
||||
38
frontend/app/api/user-types/list/route.ts
Normal file
38
frontend/app/api/user-types/list/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
'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 GetUserTypes($input: ListArguments!) {
|
||||
getUserTypes(input: $input) {
|
||||
data {
|
||||
_id
|
||||
uuid
|
||||
createdAt
|
||||
expiryStarts
|
||||
expiryEnds
|
||||
type
|
||||
token
|
||||
typeToken
|
||||
description
|
||||
isProperty
|
||||
}
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
`;
|
||||
const variables = { input: { limit, skip, sort, filters } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.getUserTypes.data, totalCount: data.getUserTypes.totalCount });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
frontend/app/api/user-types/update/route.ts
Normal file
24
frontend/app/api/user-types/update/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'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 UpdateUserType($uuid: String!, $input: UpdateUserTypeInput!) { updateUserType(uuid: $uuid, input: $input) { _id } }`;
|
||||
const variables = { uuid: uuid, input: { ...validatedBody } };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.updateUserType, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
24
frontend/app/api/user-types/update/schema.ts
Normal file
24
frontend/app/api/user-types/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>;
|
||||
5
frontend/app/living-spaces/page.tsx
Normal file
5
frontend/app/living-spaces/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PageLivingSpace } from "@/pages/living-space/tables/page"
|
||||
|
||||
const SSRPageLivingSpace = () => { return <><PageLivingSpace /></> }
|
||||
|
||||
export default SSRPageLivingSpace;
|
||||
5
frontend/app/user-types/add/page.tsx
Normal file
5
frontend/app/user-types/add/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PageAddUserTypes } from "@/pages/user-types/add/page";
|
||||
|
||||
const UserTypesAddPage = () => { return <PageAddUserTypes /> }
|
||||
|
||||
export default UserTypesAddPage;
|
||||
5
frontend/app/user-types/page.tsx
Normal file
5
frontend/app/user-types/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PageUserTypes } from '@/pages/user-types/page';
|
||||
|
||||
const UserTypesPage = () => { return <PageUserTypes /> }
|
||||
|
||||
export default UserTypesPage;
|
||||
5
frontend/app/user-types/update/page.tsx
Normal file
5
frontend/app/user-types/update/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { PageUpdateUserTypes } from "@/pages/user-types/update/page";
|
||||
|
||||
const UserTypesUpdatePage = () => { return <><PageUpdateUserTypes /></> }
|
||||
|
||||
export default UserTypesUpdatePage;
|
||||
Reference in New Issue
Block a user