evyos-frontend-development/frontend/app/api/living-space/list/route.ts

60 lines
2.1 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 { limit, skip, sort, filters, buildID } = body;
try {
const client = new GraphQLClient(endpoint);
const query = gql`
query GetLivingSpaces($buildID: String!, $input: ListArguments!) {
getLivingSpaces(buildID: $buildID, input: $input) {
data {
_id
uuid
createdAt
updatedAt
expiryStarts
expiryEnds
build {
info {
buildName
buildNo
}
}
part {
no
level
humanLivability
}
person {
firstName
middleName
surname
birthDate
birthPlace
}
userType {
isProperty
description
}
company {
uuid
}
}
totalCount
}
}
`;
const variables = { input: { limit, skip, sort, filters }, buildID };
const data = await client.request(query, variables);
return NextResponse.json({ data: data.getLivingSpaces.data, totalCount: data.getLivingSpaces.totalCount });
} catch (err: any) {
console.error(err);
return NextResponse.json({ error: err.message }, { status: 500 });
}
}