Skip to content

Database Methods

bsm5 edited this page Mar 11, 2018 · 1 revision

log methods


getEvent(eventClass, entity, from, to)

This method will return an object of event logs dependent on the arguments submitted.

Arguments Argument Type Description Default
eventClass String Allows for only returning events that match a desired eventClass type undefined
entity String Allows for only returning events that match a desired entity type undefined
from JavaScript Date,
String in the form: year--month--day
Allows for returning events that are GTE to the defined date undefined
to JavaScript Date,
String in the form: year--month--day
Allows for returning events that are LTE of the defined date undefined
Note - GTE = Greater Than or Equal | LTE = Less Than or Equal

Example

getEvent(); //Returns all events
getEvent(undefined, undefined, '2000-01-01', undefined); //Returns all events GTE the date 2000-01-01
getEvent(undefined, undefined, undefined, '2020-01-01'); //Returns all events LTE the date 2020-01-01
getEvent(undefined, undefined, '2000-01-01', '2020-01-01'); //Returns all events between both given dates
getEvent('Administration', undefined, undefined, undefined); //Return all events of eventClass type 'Administration'
getEvent(undefined, '1234567', undefined, undefined); //Return all events of entity type '1234567'
 
//Return all events of eventClass type 'Administration' & entity type '1234567'
getEvent('Administration', '1234567', undefined, undefined);

//Return all events of eventClass type 'Administration', entity type '1234567', and GTE the date 2000-01-01
getEvent('Administration', '1234567', '2000-01-01', undefined);

//Return all events of eventClass type 'Administration', entity type '1234567', and LTE the date 2020-01-01
getEvent('Administration', '1234567', undefined, '2020-01-01');

//Return all events of eventClass type 'Administration', entity type '1234567', and between the two dates
getEvent('Administration', '1234567', '2000-01-01', '2020-01-01');


logEvent(eventClass, entity, eventText, eventDate)

This method will create a new log and save it to the database.

Arguments Argument Type Description Default
eventClass String Set the desired eventClass type undefined
entity String Set the desired entity type undefined
eventText String Description of the event undefined
eventDate JavaScript Date Date of the event undefined

Example

//With JavaScirpt Date
logEvent('Administration', '1234567', 'Admin 1234567 did something', new Date());

//Without date
logEvent('Administration', '1234567', 'Admin 1234567 did something', undefined);  


Privilege Methods


getPrivilegedStationUser(sId) This method will return all users who have privileges to the given station id.

Arguments Argument Type Description Default
sId String The station id undefined

Example

//Will return all users who have been granted
//privilege to station id = 1
getPrivilegedStationUsers('1');


grantPrivileges(bId, sId)

This method will create a new entry in the database to indicate that the given bId now has access to the given sId.

Arguments Argument Type Description Default
bId String The badge id undefined
sId String The station id undefined

Example

//Badge # = '1234567' will be granted privileges to
//station id = '1'
grantPrivileges('1234567','1');


removePrivileges(bId, sId)

This method takes the same arguments as the grantPrivileges method but instead of creating a new entry in the database this method removes an existing entry.




Station Methods


createStation(stationData)

This method will add a new station to the database.

Arguments Argument Type Description Default
stationData JSON Object The stationData is a JSON Object that has key:value pairs where the key must match the attribute name in the database and the value must match the data type of the attribute. {}
Note - Refer to the createUser example for an example of how to use this method as the only difference between the two are their method name.


deleteStation(sId)

This method will remove a station entry from the database based off the given sId.

Arguments Argument Type Description Default
sId String Station id undefined

Example

//Station id = '1' will be completely removed from the database.
deleteStation('1');


getStation(sId)

This method will return a single station entry from the database based of the given sId.

Arguments Argument Type Description Default
sId String Station id undefined

Example

//Station object will be returned to the caller if station id = '1' exist in the database.
getStation('1');


getStations(reqTypeRequest)

This method will return all stations, only stations that are registered, or only stations that are not registered depending on the argument provided.

