updated living space
This commit is contained in:
21
frontend/app/api/living-space/add/route.ts
Normal file
21
frontend/app/api/living-space/add/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
'use server';
|
||||
import { NextResponse } from 'next/server';
|
||||
import { GraphQLClient, gql } from 'graphql-request';
|
||||
import { CreateLivingSpaceInputSchema } from './schema';
|
||||
|
||||
const endpoint = "http://localhost:3001/graphql";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json();
|
||||
const validatedBody = CreateLivingSpaceInputSchema.parse(body);
|
||||
try {
|
||||
const client = new GraphQLClient(endpoint);
|
||||
const query = gql`mutation CreateLivingSpace($input: CreateLivingSpaceInput!) { createLivingSpace(input:$input) { _id }}`;
|
||||
const variables = { input: validatedBody };
|
||||
const data = await client.request(query, variables);
|
||||
return NextResponse.json({ data: data.createLivingSpace, status: 200 });
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
14
frontend/app/api/living-space/add/schema.ts
Normal file
14
frontend/app/api/living-space/add/schema.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const CreateLivingSpaceInputSchema = z.object({
|
||||
buildID: z.string(),
|
||||
collectionToken: z.string(),
|
||||
partID: z.string(),
|
||||
userTypeID: z.string(),
|
||||
companyID: z.string(),
|
||||
personID: z.string(),
|
||||
expiryStarts: z.string().optional(),
|
||||
expiryEnds: z.string().optional(),
|
||||
});
|
||||
|
||||
export type CreateLivingSpaceInput = z.infer<typeof CreateLivingSpaceInputSchema>;
|
||||
Reference in New Issue
Block a user