Files
tilbudgivern/archive/test-files/test-custom-task.js
T
2025-10-30 18:28:58 +00:00

87 lines
3.0 KiB
JavaScript

const fetch = require('node-fetch');
async function testCustomTask() {
try {
// Find først en pakke
const packagesRes = await fetch('http://localhost:5001/api/smart-packages?limit=1');
const packagesData = await packagesRes.json();
if (!packagesData.success || packagesData.packages.length === 0) {
console.log('❌ Ingen pakker fundet');
return;
}
const packageId = packagesData.packages[0].id;
console.log('📦 Bruger pakke:', packagesData.packages[0].name, `(ID: ${packageId})`);
// Opret custom task: Lægter opsætning
const taskData = {
packageId: packageId,
name: 'Opsætning af lægter',
description: 'Præcis montage af lægter med korrekt afstand (cc 370mm). Inkluderer skruearbejde og kontrol af vaterpas.',
timeUnit: 'per_meter',
timePerUnit: 0.17, // 10 minutter pr. løbende meter
hourlyRate: 580,
materialVarenr: '147072',
tools: ['skruemaskine', 'vaterpas', 'målebånd', 'snor'],
skills: ['tømrerarbejde', 'præcision']
};
console.log('\n🔨 Opretter custom task:', taskData.name);
console.log(' Enhed:', taskData.timeUnit);
console.log(' Tid:', (taskData.timePerUnit * 60).toFixed(0), 'min pr. enhed');
console.log(' Materialevarenr:', taskData.materialVarenr);
const response = await fetch('http://localhost:5001/api/smart-packages/custom-tasks', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(taskData)
});
const result = await response.json();
if (result.success) {
console.log('\n✅', result.message);
console.log(' Task ID:', result.taskId);
console.log(' Order:', result.order);
// Hent custom tasks
console.log('\n📋 Henter alle custom tasks...');
const customTasksRes = await fetch('http://localhost:5001/api/smart-packages/custom-tasks');
const customTasksData = await customTasksRes.json();
if (customTasksData.success) {
console.log(`\n Fundet ${customTasksData.count} custom tasks:`);
customTasksData.tasks.forEach(task => {
console.log(` - ${task.name} (${task.time_display})`);
});
}
// Test view
console.log('\n🔍 Henter fra custom_installation_tasks view...');
const mysql = require('mysql2/promise');
const conn = await mysql.createConnection({
host: '127.0.0.1',
user: 'tilbudgivern_service',
password: 'REDACTED_PASSWORD',
database: 'tilbudgivern'
});
const [viewRows] = await conn.execute('SELECT * FROM custom_installation_tasks LIMIT 5');
console.log(`\n View returnerer ${viewRows.length} rækker`);
viewRows.forEach(row => {
console.log(` - ${row.task_name}: ${row.time_display}`);
});
await conn.end();
} else {
console.log('\n❌ Fejl:', result.error);
}
} catch (error) {
console.error('❌ Exception:', error.message);
}
}
testCustomTask();