Skip to content

Firebase Functions

Gabriel T edited this page Mar 15, 2021 · 1 revision

Firebase Functions

Table of Contents

createPostRequestBody(params)

Parameters

params: Plain Object that should look like the one below.

params = {   
    service_code: '2000031-1',
    address_string: '50 laurier ave W',
    attribute: 
    { 
        client_address_id_req: '___A6TJQ',
        client_address_string_req: 'AS',
        cmb_councillorcheckbox: 'Yes_No.Yes' 
    },
    lat: '45.7204',
    long: '-75.6896',
    first_name: 'F',
    last_name: 'S',
    email: 'fs@gmail.com',
    phone: '1231231234',
    service_name: 'Disabled parking spaces',
    user_id: 'BJ01n7HSp1ZDXuWd1IC8SYsho8d2',
    description: 'parking spot not available',
    category: 'Parking',
    city: 'ottawa',
    media_url: '' 
}

Description

This function will make the body of the post request for the specific city. It currently only handles Ottawa otherwise only returns the plain Object itself.

Return Value

This function returns a promise which resolves the body of the post request needed for the specific city. Given that it only handles Ottawa at this time, it makes the serializes the Object into a url append-able string.

getAllIssueCategories(city)

Parameters

Param Description Supported values
city String that identifies the current city the categories need to be fetched from. "Ottawa"

Description

This function gathers the categories from the given city. It first checks if the city categories have been cached, if they have been, it then checks if the categories are outdated, if they are, it then refetches from the city itself then caches them. If the categories have not been cached, the function fetches them from the city and then caches them.

Return Value

This function returns a promise which resolves an Object that contains the categories for the given city

getAllIssueCategoriesFromUrl(city)

Parameters

Param Description Supported values
city String that identifies the current city the categories need to be fetched from. "Ottawa"

Description

This function calls the correct endpoint() for the given city and molds the response into a category sorted object.

Return Value

This function returns a promise which resolves the categories for the given city.

getAllAttributesForIssue(serviceId, city)

Parameters

Param Description Supported values
city String that identifies the current city the categories need to be fetched from. "Ottawa"
serviceId String that identifies the service request ID. ex: "2000031-1"

Description

This function calls the correct city endpoint to gather all the necessary attributes for the given service request ID.

Return Values

This function returns a promise which resolves the necessary attributes for the give service request ID and city.

replaceAddressStringsToId(params, mandatoryParams)

Parameters

Params Description
params Plain Object that should look like the one below.
mandatoryParams Array of mandatory attributes needed for the given request.
params = {   
    service_code: '2000031-1',
    address_string: '50 laurier ave W',
    attribute: 
    { 
        client_address_id_req: '___A6TJQ',
        client_address_string_req: 'AS',
        cmb_councillorcheckbox: 'Yes_No.Yes' 
    },
    lat: '45.7204',
    long: '-75.6896',
    first_name: 'f',
    last_name: 's',
    email: 'fs@gmail.com',
    phone: '1231231234',
    service_name: 'Disabled parking spaces',
    user_id: 'BJ01n7HSp1ZDXuWd1IC8SYsho8d2',
    description: 'parking spot not available',
    category: 'Parking',
    city: 'ottawa'
}

mandatoryParams = [ 
    { 
        variable: true,
        code: 'client_address_string_req',
        datatype: 'string',
        required: true,
        datatypeDescription: null,
        order: 6,
        description: 'Client postal address',
        values: [] },
    { 
        variable: true,
        code: 'client_address_id_req',
        datatype: 'string',
        required: true,
        datatypeDescription: null,
        order: 7,
        description: 'Client address id',
        values: [] },
    { 
        variable: true,
        code: 'cmb_councillorcheckbox',
        datatype: 'singlevaluelist',
        required: true,
        datatypeDescription: null,
        order: 12,
        description: 'I consent to provide my personal information',
        values: [ [Object], [Object] ] 
    } 
]

Description

This function checks for attributes that need an ID version of the address and converts them by calling the appropriate city endpoint.

Return Values

This function returns a promise which resolves nothing, it simply modifies the params object.

