src/database/ActivityTypesDAO.js
import activityTypes from './ActivityTypes';
/**
* Returns all activity types
* @returns {Object} the activity types
*/
function getAllActivities() {
return activityTypes;
}
/**
* Find the activity type with the specified id
* @param {number} id - the id of the activity
* @returns {Object} the activity with given id
*/
function getActivity(id) {
const activityTypes = getAllActivities();
return activityTypes.find(e => e.id === id);
}
/**
* Returns the name of the activity type
* @param {number} id - the activity id
* @returns {string} the name of the activity
*/
function getName(id) {
return getActivity(id).name;
}
/**
* Returns the picture of the activity type
* @param {number} id - the activity id
* @returns {Object} the picture of the activity
*/
function getPicture(id) {
return getActivity(id).picture;
}
/**
* Gets the filename of activity picture
* @param {number} id - the activity id
* @returns {string} the filename for activity picture
*/
function getFilename(id) {
return getActivity(id).filename;
}
/**
* Returns all questions
* @param {number} id - the activity id
* @returns {string[]} The questions
*/
function getAllQuestions(id) {
return getActivity(id).questions;
}
/**
* Returns the question with the given activity type id and question id
* @param {number} id - the activity id
* @param {number} questionId the id of the question
* @returns {Object} the question with given questinonId from activity with given id
*/
function getQuestion(id, questionId) {
return getActivity(id).questions.find(q => q.id === questionId);
}
/**
* Returns the number of questions
* @param {number} id - the activity id
* @returns {number} the number of questions in activity with given id
*/
function numberOfQuestions(id) {
return getActivity(id).questions.length;
}
export {
getName,
getPicture,
getFilename,
getAllQuestions,
getQuestion,
numberOfQuestions,
};