Skip to main content

Overview

The Daily Record Service manages daily health and wellness records for users in the CicloVital application. It provides complete CRUD operations for tracking user daily activities, symptoms, and health metrics.

API Configuration

The service uses environment-based API URL configuration:
const isProd = import.meta.env.VITE_PROD === 'true';
const API_URL = isProd 
  ? import.meta.env.VITE_URL_API_DAILY_RECORD 
  : import.meta.env.VITE_URL_API_LOCAL_DAILY_RECORD;

Functions

getDailyRecordsByUserID

Retrieves all daily records for a specific user.
export const getDailyRecordsByUserID = async (userId) => {
  // Implementation
}
userId
string
required
The unique identifier of the user whose daily records to retrieve
response
object
Response object with daily records dataSuccess Response:
{
  ok: true,
  data: response.data // Array of daily record objects
}
Error Response:
{
  ok: false,
  messageError: string // Error message from server or default error
}
HTTP Method: GET
Endpoint: {API_URL}/usuario/{userId}

Example Usage

import { getDailyRecordsByUserID } from '@/services/dailyRecordService';

const userId = 'user123';
const result = await getDailyRecordsByUserID(userId);

if (result.ok) {
  console.log('Daily records:', result.data);
  result.data.forEach(record => {
    console.log(`Date: ${record.date}, Mood: ${record.mood}`);
  });
} else {
  console.error('Error fetching records:', result.messageError);
}

createDailyRecordService

Creates a new daily record entry.
export const createDailyRecordService = async (recordData) => {
  // Implementation
}
recordData
object
required
Daily record data to createStructure:
  • User ID
  • Date of the record
  • Health metrics (mood, symptoms, activities, etc.)
  • Any additional tracking data
response
object
Response object with created record dataSuccess Response:
{
  ok: true,
  data: response.data // Created record object with ID
}
Error Response:
{
  ok: false,
  messageError: string // Error message from server or default error
}
HTTP Method: POST
Endpoint: {API_URL}

Example Usage

import { createDailyRecordService } from '@/services/dailyRecordService';

const newRecord = {
  userId: 'user123',
  date: '2026-03-09',
  mood: 'good',
  symptoms: ['fatigue'],
  activities: ['exercise', 'meditation'],
  notes: 'Feeling energetic today'
};

const result = await createDailyRecordService(newRecord);

if (result.ok) {
  console.log('Record created:', result.data);
  const recordId = result.data.id;
} else {
  console.error('Error creating record:', result.messageError);
}

deleteDailyRecordService

Deletes a specific daily record.
export const deleteDailyRecordService = async (recordId) => {
  // Implementation
}
recordId
string
required
The unique identifier of the daily record to delete
response
object
Response object with deletion statusSuccess Response:
{
  ok: true,
  data: response.data // Confirmation message
}
Error Response:
{
  ok: false,
  messageError: string // Error message from server or default error
}
HTTP Method: DELETE
Endpoint: {API_URL}/eliminar/{recordId}

Example Usage

import { deleteDailyRecordService } from '@/services/dailyRecordService';

const recordId = 'record789';
const result = await deleteDailyRecordService(recordId);

if (result.ok) {
  console.log('Record deleted successfully:', result.data);
} else {
  console.error('Error deleting record:', result.messageError);
}

updateDailyRecordService

Updates an existing daily record.
export const updateDailyRecordService = async (recordId, recordData) => {
  // Implementation
}
recordId
string
required
The unique identifier of the daily record to update
recordData
object
required
Updated daily record dataStructure:
  • Fields to update (mood, symptoms, activities, notes, etc.)
  • Only includes fields that need to be changed
response
object
Response object with updated record dataSuccess Response:
{
  ok: true,
  data: response.data // Updated record object
}
Error Response:
{
  ok: false,
  messageError: string // Error message from server or default error
}
HTTP Method: PUT
Endpoint: {API_URL}/actualizar/{recordId}

Example Usage

import { updateDailyRecordService } from '@/services/dailyRecordService';

const recordId = 'record789';
const updatedData = {
  mood: 'excellent',
  symptoms: [],
  notes: 'Updated: Feeling much better after rest'
};

const result = await updateDailyRecordService(recordId, updatedData);

if (result.ok) {
  console.log('Record updated:', result.data);
} else {
  console.error('Error updating record:', result.messageError);
}

Error Handling

All service methods use a consistent error handling pattern:
  • Server Errors: Returns error.response?.data if available
  • Connection Errors: Returns default message: 'Error al conectar con el servidor.'
  • Response Format: Always returns { ok: boolean, data/messageError }
  • Debug Logging: Errors are logged to console for debugging

Source Code

Location: src/services/dailyRecordService.js

Build docs developers (and LLMs) love