Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

Backend API

Alexander Clines edited this page Mar 4, 2017 · 1 revision

Server API

This component is to serve as an internal library for connecting to the backend API.

Usage

import {server} from 'PATH/TO/server'

Contents

Objects

Methods

User Auth

Reports

Events

Objects

User

{
  "user" : {
    "approvalStatus" : BOOLEAN,
    "email" : STRING,
    "firstName" : STRING,
    "lastName" : STRING,
    "points" : NUMBER,
    "role" : ENUM/STRING,
    "studentId" : STRING
  }
}

Report

Event

{
  "type" : ENUM/STRING,
  "approvalStatus" : ENUM/STRING,
  "student" : USER-UID,
  "event" : EVENT-UID,
}

Other

{
  "type" : ENUM/STRING,
  "approvalStatus" : ENUM/STRING,
  "student" : USER-UID,
  "category" : ENUM/STRING,
  "datetime" : DATE-TIME STRING,
  "location" : STRING,
  "title" : STRING,
  "description" : STRING
}

Methods

Login

Method: login(email, password)

Returns: Promise

  • Resolve: user object on success

Example

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)
})

Get Logged In User

Method: getLoggedInUser()

Returns: User object if logged in

Example

var user = server.getLoggedInUser();
if(user) console.log(user.firstName," is logged in!")
else console.log("User not logged in!")

Logout

Method: logout()

Returns: None

Example

user.logout()
if(user.getLoggedInUser()) console.log("This won't happen")
else console.log("User logged out successfully.")

Create Report

Method: createReport(newReport)

Returns: Promise

  • Resolve: UID of new user

Example

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)
})

Modify Report

Method: modifyReport(uid, updatedReport)

Returns: Promise

  • Resolve: On success
  • Reject: Reason

Example

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);
})

Get Report By UID

Method: getReportByUid(uid)

Returns: Promise

  • Resolve: Report object with passed in UID

Example

server.getReportByUid(testEventReportUid).then(function(report){
  console.log("Report retrieved", report);
}).catch(function(reason){
  console.log("Report NOT retrieved with reason", reason);
})

Get All Reports

Method: getAllReports()

Returns: Promise

  • Resolve: All the report objects

Example

server.getAllReports().then(function(reports){
  console.log("Reports retrieved", report);
}).catch(function(reason) {
  console.log("Report NOT retrieved with reason", reason);
})

Delete Report

Method: deleteReport(uid)

Returns: Promise

Example

server.deleteReport(testEventReportUid).then(function() {
  console.log("Report deleted!")
}).catch(function(reason) {
  console.log("Report not deleted with reason", reason)
})

Create Event

Method: createEvent(newEvent)

Returns: Promise

  • Resolve: UID of created event

Example

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)
})

Modify Event

Method: modifyEvent(uid, updatedEvent)

Returns: Promise

Example

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)
})

Get Event By UID

Method: getEventByUid(uid)

Returns: Promise

  • Resolve: Event object

Example

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)
})

Get All Events

Method: getAllEvents()

Returns: Promise

  • Resolve: Object containing all event objects

Example

server.getAllEvents().then(function(events){
  console.log("Got events", events)
}).catch(function(reason){
  console.log("Did not get events with reason", reason)
})

Delete Event

Method: deleteEvent(uid)

Returns: Promise

Example

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)
})