checkSubmissionParams(params)

Parameters

Param Description
params Plain Object that should look like the one below.
params = {   
    service_code: '2000031-1',
    address_string: '50 laurier ave W',
    attribute: 
    { 
        client_address_id_req: '___A6TJQ',
        client_address_string_req: 'AS',
        cmb_councillorcheckbox: 'Yes_No.Yes' 
    },
    lat: '45.7204',
    long: '-75.6896',
    first_name: 'f',
    last_name: 's',
    email: 'fs@gmail.com',
    phone: '1231231234',
    service_name: 'Disabled parking spaces',
    user_id: 'BJ01n7HSp1ZDXuWd1IC8SYsho8d2',
    description: 'parking spot not available',
    category: 'Parking',
    city: 'ottawa'
}

Description

This function checks if the post request to the city contains all the necessary attributes for the given service request.

Return Values

This function returns a promise which does not resolve anything, it simply modifies the params object as it may call replaceAddressStringsToId(params, mandatoryParams).

submitIssueToCity(params, city)

Parameters

Param Description Supported values
params Plain Object that should look like the one below or serialized to a string by createPostRequestBody(params).
city String that identifies the current city where the request needs to be posted to. "Ottawa"
params = {   
    service_code: '2000031-1',
    address_string: '50 laurier ave W',
    attribute: 
    { 
        client_address_id_req: '___A6TJQ',
        client_address_string_req: 'AS',
        cmb_councillorcheckbox: 'Yes_No.Yes' 
    },
    lat: '45.7204',
    long: '-75.6896',
    first_name: 'f',
    last_name: 's',
    email: 'fs@gmail.com',
    phone: '1231231234',
    service_name: 'Disabled parking spaces',
    user_id: 'BJ01n7HSp1ZDXuWd1IC8SYsho8d2',
    description: 'parking spot not available',
    category: 'Parking',
    city: 'ottawa'
}

Description

This function submits the service request to the given city.

Return Values

This function returns a promise which resolves a response Object received from the city.

checkIfCityIsAccepted(city)

Parameters

Param Description Supported value
city String that identifies the current city where the request needs to be posted to. "Ottawa"

Description

This function checks if the city is in the Neappoli's offering.

Return Values

This function returns a boolean based on the presence of the city in Neappoli.

findCityBasedOnLatAndLon(lat, long)

Parameters

Param Description Example
lat Float that represents the latitude of the pin. 45.7204
long Float that represents the longitude of the pin. -75.6896

Description

This function gets the city of the pin created based on its geo-coordinates

Return Values

This function returns a promise which resolves a String representing the city the pin is in.

cacheCategoriesForCity(city, categories)

Parameters

Param Description Supported values
city String that represents the city to which the categories of services belong. "Ottawa"
categories Category Object which should be returned by the cache or getAllIssueCategories(city).

Description

This function caches the categories in the Firebase database with the city as the key.

Return Values

This function returns a promise which resolves nothing.

uploadIssueToFirebaseDatabase(params, cityResponse)

Parameters

Param Description
params Plain Object that should look like the one below.
cityResponse Object that the city returns.
params = {   
    service_code: '2000031-1',
    address_string: '50 laurier ave W',
    attribute: 
    { 
        client_address_id_req: '___A6TJQ',
        client_address_string_req: 'AS',
        cmb_councillorcheckbox: 'Yes_No.Yes' 
    },
    lat: '45.7204',
    long: '-75.6896',
    first_name: 'f',
    last_name: 's',
    email: 'fs@gmail.com',
    phone: '1231231234',
    service_name: 'Disabled parking spaces',
    user_id: 'BJ01n7HSp1ZDXuWd1IC8SYsho8d2',
    description: parking spot not available,
    category: 'Parking',
    city: 'ottawa',
    media_url: '' 
}

Description

This function uploads the service request issue to the Firebase database.

Return Values

This function returns a promise which resolves nothing.

handleFormUpload(req)

Parameters

Param Description
req The post request body received from any client device.

Description

This function parses the multiform data received from the POST request and creates the params object.

Return Values

This function returns a promise which the parsed parameters.