UNPKG

@olavarriaga/n8n-nodes-myfitnesspal

Version:
321 lines 13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Health = void 0; class Health { constructor() { this.description = { displayName: 'MyFitnessPal', name: 'myFitnessPal', icon: 'file:health.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"]}}', description: 'Interact with MyFitnessPal API', defaults: { name: 'MyFitnessPal', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'myFitnessPalApi', required: true, testedBy: 'testMyFitnessPalApiAuth', }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, default: 'searchFoods', options: [ { name: 'Get Food Item', value: 'getFoodItem', description: 'Get details about a specific food item', action: 'Get a food item', }, { name: 'Search Foods', value: 'searchFoods', description: 'Search for food items in the database', action: 'Search for food items', }, { name: 'Get Diary', value: 'getDiary', description: 'Get user diary entries for a specific date', action: 'Get diary entries', }, { name: 'Add Food to Diary', value: 'addFoodToDiary', description: 'Add a food item to user diary', action: 'Add food to diary', }, { name: 'Get Exercise', value: 'getExercise', description: 'Get exercise information for a specific date', action: 'Get exercise information', }, { name: 'Add Exercise', value: 'addExercise', description: 'Add an exercise entry to diary', action: 'Add exercise entry', }, { name: 'Get User Profile', value: 'getUserProfile', description: 'Get user profile information and preferences', action: 'Get user profile', }, ], }, { displayName: 'Search Query', name: 'query', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['searchFoods'], }, }, placeholder: 'chicken breast', description: 'Search term for finding food items in the database', }, { displayName: 'Max Results', name: 'maxResults', type: 'number', default: 10, description: 'Maximum number of results to return (max: 50)', displayOptions: { show: { operation: ['searchFoods'], }, }, }, { displayName: 'Food Item ID', name: 'foodItemId', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['getFoodItem'], }, }, description: 'Unique identifier of the food item to retrieve', }, { displayName: 'Date', name: 'date', type: 'dateTime', default: '', required: true, displayOptions: { show: { operation: ['getDiary', 'getExercise'], }, }, description: 'Date to retrieve entries for (Format: YYYY-MM-DD)', }, { displayName: 'Food Item ID', name: 'foodItemId', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['addFoodToDiary'], }, }, description: 'ID of the food item to add to the diary', }, { displayName: 'Meal Type', name: 'mealType', type: 'options', options: [ { name: 'Breakfast', value: 'breakfast', description: 'Morning meal', }, { name: 'Lunch', value: 'lunch', description: 'Midday meal', }, { name: 'Dinner', value: 'dinner', description: 'Evening meal', }, { name: 'Snacks', value: 'snacks', description: 'Between-meal snacks', }, ], default: 'breakfast', required: true, displayOptions: { show: { operation: ['addFoodToDiary'], }, }, description: 'Type of meal this food entry belongs to', }, { displayName: 'Serving Size', name: 'servingSize', type: 'number', default: 1, required: true, displayOptions: { show: { operation: ['addFoodToDiary'], }, }, description: 'Number of servings of the food item', }, { displayName: 'Exercise Name', name: 'exerciseName', type: 'string', default: '', required: true, displayOptions: { show: { operation: ['addExercise'], }, }, placeholder: 'Running', description: 'Name of the exercise activity', }, { displayName: 'Duration', name: 'duration', type: 'number', default: 30, required: true, displayOptions: { show: { operation: ['addExercise'], }, }, description: 'Duration of exercise in minutes', }, { displayName: 'Calories Burned', name: 'caloriesBurned', type: 'number', default: 0, required: true, displayOptions: { show: { operation: ['addExercise'], }, }, description: 'Number of calories burned during the exercise', }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { let responseData = {}; const qs = {}; let requestMethod = 'GET'; let endpoint = ''; let body = {}; if (operation === 'searchFoods') { const query = this.getNodeParameter('query', i); const maxResults = this.getNodeParameter('maxResults', i); endpoint = '/foods/search'; qs.q = query; qs.max_results = maxResults; } else if (operation === 'getFoodItem') { const foodItemId = this.getNodeParameter('foodItemId', i); endpoint = `/foods/${foodItemId}`; } else if (operation === 'getDiary') { const date = this.getNodeParameter('date', i); endpoint = '/diary'; qs.date = date; } else if (operation === 'addFoodToDiary') { requestMethod = 'POST'; const foodItemId = this.getNodeParameter('foodItemId', i); const mealType = this.getNodeParameter('mealType', i); const servingSize = this.getNodeParameter('servingSize', i); endpoint = '/diary/add'; body = { food_id: foodItemId, meal_type: mealType, serving_size: servingSize, }; } else if (operation === 'getExercise') { const date = this.getNodeParameter('date', i); endpoint = '/exercise'; qs.date = date; } else if (operation === 'addExercise') { requestMethod = 'POST'; const exerciseName = this.getNodeParameter('exerciseName', i); const duration = this.getNodeParameter('duration', i); const caloriesBurned = this.getNodeParameter('caloriesBurned', i); endpoint = '/exercise/add'; body = { name: exerciseName, duration, calories_burned: caloriesBurned, }; } else if (operation === 'getUserProfile') { endpoint = '/user/profile'; } const options = { method: requestMethod, qs, body, url: `https://api.myfitnesspal.com/v2${endpoint}`, json: true, }; responseData = await this.helpers.requestWithAuthentication.call(this, 'myFitnessPalApi', options); returnData.push({ json: responseData, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw error; } } return [returnData]; } } exports.Health = Health; //# sourceMappingURL=Health.node.js.map