Skip to content

Commit

Permalink
feature/booked-dates
Browse files Browse the repository at this point in the history
- add jsdoc
- setup jsdoc and modify files to use jsdoc
  • Loading branch information
Billmike committed Apr 19, 2018
1 parent 14b330a commit 72465ed
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@
"err"
]
}
]
],
"require-jsdoc": ["error", {
"require": {
"ClassDeclaration": true,
"FunctionDeclaration": true,
"ArrowFunctionExpression": true,
"MethodDefinition": true
}
}]
},
"globals": {
"localStorage": true,
Expand Down
55 changes: 54 additions & 1 deletion server/controllers/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ import serverError from '../errorHandler/serverError';
import validateInput from '../validators/validateAddCenter';

const { Center } = db;
const Op = Sequelize.Op;
const { Op } = Sequelize;

/**
* A controller class for handling center actions
*/
class CenterController {
/**
* Create a new center
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static createCenter(request, response) {
const { errors, isValid } = validateInput(request.body);

Expand Down Expand Up @@ -52,6 +63,14 @@ class CenterController {
});
}

/**
* Edit a center in the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static editCenter(request, response) {
return Center.findById(request.params.centerId)
.then((center) => {
Expand Down Expand Up @@ -87,6 +106,14 @@ class CenterController {
});
}

/**
* Delete a center
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static deleteCenter(request, response) {
const { username } = request.userDetails;
Center.findById(request.params.centerId)
Expand Down Expand Up @@ -114,6 +141,14 @@ class CenterController {
});
}

/**
* Fetch all centers
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static getCenters(request, response) {
Center.all()
.then((centers) => {
Expand All @@ -127,6 +162,15 @@ class CenterController {
});
});
}

/**
* Search through the centers
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static searchCenters(request, response) {
const { search } = request.query;
return Center.findAll({
Expand Down Expand Up @@ -156,6 +200,15 @@ class CenterController {
});
});
}

/**
* Fetch one center from the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The center object
*/
static getOneCenter(request, response) {
Center.findById(request.params.centerId)
.then((foundCenter) => {
Expand Down
45 changes: 45 additions & 0 deletions server/controllers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ import validateAddEvent from '../validators/validateAddEvent';

const { Event, Center, User } = db;

/**
* A class controller for handling events actions
*/
class Events {
/**
* Adds an event to the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The event object
*/
static addEvent(request, response) {
const { errors, valid } = validateAddEvent(request.body);
if (!valid) {
Expand Down Expand Up @@ -89,6 +100,14 @@ class Events {
});
}

/**
* Fetch all the events in the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The event object
*/
static getEvents(request, response) {
return Event.findAndCountAll()
.then((allEvents) => {
Expand All @@ -107,6 +126,15 @@ class Events {
});
});
}

/**
* Edit the event in the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The event object
*/
static modifyEvent(request, response) {
Event.findById(request.params.eventId)
.then((event) => {
Expand Down Expand Up @@ -138,6 +166,14 @@ class Events {
});
}

/**
* Delete the event in the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The event object
*/
static deleteEvent(request, response) {
Event.findById(request.params.eventId)
.then((event) => {
Expand Down Expand Up @@ -177,6 +213,15 @@ class Events {
});
});
}

/**
* Fetch events for a particular center in the database
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The event object
*/
static getCenterEvents(request, response) {
Event.findAll({
where: {
Expand Down
19 changes: 19 additions & 0 deletions server/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import validateSignin from '../validators/validateSignin';

const { User } = db;

/**
* Controller class for handling user actions
*/
class Users {
/**
* Create a new User
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The user object
*/
static userSignup(request, response) {
const { errors, isValid } = validateSignup(request.body);
if (!isValid) {
Expand Down Expand Up @@ -64,6 +75,14 @@ class Users {
});
}

/**
* Sign-in a user
*
* @param {object} request - The request object
* @param {object} response - The response object
*
* @returns {object} The user object
*/
static userSignin(request, response) {
const { errors, isValid } = validateSignin(request.body);
if (!isValid) {
Expand Down
6 changes: 6 additions & 0 deletions server/validators/validateAddCenter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { isEmpty } from 'lodash';

/**
* Validates the incoming request
*
* @param {Object} centerData - The incoming request
* data for the creation of a center
*/
const validateAddCenter = (centerData) => {
const errors = {};
if (centerData.name === undefined || centerData.name.trim() === '') {
Expand Down
6 changes: 6 additions & 0 deletions server/validators/validateAddEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { isEmpty } from 'lodash';

/**
* Validates the incoming request
*
* @param {Object} eventData - The incoming request
* data for the creation of an event
*/
const validateAddEvent = (eventData) => {
const errors = {};
if (eventData.name.trim() === '' || eventData.name === undefined) {
Expand Down
6 changes: 6 additions & 0 deletions server/validators/validateSignin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { isEmpty } from 'lodash';

const validateEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

/**
* Validates the incoming request
*
* @param {Object} userData - The incoming request
* data for the creation of a new user
*/
const validateSignin = (userData) => {
const errors = {};
if (
Expand Down
6 changes: 6 additions & 0 deletions server/validators/validateSignup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { isValidNumber } from 'libphonenumber-js';

const validateEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

/**
* Validates the incoming request
*
* @param {Object} userData - The incoming request
* data for the creation of a user
*/
const validateSignup = (userData) => {
const errors = {};
if (
Expand Down

0 comments on commit 72465ed

Please sign in to comment.