This repository has been archived by the owner on Mar 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Backend API
Alexander Clines edited this page Mar 4, 2017
·
1 revision
This component is to serve as an internal library for connecting to the backend API.
import {server} from 'PATH/TO/server'
createReport(newReport)
modifyReport(uid, updatedReport)
getReportByUid(uid)
getAllReports()
deleteReport(uid)
createEvent(newEvent)
modifyEvent(uid, updatedEvent)
getEventByUid(uid)
getAllEvents()
deleteEvent(uid)
{
"user" : {
"approvalStatus" : BOOLEAN,
"email" : STRING,
"firstName" : STRING,
"lastName" : STRING,
"points" : NUMBER,
"role" : ENUM/STRING,
"studentId" : STRING
}
}
{
"type" : ENUM/STRING,
"approvalStatus" : ENUM/STRING,
"student" : USER-UID,
"event" : EVENT-UID,
}
{
"type" : ENUM/STRING,
"approvalStatus" : ENUM/STRING,
"student" : USER-UID,
"category" : ENUM/STRING,
"datetime" : DATE-TIME STRING,
"location" : STRING,
"title" : STRING,
"description" : STRING
}
Method: login(email, password)
Returns: Promise
- Resolve: user object on success
var email = "test.person@email.com"
var password = "secureP@$$word"
server.login(email, password).then(function(user){
console.log("Logged in successfully!")
}).catch(function(reason){
console.log("Could not login with reason", reason)
})
Method: getLoggedInUser()
Returns: User object if logged in
var user = server.getLoggedInUser();
if(user) console.log(user.firstName," is logged in!")
else console.log("User not logged in!")
Method: logout()
Returns: None
user.logout()
if(user.getLoggedInUser()) console.log("This won't happen")
else console.log("User logged out successfully.")
Method: createReport(newReport)
Returns: Promise
- Resolve: UID of new user
var testEventReport = {
type: "event",
student: "1234567",
event: "9876543321"
}
server.createReport(testEventReport).then(function(uid) {
console.log(uid, "created!")
}).catch(function(reason) {
console.log("Event report was NOT created with reason", reason)
})
Method: modifyReport(uid, updatedReport)
Returns: Promise
- Resolve: On success
- Reject: Reason
var testEventReport = {
type: "event",
student: "1234567",
event: "12343645"
}
var reportUid = ... //Let's pretend this is the UID returned from creating report
server.modifyReport(testEventReportUid, testEventReport).then(function() {
console.log("Report modified!")
}).catch(function(reason) {
console.log("Report NOT modified with reason", reason);
})
Method: getReportByUid(uid)
Returns: Promise
- Resolve: Report object with passed in UID
server.getReportByUid(testEventReportUid).then(function(report){
console.log("Report retrieved", report);
}).catch(function(reason){
console.log("Report NOT retrieved with reason", reason);
})
Method: getAllReports()
Returns: Promise
- Resolve: All the report objects
server.getAllReports().then(function(reports){
console.log("Reports retrieved", report);
}).catch(function(reason) {
console.log("Report NOT retrieved with reason", reason);
})
Method: deleteReport(uid)
Returns: Promise
server.deleteReport(testEventReportUid).then(function() {
console.log("Report deleted!")
}).catch(function(reason) {
console.log("Report not deleted with reason", reason)
})
Method: createEvent(newEvent)
Returns: Promise
- Resolve: UID of created event
var newEvent = {
"datetime": "2017:05:20:09:00",
"location": "United Supermarkets Arena",
"title": "Graduation",
"description": "TTU Commencement for the College of Engineering"
}
server.createEvent(newEvent).then(function(uid){
console.log("Event created with uid",uid)
}).catch(function(reason){
console.log("Event NOT created with reason", reason)
})
Method: modifyEvent(uid, updatedEvent)
Returns: Promise
var newEvent = {...}//As above
var newEventUid = //Let's pretend this is the UID returned in previous method.
testEvent.title = "Commencement";
server.modifyEvent(testEventUid, testEvent).then(function(){
console.log("Event modified!")
}).catch(function(reason){
console.log("Event NOT modified with reason", reason)
})
Method: getEventByUid(uid)
Returns: Promise
- Resolve: Event object
var newEventUid = //Let's pretend this is the UID returned in previous method.
server.getEventByUid(testEventUid).then(function(event){
console.log("Got event", event)
}).catch(function(reason){
console.log("Did not get event with reason", reason)
})
Method: getAllEvents()
Returns: Promise
- Resolve: Object containing all event objects
server.getAllEvents().then(function(events){
console.log("Got events", events)
}).catch(function(reason){
console.log("Did not get events with reason", reason)
})
Method: deleteEvent(uid)
Returns: Promise
var newEventUid = //Let's pretend this is the UID returned in previous method.
server.deleteEvent(newEventUid).then(function(){
console.log("Event deleted")
}).catch(function(reason){
console.log("Event NOT deleted with reason", reason)
})