Home Reference Source Repository

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 unmock if NODE_ENV is 'test'.

public

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

Given User information, create a User.

public

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

Utility function to delete all sessions for a given user's email.

public

Deletes a user from the server

public

deleteUser(userUid: string, locals: Object, deleteCallback: DeleteUserCallback)

Deletes the user from the database.

public

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

async getCollection(connection: string, name: string): Promise<Object, Error>

Utility function to get a MongoClient collection instance from Mongoose.

public

getEvent(uid: string): Promise<EventSchema, Error

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

getReport(uid: string): Promise<Object, Error

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

getUser(userUid: string): Promise<userSchema, Error>

Retrieves a user from the server

public

getUserById(userUid: string, locals: Object, queryCallback: GetUserCallback)

Retrieves the user.

public

async login(req: Object, res: Object): Promise<string, Error>

Given a valid email/password, generates a session and returns the id.

public

login(email: String, password: String): Promise<Object, Error>

Attempt to login using email and password.

public

async logout(session: Object): Promise<undefined, Error>

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

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

modifyReport(uid: string, updatedReport: Object): Promise<Object, Error>

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

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 NODE_ENV is 'test'.

public

Removes an event on the server.

public

Removes an report on the server.

public

verify(req: Object, res: Object, next: function)

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

Delete all of user's sessions from database and change their email.

Params:

NameTypeAttributeDescription
email string

The user's email address.

storedPassword string

The user's stored password.

password string

The user's old password.

newEmail string

The user's new email.

Return:

Promise<undefined, Error>

resolves, or rejects with an error.

public async changePassword(email: string, storedPassword: string, password: string, newPassword: string): Promise<undefined, Error> source

Delete all of user's sessions from database and change their password.

Params:

NameTypeAttributeDescription
email string

The user's email address.

storedPassword string

The user's stored password.

password string

The user's old password.

newPassword string

The user's new password.

Return:

Promise<undefined, Error>

resolves, or rejects with an error.

public close(): Promise<undefined, Error> source

Closes the connection from mongoose to the database, using unmock if NODE_ENV is 'test'.

Return:

Promise<undefined, Error>

Resolves when connection is closed.

public comparePassword(password: string): Promise<boolean, Error> source

Helper method to check users password

Params:

NameTypeAttributeDescription
password string

The password to be compared to the user's password

Return:

Promise<boolean, Error>

Resolves with a boolean indicating whether or not the password is a match

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.

Params:

NameTypeAttributeDescription
password string

The password to be compared.

target string

The target of comparison.

Return:

Promise<boolean, Error>

Resolves with a boolean indicating whether or not the password is a match.

public createEvent(newEvent: EventSchema): Promise<string, Error source

Creates a new event on the server

Params:

NameTypeAttributeDescription
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

Creates a event using fields from the request object then calls back when the database save finishes.

Params:

NameTypeAttributeDescription
reqData Object

The request object containing the event data to be created.

locals Object

An object containing the current request's local variables.

createCallback EventCallback

Called once the operation finishes.

public createReport(reqData: Object, locals: Object, createCallback: reportCallback) source

Creates a report with the fields in the request object, and calls a callback when the database save finishes.

Params:

NameTypeAttributeDescription
reqData Object

The request object representing the report to be created.

locals Object

An object containing the current request's local variables.

createCallback reportCallback

Called once the operation finishes.

public createReport(newReport: Object): Promise<string, Error source

Creates a new report on the server

Params:

NameTypeAttributeDescription
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

Given User information, create a User.

Params:

NameTypeAttributeDescription
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

Creates a new user on the server

Params:

NameTypeAttributeDescription
newUser UserSchema

The data for the new user

Return:

Promise<string, Error>

Promise that resolves with the UID or rejects with the error

public deleteEvent(eventUid: string, locals: Object, deleteCallback: EventCallback) source

Deletes a specific event and calls back once database deletion finishes.

Params:

NameTypeAttributeDescription
eventUid string

The UID of the event to be deleted.

locals Object

An object containg the current request's local variables.

deleteCallback EventCallback

Called once the operation is done.

public deleteReport(reportUid: string, locals: Object, deleteCallback: reportCallback) source

Deletes a specific report, and calls a callback once the database deletion finishes.

Params:

NameTypeAttributeDescription
reportUid string

The UID corresponding to the report to be deleted.

locals Object

An object containing the current request's local variables.

deleteCallback reportCallback

Called once the operation 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:

NameTypeAttributeDescription
email string

The user's email.

Return:

Promise<Object, Error>

Resolves with the number of sessions deleted.

public deleteUser(userUid: string): Promise<Error> source

Deletes a user from the server

Params:

NameTypeAttributeDescription
userUid string
  • optional

UID of user to be removed, defaults to current user's uid

Return:

Promise<Error>

Resolves on null, rejects with error

public deleteUser(userUid: string, locals: Object, deleteCallback: DeleteUserCallback) source

Deletes the user from the database.

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
err Object

The error object recieved from Axios

onError OnApiCallFinished

