Home Reference Source

src/database/ActivitiesDAO.js

import activities from './Activities';

/**
 * Returns the activity picture
 * @param {number} activityId - id of activity
 * @returns {Object} the picture from the activity object
 */
function getPicture(activityId) {
    return getActivity(activityId).picture;
}

/**
 * Returns the activity name
 * @param {number} activityId - id of activity
 * @returns {string} name of activity
 */
function getName(activityId) {
    return getActivity(activityId).name;
}

/**
 * Return all activites
 * @returns {Object[]} the activites
 */
function getAllActivites() {
    return activities;
}

/**
 * Returns activity with given id
 * @param {number} activityId - the id of the activity
 * @returns {Object} the activity
 */
function getActivity(activityId) {
    return activities.find(e => e.id === activityId);
}

/**
 * Returns question with given questoinIdd from activity with given activityId
 * @param {number} activityId - the id of the activity
 * @param {number} questionId - the id of the question
 * @returns {Object} the question object
 */
function getQuestion(activityId, questionId) {
    return getActivity(activityId).questions.find(q => q.id === questionId);
}

export {getAllActivites, getPicture, getActivity, getName, getQuestion};