0.3.0 • Published 3 years ago

paraplan-react v0.3.0

Weekly downloads
85
License
MIT
Repository
github
Last release
3 years ago

paraplan-react

Library for ParaPlan API On Demand and Demand Response Transportation

NPM JavaScript Style Guide

Install

npm install --save paraplan-react

Example

There is an example project available here.

Login

Configuration Options (Filespecs)

import { config } from 'paraplan-react'
getConfig(){
        var request = {
            restUrl: '<from login>',
            key: '<from login>',
            device: 'connect-web',
        }
        config(request)
            .then(response => {
                this.setState({
                    success: response.success,
                    config: response.entity,
                })
            })
            .catch(reason => {
                this.setState({
                    success: reason.success,
                    errorMessage: reason.errorMessage,
                })
            })
    }

Drivers

import { allDrivers } from 'paraplan-react'

getDrivers() {
    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
    }
    allDrivers(request)
        .then(response => {
            this.setState({
                success: response.success,
                allDrivers: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Save Fleetmanager

import { saveFleetmanager } from 'paraplan-react'
saveFleetmanager(){

    var fm = {
        driverID: 157,
        routeId: 102,
        endTime: "/Date(-2209093200000+0000)/",
        startTime: "/Date(-2209141800000+0000)/",
        vehicleID: 311,
        fleetmanagerID: 10463
    }

    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
        fleetmanager: fm,
    }


    saveFleetmanager(request)
        .then(response => {
            console.log(response);
            this.setState({fleetManagerId: response.fleetmanagerId})

        })
        .catch(reason => {
            console.log(reason.errorMessage)
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })

}

Vehicles

import { allVehicles } from 'paraplan-react'

getVehicles() {

    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
    }
    allVehicles(request)
        .then(response => {
            this.setState({
                success: response.success,
                allVehicles: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Routes (FleetManagers)

import { routes } from 'paraplan-react'

viewTodaysRoutes() {
  var request = {
      restUrl: '<from login>',
      key: '<from login>',
      tripDate: '06-15-2020'
      device: 'connect-web',
  }
  routes(request).then(response => {
      this.setState({
          success: response.success,
          errorMessage: response.errorMessage,
          routes: response.list,
      })
  })
  .catch((reason) => {
      this.setState({
          success: reason.success,
          errorMessage: reason.errorMessage,
      })
  })
}
import { allRoutes } from 'paraplan-react'
getRoutes() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
    }
    allRoutes(request)
        .then(response => {
            this.setState({
                success: response.success,
                allRoutes: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Trips

import { trips } from 'paraplan-react'

viewTodaysTrips() {
  var request = {
    restUrl: '<from login>',
    key: '<from login>',
    device: 'connect-web',
    startTime: new Date(new Date().setHours(0, 0, 0, 0)).getTime() / 1000,
    endTime: new Date(new Date().setHours(24, 0, 0, 0)).getTime() / 1000,
  }
  trips(request).then(response => {
      this.setState({
          success: response.success,
          errorMessage: response.errorMessage,
          trips: response.list,
      })
  })
  .catch((reason) => {
      this.setState({
          success: reason.success,
          errorMessage: reason.errorMessage,
      })
  })
}

Trip Requests

import { tripRequests } from 'paraplan-react'

viewTodaysTripRequests() {
  var request = {
    restUrl: '<from login>',
    key: '<from login>',
    device: 'connect-web',
    startDateTime: new Date(new Date().setHours(0, 0, 0, 0)).getTime() / 1000,
    endDateTime: new Date(new Date().setHours(24, 0, 0, 0)).getTime() / 1000,
  }
  tripRequests(request).then(response => {
      this.setState({
          success: response.success,
          errorMessage: response.errorMessage,
          requests: response.list,
      })
  })
  .catch((reason) => {
      this.setState({
          success: reason.success,
          errorMessage: reason.errorMessage,
      })
  })
}

Managing Trips Requests

import { approveRequest } from 'paraplan-react'

approveTripRequest() {

    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
        tripRequest: <trip request to approve>
    }

    approveRequest(request)
        .then(response => {
            var tripStatus = response.request.tripStatus
            var importTripID = response.request.importTripID
            this.setState({
                success: response.success,
                tripRequests: this.state.tripRequests.map(el =>
                    el.importTripID === importTripID
                        ? { ...el,  tripStatus}
                        : el
                )
            })
            //response also includes `.stops` which are the legs of the approved trip
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}
import { rejectRequest } from 'paraplan-react'

rejectTripRequest() {

    var request = {
        restUrl: '<from login>',
        key: '<from login>',
        device: 'connect-web',
        tripRequest: <trip request to reject>,
        rejectReason: <reason trip is being rejected>
    }

    rejectRequest(request)
        .then(response => {
            var tripStatus = response.entity.tripStatus
            var importTripID = response.entity.importTripID
            this.setState({
                success: response.success,
                tripRequests: this.state.tripRequests.map(el =>
                    el.importTripID === importTripID
                        ? { ...el,  tripStatus}
                        : el
                )
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Add a new trip (not request)

addTripFromDispatch() {
    var request = {
        key: <from login>,
        restUrl: <from login>,
        device: 'connect-web',
        trip: {
                client: {
                    id: 19282
                },
                pickUpPlace: {
                    databaseId: 35604
                },
                dropOffPlace: {
                    databaseId: 34409
                },
                scheduledPickUpTime : moment().add(5,'minutes').unix(),
                scheduledDropOffTime : moment().add(30,'minutes').unix(),
                appointmentTime : moment().add(5,'minutes').unix(),
                program : {
                    databaseID : 53
                },
            }
    }

    addTrip(request)
            .then(response => {
                this.setState({
                    success: response.success,
                    successMessage: 'new tripid is ' + response.entity.tripId
                })
            })
            .catch(reason => {
                this.setState({
                    success: reason.success,
                    errorMessage: reason.errorMessage,
                })
            })
}
  • While request.tripRequest will take the entire trip request. It only needs to have .importTripID populated. It will ignore all other fields and build the object on the server fresh from the database.
  • In the return object, request will have the most up to date version of the trip request.
  • Also, the return object of approve will contain stops, which is an array of Stop. Appending existing stop arrays with this data will save a round trip to the server.
  • Since we are dealing with trip requests and http requests, you might want to rename your variables to avoid confusion.

Scheduling trips to routes

import { scheduleTrip } from 'paraplan-react'

scheduleTripToRoute(trip, fleetmanager) {

    var request = {
        key: <from login>,
        restUrl: <from login>,
        device: 'connect-web',
        fleetManagerId: <fleetmanager ID to assign to>,
        trip: <trip to assign. Only .tripId needed>
    }

    scheduleTrip(request)
        .then(response => {
            var tripId = response.entity.tripId
            var fleetmanager = response.entity.fleetmanager

            this.setState({
                success: response.success,
                dispatcherTrips: this.state.dispatcherTrips.map(el =>
                    el.tripId === tripId
                        ? { ...el, fleetmanager }
                        : el
                ),
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}
import { unscheduleTrip } from 'paraplan-react'
unscheduleTrip() {
    var request = {
        key: <from login>,
        restUrl: <from login>,
        device: 'connect-web',
        trip: <trip to assign. Only .tripId needed>
    }

    unscheduleTrip(request)
        .then(response => {
            var tripId = response.trip.tripId
            var fleetmanager = response.trip.fleetmanager

            console.log(response.trip)

            this.setState({
                success: response.success,
                dispatcherTrips: this.state.dispatcherTrips.map(el =>
                    el.tripId === tripId
                        ? { ...el, fleetmanager }
                        : el
                ),
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Searching for clients

import { clientSearch } from 'paraplan-react'

searchClients(){
    const { key, restUrl, requestDevice, clientSearchString } = this.state
    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
        search: clientSearchString,
    }
    
    clientSearch(request)
        .then(response => {
            this.setState({
                success: response.success,
                clients: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
    }
}

Places

import { placeSearch } from 'paraplan-react'

searchPlaces(){
    const { key, restUrl, requestDevice, placesSearchString } = this.state
    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
        search: placesSearchString,
    }
    
    placeSearch(request)
        .then(response => {
            this.setState({
                success: response.success,
                places: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })

    }
//Places specificallly designated as on demand spots
import { placesOnDemand } from 'paraplan-react'

getOnDemandPlaces() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
    }
    placesOnDemand(request)
        .then(response => {
            this.setState({
                success: response.success,
                places: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Programs (Trip funding source)

import { programs } from 'paraplan-react'

getPrograms() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
    }

    programs(request)
        .then(response => {
            this.setState({
                success: response.success,
                programs: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Trip Purposes (Appointment Types)

import { purposes } from 'paraplan-react'
getPurposes() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
    }
    purposes(request)
        .then(response => {
            this.setState({
                success: response.success,
                purposes: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Client Status Types

import { statusTypes } from 'paraplan-react'
getStatusTypes() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
    }
    statusTypes(request)
        .then(response => {
            this.setState({
                success: response.success,
                statusTypes: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

Wheelchair Types

import { wheelchairTypes } from 'paraplan-react'
getWheelchairTypes() {
    const { key, restUrl, requestDevice } = this.state

    var request = {
        key: key,
        restUrl: restUrl,
        device: requestDevice,
    }
    wheelChairTypes(request)
        .then(response => {
            this.setState({
                success: response.success,
                wheelchairTypes: response.list,
            })
        })
        .catch(reason => {
            this.setState({
                success: reason.success,
                errorMessage: reason.errorMessage,
            })
        })
}

License

MIT © timhibbard timhibbard@passiotech.com

0.3.0

3 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

1.0.0

4 years ago