Arguments Argument Type Description Default
reqTypeRequest Boolean true = registered stations
false = unregistered stations
undefined = all stations
undefined

Example

//Return all stations
getStations();

//Return all registered stations
getStations(true);

//Return all unregistered stations
getStations(false);


modifyStation(sId, stationData)

This function will allow for modifying any attribute for the given station id.

Arguments Argument Type Description Default
sId String Station id undefined
stationData JSON Object The stationData is a JSON Object that has key:value pairs where the key must match the attribute name in the database and the value must match the data type of the attribute. {}

Example

//Assume there is a table in the database with this schema:
//   | id |  sId | stationName |
//   | 0  |   1  |     bat     |
//   | 1  |   2  |     man     |

//Modify station name to 'Joker' with sId = '1'
var jsonObject = {"stationName": "Joker"};
modifyStation('1', jsonObject);

//Database instance after modifyStation is called:
//   | id |  sId | stationName |
//   | 0  |   1  |     Joker   |
//   | 1  |   2  |     man     |
     



User Methods


createUser(userData)

This method will add a new registered user to the database.

Arguments Argument Type Description Default
userData JSON Object The userData is a JSON Object that has key:value pairs where the key must match the attribute name in the database and the value must match the data type of the attribute. {}

Example

Note - Example based off person model
var jsonObject = {"first":"Bat", "last":"Man"};
  
createUser(jsonObject);


deleteUser(bId)

This method will remove a user entry from the database.

Arguments Argument Type Description Default
bId String Badge id undefined
Note - This method works just like the deleteStation(sId) method.


getLoggedIn(uId)

This method will return a user object only if the uId is in the database and the user is logged in.

Arguments Argument Type Description Default
uId String Badge id,
Email
undefined

Example

//This will return a user object if user with badge id = '1234567'
//exist and is logged in.  Otherwise, it will return false.
getLoggedIn('1234567');

//This will return a user object if user with email = '123@456.com'
//exist and is logged in.  Otherwise, it will return false.
getLoggedIn('123@456');


getUsers(from, to)

This method will return an object of users dependent on the dates that are passed in as arguments.

Arguments Argument Type Description Default
from JavaScript Date,
String in the form: year--month--day
The starting date undefined
to JavaScript Date,
String in the form: year--month--day
The ending date undefined

Example

  getUsers(); //Returns all users

  getUsers('2000-01-01', undefined); //Returns all users GTE 2000-01-01

  getUsers(undefined, '2020-01-01');  //Returns all users LTE 2020-01-01

  getUsers('2000-01-01', '2020-01-01'); //Returns all users between 2000-01-01 and 2020-01-01


modifyUser(bId, userData)

This function will allow for modifying any attribute for the given badge id.

Arguments Argument Type Description Default
bId String Badge id undefined
userData JSON Object The userData is a JSON Object that has key:value pairs where the key must match the attribute name in the database and the value must match the data type of the attribute. {}

Example

//Assume there is a table in the database with this schema:
//   | id |  bId | first | last |
//   | 0  |   1  |  bat  |  man |
//   | 1  |   2  |  Joker|  man |

//Modify first to 'bat' and last to 'man 2' with bId = '2'
var jsonObject = {"first": "bat", "last": "man 2"};
modifyUser('2', jsonObject);

//Database instance after modifyUser is called:
//   | id |  bId | first | last |
//   | 0  |   1  |  bat  |  man |
//   | 1  |   2  |  bat  | man 2|
     


validateUser(uId)

This method will return a single user object dependent on the given argument.

Arguments Argument Type Description Default
uId String Badge id,
Email
undefined

Example

//Assume there is a table in the database with this schema:
//   | id |  bId |    email     |
//   | 0  |   1  | 123@456.com  |
//   | 1  |   2  | abc@def.com  |

//This will return the user with id = 0, bId = '1', and email = '123@456.com'
validateUser('1');

//This will return the user with id = 1, bId = '2', and email = 'abc@def.com'
validateUser('abc@def.com');