const axios = require('axios'); const BASE_URL = 'https://www.satloccloudfc.com'; const IS_ALIVE = '/api/Satloc/IsAlive'; const AUTH = '/api/Satloc/AuthenticateAPIUser'; const AC_LIST = '/api/Satloc/GetAircraftList'; const AC_LOGS = '/api/Satloc/GetAircraftLogs'; const AC_LOG_DATA = '/api/Satloc/GetAircraftLogData'; const UPLOAD_JOB_DATA = '/api/Satloc/UploadJobData'; const checkApiAlive = async () => { try { const response = await axios(`${BASE_URL}${IS_ALIVE}`); return response.data; } catch (error) { throw new Error(error); } }; async function auth(username, password) { try { const response = await axios(`${BASE_URL}${AUTH}?userLogin=${username}&password=${password}`); return response.data; } catch (error) { throw new Error('Error:', error); } } async function getAircraftList(userId, companyId) { try { const response = await axios(`${BASE_URL}${AC_LIST}?userId=${userId}&companyId=${companyId}`); return response.data; } catch (error) { throw new Error(error); } } async function getAircraftLogs(userId, aircraftId) { try { const response = await axios(`${BASE_URL}${AC_LOGS}?userId=${userId}&aircraftId=${aircraftId}`); return response.data; } catch (error) { throw new Error(error); } } async function getAircraftLogData(userId, logId) { try { const response = await axios(`${BASE_URL}${AC_LOG_DATA}?userId=${userId}&logId=${logId}`); return response.data; } catch (error) { throw new Error(error); } } async function uploadJobData(jobPackage) { try { const response = await axios.post(`${BASE_URL}${UPLOAD_JOB_DATA}`, jobPackage, { headers: { 'Content-Type': 'application/json' } }); return response.data; } catch (error) { throw new Error(error); } } // Helper function to create a JobDataModel function createJobDataModel(aircraftId, jobName, jobData, notes = '') { return { // id: generateGuid(), aircraftId: aircraftId, jobName: jobName, notes: '', //notes, jobData: jobData, // lastModified: new Date().toISOString(), // lastModifiedBy: process.env.USER || 'system', // createdDate: new Date().toISOString(), // createdBy: process.env.USER || 'system' }; } // Helper function to create a JobPackage function createJobPackage(companyId, userId, jobDataList = []) { return { companyId: companyId, userId: userId, jobDataList: jobDataList }; } // Helper function to generate a GUID (simple version) function generateGuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { const r = Math.random() * 16 | 0; const v = c === 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } module.exports = { checkApiAlive, auth, getAircraftList, getAircraftLogs, getAircraftLogData, uploadJobData, createJobDataModel, createJobPackage }