38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
'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 { uuid, buildID } = body;
|
|
try {
|
|
const client = new GraphQLClient(endpoint);
|
|
const query = gql`
|
|
query GetLivingSpaceDetail($uuid: String!, $buildID: String!) {
|
|
getLivingSpaceDetail(uuid: $uuid, buildID: $buildID) {
|
|
_id
|
|
company {_id}
|
|
userType {_id}
|
|
build {_id}
|
|
person {_id}
|
|
part {_id}
|
|
}
|
|
}
|
|
`;
|
|
const variables = { uuid, buildID };
|
|
const data = await client.request(query, variables);
|
|
if (!data?.getLivingSpaceDetail) { return NextResponse.json({ error: 'Living space not found' }, { status: 404 }) };
|
|
return NextResponse.json({
|
|
data: {
|
|
_id: data.getLivingSpaceDetail._id, company: data.getLivingSpaceDetail?.company?._id, userType: data.getLivingSpaceDetail.userType._id,
|
|
build: data.getLivingSpaceDetail.build._id, person: data.getLivingSpaceDetail.person._id, part: data.getLivingSpaceDetail.part._id,
|
|
}
|
|
});
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
|
}
|
|
}
|