StackOverflow angular factory problem
JavaScript
angular.module('app', ['processFactory']);
function processFactory () {
/**
* Returns a random number between min and max (Based on PHP rand() function)
*
* @param {Integer} min The minimum that the random number should be
* @param {Integer} max The maximum that the random number should be
* @return {Integer} A random number between min and max
*/
function rand (min, max) {
var argc = arguments.length;
if (argc === 0) {
min = 0;
max = 2147483647;
} else if (argc === 1) {
throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
}
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* A constructor for Role objects
*
* @param {Integer} processId An integer representing this role's parent process ID
* @param {Integer} number What number to assign the roleName attribute
*
* @return {Object Role} A brand new Role object
*/
function Role (processId, number) {
// typecast
processId = +processId;
number = +number;
if ( !!isNaN(processId) || !!isNaN(number) ) {
throw 'Both processId and number need to be numbers';
}
this.roleName = 'role' + number;
this.startDate = rand(0, new Date().getTime());
this.endDate = rand(this.startDate, new Date().getTime());
this.href = '/v1/transactions/' + processId + '/roles/' + this.roleName;
return this;
}
/**
* A constructor for Process objects
*
* @param {Object} options An object with an integer processId and an array of roles containing
* roles
*
* @return {Process} A new Process object
*/
function Process (options) {
if ( typeof options.processId !== 'number' ) {
throw 'Process ID is not a number';
}
if ( typeof...