Function
Static Public Summary | ||
public |
async changeEmail(email: string, storedPassword: string, password: string, newEmail: string): Promise<undefined, Error> Delete all of user's sessions from database and change their email. |
|
public |
async changePassword(email: string, storedPassword: string, password: string, newPassword: string): Promise<undefined, Error> Delete all of user's sessions from database and change their password. |
|
public |
Closes the connection from mongoose to the database, using |
|
public |
comparePassword(password: string): Promise<boolean, Error> Helper method to check users password |
|
public |
Utility function to compare against a bcrypt'd password. |
|
public |
createEvent(newEvent: EventSchema): Promise<string, Error Creates a new event on the server |
|
public |
createEvent(reqData: Object, locals: Object, createCallback: EventCallback) Creates a event using fields from the request object then calls back when the database save finishes. |
|
public |
createReport(reqData: Object, locals: Object, createCallback: reportCallback) Creates a report with the fields in the request object, and calls a callback when the database save finishes. |
|
public |
createReport(newReport: Object): Promise<string, Error Creates a new report on the server |
|
public |
createUser(data: Object, next: CreateUserCallback) Given User information, create a User. |
|
public |
createUser(newUser: UserSchema): Promise<string, Error> Creates a new user on the server |
|
public |
deleteEvent(eventUid: string, locals: Object, deleteCallback: EventCallback) Deletes a specific event and calls back once database deletion finishes. |
|
public |
deleteReport(reportUid: string, locals: Object, deleteCallback: reportCallback) Deletes a specific report, and calls a callback once the database deletion finishes. |
|
public |
async deleteSessionsByEmail(email: string): Promise<Object, Error> Utility function to delete all sessions for a given user's email. |
|
public |
deleteUser(userUid: string): Promise<Error> Deletes a user from the server |
|
public |
deleteUser(userUid: string, locals: Object, deleteCallback: DeleteUserCallback) Deletes the user from the database. |
|
public |
errorHandler(err: Object, onError: OnApiCallFinished) Handles errors from API and logs them |
|
public |
getAllEvents(): Promise<Object, Error Retrieves all events from the server. |
|
public |
getAllReports(): Promise<Object, Error Retrieves all reports from the server. |
|
public |
getAllReports(reqData: Object, locals: Object, queryCallback: multipleReportsCallback) Finds all reports, and calls a callback once all reports are found. |
|
public |
Utility function to get a MongoClient collection instance from Mongoose. |
|
public |
Retrieves an event from the server by its UID |
|
public |
getEventById(eventUid: string, locals: Object, getCallback: EventCallback) Finds a specific event and calls back once find operation finishes. |
|
public |
Retrieves an report from the server by its UID |
|
public |
getReportById(reportUid: string, locals: Object, queryCallback: reportCallback) Finds a specific report, and calls a callback once the report is found. |
|
public |
Retrieves a user from the server |
|
public |
getUserById(userUid: string, locals: Object, queryCallback: GetUserCallback) Retrieves the user. |
|
public |
Given a valid email/password, generates a session and returns the id. |
|
public |
Attempt to login using email and password. |
|
public |
Delete a specific session from the database. |
|
public |
Attempt to logout. |
|
public |
modifyEvent(event: string, reqData: Object, locals: Object, modifyCallback: EventCallback) Modifies a specific event with the fields in the request object then calls back when the database update finishes. |
|
public |
modifyEvent(uid: string, updatedEvent: EventSchema): Promise<EventSchema, Error> Modifies an event on the server. |
|
public |
modifyReport(reportUid: string, reqData: Object, locals: Object, modifyCallback: reportCallback) Modifies a specific report according to the fields in the request object, and calls a callback when the database save finishes. |
|
public |
Modifies an report on the server. |
|
public |
modifyUser(userUid: string, reqData: Object, locals: Object, modifyCallback: ModifyUserCallback) Updates the user with the passed in values. |
|
public |
modifyUser(data: Object, userUid: string): Promise<UserSchema, Error> Modifies a user on the server |
|
public |
newIfPresent(newValue: T, oldValue: T): T If the new value is defined and non-null, returns the new value. |
|
public |
Opens a connection from mongoose to the database, wrapping it with
mockgoose if |
|
public |
removeEvent(uid: string): Promise<, Error>,> Removes an event on the server. |
|
public |
removeReport(uid: string): Promise<, Error>,> Removes an report on the server. |
|
public |
Middleware to determine whether the session is verified. |
Static Public
public async changeEmail(email: string, storedPassword: string, password: string, newEmail: string): Promise<undefined, Error> source
import {changeEmail} from 'cpceed-web-app/cpceed-webapp/api/auth/auth-manager.js'
Delete all of user's sessions from database and change their email.
public async changePassword(email: string, storedPassword: string, password: string, newPassword: string): Promise<undefined, Error> source
import {changePassword} from 'cpceed-web-app/cpceed-webapp/api/auth/auth-manager.js'
Delete all of user's sessions from database and change their password.
public close(): Promise<undefined, Error> source
import {close} from 'cpceed-web-app/cpceed-webapp/api/connection.js'
Closes the connection from mongoose to the database, using unmock
if
NODE_ENV is 'test'.
public comparePassword(password: string): Promise<boolean, Error> source
Helper method to check users password
Params:
Name | Type | Attribute | Description |
password | string | The password to be compared to the user's password |
public comparePassword(password: string, target: string): Promise<boolean, Error> source
import {comparePassword} from 'cpceed-web-app/cpceed-webapp/api/core/utils.js'
Utility function to compare against a bcrypt'd password.
public createEvent(newEvent: EventSchema): Promise<string, Error source
import {createEvent} from 'cpceed-web-app/cpceed-webapp/src/server/events.js'
Creates a new event on the server
Params:
Name | Type | Attribute | Description |
newEvent | EventSchema | The data for the new event |
Return:
Promise<string, Error | Resolves with UID of created event rejects with the error |
Example:
const newEvent = {
creator: '<User UID>',
title: 'Studying',
description: 'Studying for finals',
datetime: new Date(),
location: 'Library',
category: 'misc',
};
createEvent(newEvent).then((result) => {
logger.info(`Created new event with uid: ${result.uid}`);
}).catch((err) => {
logger.error(err);
});
public createEvent(reqData: Object, locals: Object, createCallback: EventCallback) source
import {createEvent} from 'cpceed-web-app/cpceed-webapp/api/events/event-manager.js'
Creates a event using fields from the request object then calls back when the database save finishes.
public createReport(reqData: Object, locals: Object, createCallback: reportCallback) source
import {createReport} from 'cpceed-web-app/cpceed-webapp/api/reports/report-manager.js'
Creates a report with the fields in the request object, and calls a callback when the database save finishes.
public createReport(newReport: Object): Promise<string, Error source
import {createReport} from 'cpceed-web-app/cpceed-webapp/src/server/reports.js'
Creates a new report on the server
Params:
Name | Type | Attribute | Description |
newReport | Object | The data for the new report |
Return:
Promise<string, Error | Resolves with UID of created report rejects with the error |
Example:
const newOtherReport = {
creator: '<User UID>',
title: 'Studying',
description: 'Studying for finals',
datetime: new Date(),
location: 'Library',
category: 'misc',
};
createReport(newOtherReport).then((result) => {
logger.info(`Created new report with uid: ${result.uid}`);
}).catch((err) => {
logger.error(err);
});
public createUser(data: Object, next: CreateUserCallback) source
import {createUser} from 'cpceed-web-app/cpceed-webapp/api/users/user-manager.js'
Given User information, create a User.
Params:
Name | Type | Attribute | Description |
data | Object | The request body data. |
|
data.role | String | The user role. |
|
data.email | String | The user email address. |
|
data.password | String | The user password. |
|
data.name | String | The user name. |
|
next | CreateUserCallback | The callback function to run after this function finishes. |
public createUser(newUser: UserSchema): Promise<string, Error> source
import {createUser} from 'cpceed-web-app/cpceed-webapp/src/server/user.js'
Creates a new user on the server
Params:
Name | Type | Attribute | Description |
newUser | UserSchema | The data for the new user |
public deleteEvent(eventUid: string, locals: Object, deleteCallback: EventCallback) source
import {deleteEvent} from 'cpceed-web-app/cpceed-webapp/api/events/event-manager.js'
Deletes a specific event and calls back once database deletion finishes.
public deleteReport(reportUid: string, locals: Object, deleteCallback: reportCallback) source
import {deleteReport} from 'cpceed-web-app/cpceed-webapp/api/reports/report-manager.js'
Deletes a specific report, and calls a callback once the database deletion finishes.
public async deleteSessionsByEmail(email: string): Promise<Object, Error> source
import {deleteSessionsByEmail} from 'cpceed-web-app/cpceed-webapp/api/core/utils.js'
Utility function to delete all sessions for a given user's email.
Params:
Name | Type | Attribute | Description |
string | The user's email. |
public deleteUser(userUid: string): Promise<Error> source
import {deleteUser} from 'cpceed-web-app/cpceed-webapp/src/server/user.js'
Deletes a user from the server
Params:
Name | Type | Attribute | Description |
userUid | string |
|
UID of user to be removed, defaults to current user's uid |
public deleteUser(userUid: string, locals: Object, deleteCallback: DeleteUserCallback) source
import {deleteUser} from 'cpceed-web-app/cpceed-webapp/api/users/user-manager.js'
Deletes the user from the database.
Params:
Name | Type | Attribute | Description |
userUid | string | The UID of the user to be updated. |
|
locals | Object | ||
deleteCallback | DeleteUserCallback |
public errorHandler(err: Object, onError: OnApiCallFinished) source
Handles errors from API and logs them
Params:
Name | Type | Attribute | Description |
err | Object | The error object recieved from Axios |
|
onError | OnApiCallFinished | Called with the correct error object |
public getAllEvents(): Promise<Object, Error source
import {getAllEvents} from 'cpceed-web-app/cpceed-webapp/src/server/events.js'
Retrieves all events from the server. In future, this will accept search and filter parameters.
Return:
Promise<Object, Error | Resolves with an object of key value pairs where the key is the Event UID and the is the Event Data. |
Example:
getAllEvents().then((events) => {
Object.keys(events).forEach((eventUid) => {
logger.info(`Retrieved event with UID: ${eventUid} and data: ${events[eventUid]}`);
});
}).catch((err) => {
logger.error(err);
});
public getAllReports(): Promise<Object, Error source
import {getAllReports} from 'cpceed-web-app/cpceed-webapp/src/server/reports.js'
Retrieves all reports from the server. In future, this will accept search and filter parameters.
Return:
Promise<Object, Error | Resolves with an object of key value pairs where the key is the Report UID and the is the Report Data. |
Example:
getAllReports().then((reports) => {
Object.keys(reports).forEach((reportUid) => {
logger.info(`Retrieved report with UID: ${reportUid} and data: ${reports[reportUid]}`);
});
}).catch((err) => {
logger.error(err);
});
public getAllReports(reqData: Object, locals: Object, queryCallback: multipleReportsCallback) source
import {getAllReports} from 'cpceed-web-app/cpceed-webapp/api/reports/report-manager.js'
Finds all reports, and calls a callback once all reports are found.
public async getCollection(connection: string, name: string): Promise<Object, Error> source
import {getCollection} from 'cpceed-web-app/cpceed-webapp/api/core/utils.js'
Utility function to get a MongoClient collection instance from Mongoose.
public getEvent(uid: string): Promise<EventSchema, Error source
import {getEvent} from 'cpceed-web-app/cpceed-webapp/src/server/events.js'
Retrieves an event from the server by its UID
Params:
Name | Type | Attribute | Description |
uid | string | UID of the event to be retrieved |
Return:
Promise<EventSchema, Error | Resolves with event info |
Example:
getEvent('12345').then((event) => {
logger.info(`Retrieved event with uid: ${event.uid}`); // == 12345
}).catch((err) => {
logger.error(err);
});
public getEventById(eventUid: string, locals: Object, getCallback: EventCallback) source
import {getEventById} from 'cpceed-web-app/cpceed-webapp/api/events/event-manager.js'
Finds a specific event and calls back once find operation finishes.
public getReport(uid: string): Promise<Object, Error source
import {getReport} from 'cpceed-web-app/cpceed-webapp/src/server/reports.js'
Retrieves an report from the server by its UID
Params:
Name | Type | Attribute | Description |
uid | string | UID of the report to be retrieved |
Return:
Promise<Object, Error | Resolves with report info |
Example:
getReport('12345').then((report) => {
logger.info(`Retrieved report with uid: ${report.uid}`); // == 12345
}).catch((err) => {
logger.error(err);
});
public getReportById(reportUid: string, locals: Object, queryCallback: reportCallback) source
import {getReportById} from 'cpceed-web-app/cpceed-webapp/api/reports/report-manager.js'
Finds a specific report, and calls a callback once the report is found.
public getUser(userUid: string): Promise<userSchema, Error> source
import {getUser} from 'cpceed-web-app/cpceed-webapp/src/server/user.js'
Retrieves a user from the server
Params:
Name | Type | Attribute | Description |
userUid | string |
|
UID of user to be updated, defaults to current user's uid |
public getUserById(userUid: string, locals: Object, queryCallback: GetUserCallback) source
import {getUserById} from 'cpceed-web-app/cpceed-webapp/api/users/user-manager.js'
Retrieves the user.
Params:
Name | Type | Attribute | Description |
userUid | string | The UID of the user to be updated |
|
locals | Object | ||
queryCallback | GetUserCallback |
public async login(req: Object, res: Object): Promise<string, Error> source
import {login} from 'cpceed-web-app/cpceed-webapp/api/auth/auth-manager.js'
Given a valid email/password, generates a session and returns the id.
public login(email: String, password: String): Promise<Object, Error> source
import {login} from 'cpceed-web-app/cpceed-webapp/src/server/user-auth.js'
Attempt to login using email and password.
public async logout(session: Object): Promise<undefined, Error> source
import {logout} from 'cpceed-web-app/cpceed-webapp/api/auth/auth-manager.js'
Delete a specific session from the database.
Params:
Name | Type | Attribute | Description |
session | Object | The client's session. |
public logout(): Promise<undefined, Error> source
import {logout} from 'cpceed-web-app/cpceed-webapp/src/server/user-auth.js'
Attempt to logout.
public modifyEvent(event: string, reqData: Object, locals: Object, modifyCallback: EventCallback) source
import {modifyEvent} from 'cpceed-web-app/cpceed-webapp/api/events/event-manager.js'
Modifies a specific event with the fields in the request object then calls back when the database update finishes.
Params:
Name | Type | Attribute | Description |
event | string | Uid - The UID corresponding to the event to be modified. |
|
reqData | Object | The request object containing the new event fields. |
|
locals | Object | An object containg the current request's local variables. |
|
modifyCallback | EventCallback | Called once the operation finishes. |
public modifyEvent(uid: string, updatedEvent: EventSchema): Promise<EventSchema, Error> source
import {modifyEvent} from 'cpceed-web-app/cpceed-webapp/src/server/events.js'
Modifies an event on the server. Must be the creator of the event or admin to modify.
Params:
Name | Type | Attribute | Description |
uid | string | UID of event to be modified |
|
updatedEvent | EventSchema | Event data to be updated |
Example:
const updatedEvent.description = 'Giving up on finals';
modifyEvent(updatedEvent).then((result) => {
logger.info(`Event with uid ${result.uid} was updated`);
}).catch((err) => {
logger.error(err);
});
public modifyReport(reportUid: string, reqData: Object, locals: Object, modifyCallback: reportCallback) source
import {modifyReport} from 'cpceed-web-app/cpceed-webapp/api/reports/report-manager.js'
Modifies a specific report according to the fields in the request object, and calls a callback when the database save finishes.
Params:
Name | Type | Attribute | Description |
reportUid | string | The UID corresponding to the report to be modified. |
|
reqData | Object | The request object containing the fields to be modified. |
|
locals | Object | An object containing the current request's local variables. |
|
modifyCallback | reportCallback | Called once the operation finishes. |
public modifyReport(uid: string, updatedReport: Object): Promise<Object, Error> source
import {modifyReport} from 'cpceed-web-app/cpceed-webapp/src/server/reports.js'
Modifies an report on the server. Must be the creator of the report or admin to modify.
Example:
const updatedReport.description = 'Giving up on finals';
modifyReport(updatedReport).then((result) => {
logger.info(`Report with uid ${result.uid} was updated`);
}).catch((err) => {
logger.error(err);
});
public modifyUser(userUid: string, reqData: Object, locals: Object, modifyCallback: ModifyUserCallback) source
import {modifyUser} from 'cpceed-web-app/cpceed-webapp/api/users/user-manager.js'
Updates the user with the passed in values. This method does NOT delete fields
Params:
Name | Type | Attribute | Description |
userUid | string | The UID of the user to be updated |
|
reqData | Object | The request data |
|
locals | Object | ||
modifyCallback | ModifyUserCallback |
public modifyUser(data: Object, userUid: string): Promise<UserSchema, Error> source
import {modifyUser} from 'cpceed-web-app/cpceed-webapp/src/server/user.js'
Modifies a user on the server
Return:
Promise<UserSchema, Error> | Promise that resolves with the modified user or rejects with error |
public newIfPresent(newValue: T, oldValue: T): T source
import {newIfPresent} from 'cpceed-web-app/cpceed-webapp/api/core/utils.js'
If the new value is defined and non-null, returns the new value. Otherwise, returns the old value.
Params:
Name | Type | Attribute | Description |
newValue | T | A new value value that may or may not be defined and non-null. |
|
oldValue | T | A old value that is defined and non-null. |
Return:
T | The new value if it is defined and non-null. The old value if the new value is undefined or null. |
public open(): Promise<undefined, Error> source
import {open} from 'cpceed-web-app/cpceed-webapp/api/connection.js'
Opens a connection from mongoose to the database, wrapping it with
mockgoose if NODE_ENV
is 'test'.
public removeEvent(uid: string): Promise<, Error>,> source
import {removeEvent} from 'cpceed-web-app/cpceed-webapp/src/server/events.js'
Removes an event on the server. Must be the creator of the event or admin to remove
Params:
Name | Type | Attribute | Description |
uid | string | UID of the event to remove |
Example:
removeEvent(someEvent.uid).then(() => {
logger.info(`Event with UID ${someEvent.uid} removed`);
}).catch((err) => {
logger.error(err);
});
public removeReport(uid: string): Promise<, Error>,> source
import {removeReport} from 'cpceed-web-app/cpceed-webapp/src/server/reports.js'
Removes an report on the server. Must be the creator of the report or admin to remove
Params:
Name | Type | Attribute | Description |
uid | string | UID of the report to remove |
Example:
removeReport(someReport.uid).then(() => {
logger.info(`Report with UID ${someReport.uid} removed`);
}).catch((err) => {
logger.error(err);
});
public verify(req: Object, res: Object, next: function) source
import {verify} from 'cpceed-web-app/cpceed-webapp/api/auth/auth-manager.js'
Middleware to determine whether the session is verified. For valid sessions, the next middleware is called.