42 lines
1.3 KiB
TypeScript
42 lines
1.3 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 } = body;
|
|
try {
|
|
const client = new GraphQLClient(endpoint);
|
|
const query = gql`
|
|
query BuildAreas($input: ListArguments!) {
|
|
buildAreas(input: $input) {
|
|
data {
|
|
_id
|
|
uuid
|
|
createdAt
|
|
areaName
|
|
areaCode
|
|
areaType
|
|
areaDirection
|
|
areaGrossSize
|
|
areaNetSize
|
|
width
|
|
size
|
|
expiryStarts
|
|
expiryEnds
|
|
}
|
|
totalCount
|
|
}
|
|
}`;
|
|
const variables = { input: { limit, skip, sort, filters } };
|
|
console.dir({ variables })
|
|
const data = await client.request(query, variables);
|
|
return NextResponse.json({ data: data.buildAreas.data, totalCount: data.buildAreas.totalCount });
|
|
} catch (err: any) {
|
|
console.error(err);
|
|
return NextResponse.json({ error: err.message }, { status: 500 });
|
|
}
|
|
}
|