Called with the correct error object

public getAllEvents(): Promise<Object, Error source

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

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

Finds all reports, and calls a callback once all reports are found.

Params:

NameTypeAttributeDescription
reqData Object

An object containing additional search parameters (not yet implemented).

locals Object

An object containing the current request's local variables.

queryCallback multipleReportsCallback

Called once the operation finishes.

public async getCollection(connection: string, name: string): Promise<Object, Error> source

Utility function to get a MongoClient collection instance from Mongoose.

Params:

NameTypeAttributeDescription
connection string

The mongoose connection.

name string

The name of the collection.

Return:

Promise<Object, Error>

Resolves with the collection.

public getEvent(uid: string): Promise<EventSchema, Error source

Retrieves an event from the server by its UID

Params:

NameTypeAttributeDescription
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

Finds a specific event and calls back once find operation finishes.

Params:

NameTypeAttributeDescription
eventUid string

The UID of the event to be found.

locals Object

An object containing the current request's local variables.

getCallback EventCallback

Called once the operation is done.

public getReport(uid: string): Promise<Object, Error source

Retrieves an report from the server by its UID

Params:

NameTypeAttributeDescription
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

Finds a specific report, and calls a callback once the report is found.

Params:

NameTypeAttributeDescription
reportUid string

The UID corresponding to the report to be found.

locals Object

An object containing the current request's local variables.

queryCallback reportCallback

Called once the operation finishes.

public getUser(userUid: string): Promise<userSchema, Error> source

Retrieves a user from the server

Params:

NameTypeAttributeDescription
userUid string
  • optional

UID of user to be updated, defaults to current user's uid

Return:

Promise<userSchema, Error>

Promise that resolves with the user or rejects with error

public getUserById(userUid: string, locals: Object, queryCallback: GetUserCallback) source

Retrieves the user.

Params:

NameTypeAttributeDescription
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

Given a valid email/password, generates a session and returns the id.

Params:

NameTypeAttributeDescription
req Object

The request object.

res Object

The response object.

Return:

Promise<string, Error>

Resolves with the session id, or rejects with an error that contains a status code and a message.

public login(email: String, password: String): Promise<Object, Error> source

Attempt to login using email and password.

Params:

NameTypeAttributeDescription
email String

The email address.

password String

The password.

Return:

Promise<Object, Error>

Promise that resolves with the user's data or rejects with an error.

public async logout(session: Object): Promise<undefined, Error> source

Delete a specific session from the database.

Params:

NameTypeAttributeDescription
session Object

The client's session.

Return:

Promise<undefined, Error>

Resolves, or rejects with an error.

public logout(): Promise<undefined, Error> source

Attempt to logout.

Return:

Promise<undefined, Error>

Promise that resolves as undefined or rejects with an error.

public modifyEvent(event: string, reqData: Object, locals: Object, modifyCallback: EventCallback) source

Modifies a specific event with the fields in the request object then calls back when the database update finishes.

Params:

NameTypeAttributeDescription
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

Modifies an event on the server. Must be the creator of the event or admin to modify.

Params:

NameTypeAttributeDescription
uid string

UID of event to be modified

updatedEvent EventSchema

Event data to be updated

Return:

Promise<EventSchema, Error>

Resolves with the updated event data

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

Modifies a specific report according to the fields in the request object, and calls a callback when the database save finishes.

Params:

NameTypeAttributeDescription
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

Modifies an report on the server. Must be the creator of the report or admin to modify.

Params:

NameTypeAttributeDescription
uid string

UID of report to be modified

updatedReport Object

Report data to be updated

Return:

Promise<Object, Error>

Resolves with the updated report data

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

Updates the user with the passed in values. This method does NOT delete fields

Params:

NameTypeAttributeDescription
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

Modifies a user on the server

Params:

NameTypeAttributeDescription
data Object

Data on the user to be updated

userUid string
  • optional

UID of user to be updated, defaults to current user's uid

Return:

Promise<UserSchema, Error>

Promise that resolves with the modified user or rejects with error

public newIfPresent(newValue: T, oldValue: T): T source

If the new value is defined and non-null, returns the new value. Otherwise, returns the old value.

Params:

NameTypeAttributeDescription
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

Opens a connection from mongoose to the database, wrapping it with mockgoose if NODE_ENV is 'test'.

Return:

Promise<undefined, Error>

Resolves when connection is opened.

public removeEvent(uid: string): Promise<, Error> source

Removes an event on the server. Must be the creator of the event or admin to remove

Params:

NameTypeAttributeDescription
uid string

UID of the event to remove

Return:

Promise<, Error>

Resolves with nothing if successful

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

Removes an report on the server. Must be the creator of the report or admin to remove

Params:

NameTypeAttributeDescription
uid string

UID of the report to remove

Return:

Promise<, Error>

Resolves with nothing if successful

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

Middleware to determine whether the session is verified. For valid sessions, the next middleware is called.

Params:

NameTypeAttributeDescription
req Object

The request object.

res Object

The response object.

next function

Invoke the next middleware or route.