Files
tilbudgivern/archive/test-files/test_planning_calendar_graphql.js
2026-08-13 14:29:15 +02:00

101 lines
2.3 KiB
JavaScript

/**
* Test GraphQL Planning Calendar
*/
const axios = require('axios');
const GRAPHQL_ENDPOINT = 'https://graphql.ordrestyring.dk/graphql';
const API_TOKEN = '<ORDRESTYRING_API_TOKEN>';
async function testPlanningCalendar() {
const now = Math.floor(Date.now() / 1000);
const fourWeeksAgo = now - (28 * 24 * 60 * 60);
const fourWeeksAhead = now + (28 * 24 * 60 * 60);
const query = `
query GetPlanningHours($between: HourBetweenInput!, $pagination: Pagination) {
hours(
between: $between
pagination: $pagination
) {
items {
id
startTime
stopTime
description
user {
id
fullName
}
type {
id
name
}
case {
id
caseNumber
projectName
customer {
id
name
number
}
}
}
nextCursor
}
}
`;
const variables = {
between: {
field: "startTime",
from: fourWeeksAgo,
to: fourWeeksAhead
},
pagination: {
cursor: null,
limit: 100
}
};
try {
console.log('📅 Testing planning calendar GraphQL query...');
console.log('Date range:', new Date(fourWeeksAgo * 1000).toISOString(), 'to', new Date(fourWeeksAhead * 1000).toISOString());
const response = await axios.post(
GRAPHQL_ENDPOINT,
{ query, variables },
{
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
}
}
);
if (response.data.errors) {
console.error('❌ GraphQL Errors:');
response.data.errors.forEach(err => console.error(' -', err.message));
return;
}
const hours = response.data.data.hours.items;
console.log(`✅ Success! Received ${hours.length} hours`);
if (hours.length > 0) {
console.log('\n📊 Sample entry:');
console.log(JSON.stringify(hours[0], null, 2));
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.response?.data?.errors) {
console.error('GraphQL Errors:');
error.response.data.errors.forEach(err => console.error(' -', err.message));
}
}
}
testPlanningCalendar();