Skip to content

Worktez API Documentation

Sanjay Krishna S R edited this page Oct 29, 2022 · 2 revisions

INTRODUCTION

Application Programming Interface(API) is a set of functions that allow for creation of applications that access data and other features of other applications, services or operating systems.

Where to find APIs in our code?

Go to the code

  • functions
  • model
    and you will find the list of APIs.

Lib.js (available in every API)

The lib.js file is the only place within the API where the db is accessed. This db is exported from the lib.js within the application folder.


1. APPLICATION

Application API is used for the basic data of the app.
The Application API resides in the following structure:
It contains of only one file:

Lib.js

The following functions are present within the lib.js-

1. setApplication()

collects information and stores in the given properties which are then stored in firebase. It then returns a promise.

2. updateApplication()

function works similar to setApplication() except only the fields which need to be updated are passed as parameters in the form of a JSON object.

3. getApplication()

function is called to obtain the data of the app.If the doc exists, the doc data is returned in the form of a promise.

4. createSprintName()

function creates a sprint name by taking sprintId as a parameter.

  • If sprintId is -1 then it returns “Backlog”
  • If sprintId is -2 then it returns “Deleted”
  • Else it returns the sprint number.

2. ACTIVITY

The activity API is used for various functions such as addActivity, getActivity, etc.
The Activity API reside in the following structure:
It consists of the following files:

addActivity.js

This file basically deals with the organization's activity collection in the database and helps in tracking the actions taken on every task.
The addActivity() function has various arguments.

  • A new promise is created to store getActivities, if activityDoc is not undefined then the activity gets updated in updateActivities(),else set new activity using setActivities().
  • Then the promise is returned with a message or an error depending on the case.
  • A new function createActivityId with argument actionId returns the latest activityId.

lib.js

There are four functions in this file:

1. setActivities()

Is called with all the fields present in the firestore database.Here, the fields are set to the values that are passed as parameters and a promise is returned.

2. updateActivities()

Works similar to setActivities. The only difference is that here, the fields which need to be updated are passed as parameters in the form of a JSON object.

3. getActivities()

Requires the orgDomain , taskId as the parameters and returns the activity details corresponding to that particular parameter , if it exists. It then returns a promise.

4. setAction()

Is called with all the fields present in the firestore database.Here, the fields are set to the values that are passed as parameters and a promise returned.


3. EMAIL

When a new member is to be added to a team, email API generates an email that will be sent to the person as an invite to join the team.

The email API resides in the following structure:

lib.js

There is only one function in this file.

1. sendMail()
function accepts arguments related to information which is required to generate an invitation email.A promise is returned at the end.


4. ORGANIZATION

The Organization API is used for creating and updating Organizations and also to get and update applications.
The Organization API resides under the following structure:

organization.js :

The organization.js file is the starting point for all API calls related to organisations. Every call to the API is forwarded to the organization.js file. The required functions are imported using the require function.
The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.
The onRequest() event has two arguments -

  1. Request object gives you access to the properties of the HTTP request sent by the client.
  2. Response object gives you a way to send a response back to the client.
    The mode is fetched from the body of the data brought by the request and checked if the mode is ‘create’. To create the createOrg(request, response) is called.

createOrg.js

In this an organization is auto setup using firebase tools and fetch application data and update applications.

  1. setOrg , getOrg - functions present in lib.js.
  2. getOrgRawData - fetch the organization data.
  3. setOrgRawData - auto setup organization data.

All the details passed in through the body of the request are stored in variables for easy access.
In the first promise The organization is obtained using the createOrg function and then the getOrg(orgDomain) is called to check if the organization is undefined or not.
If the organization is undefined the setOrg() function is called with all the required details as parameters. Then the firestore resolves the first promise.
In second promise, similarly it checks if AppDeatails document exist in raw data collection of Organization Domain document,
If not it creates a new one and also updates(increments) the TotalNumberOfOrganization in Appdetails of Raw Collection which is not under OrganizationDomain Document.Then Firestore resolves the second promise. API resolves all promises and returns to UI. If the organization is created successfully return "Created Organization Successfully" else return "Error Creating Organization".

lib.js:

There are seven functions present in lib.js.

1. setOrg()
function is called with all the fields present in the firestore database.

To get to the particular Organization, move through:
Organizations > orgDomain.

2. updateOrg()
function works similar to setOrg except only the fields which need to be updated are passed as parameters in the form of a JSON object.

3. The getOrg()
function is called to obtain the data of a particular doc by passing in the orgDomain as a parameter.

4. getOrgUseAppKey()
function is called to fetch the data from the doc for the organization.

5. setOrgRawData()
function is called with all the fields present in firebase tools to get the particular organization

-Organizations > orgDomain > RawData > AppDetails.

6. updateOrgRawData()
function works on which fields need to be updated in the form of a JSON object.

7. getOrgRawData()
function is called to get data of a particular organization.


5. TASKS

The task API is used for creating new tasks , updating tasks , log work and deleting tasks.
The task API recides under the following structure:

tasks.js :

  • The tasks.js file is the entry point for all task related API calls. Every API call made is redirected to the tasks.js file. First the required functions are imported using the require function which is the easiest way to include modules that exist in separate files.

  • The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.

  • The onRequest() event has two arguments - request and response.

    1. Request object gives you access to the properties of the HTTP request sent by the client
    2. Response object gives you a way to send a response back to the client.
  • The cors support is also enabled using the cors code block.

  • The mode is fetched from the body of the data brought by the request and checked if the mode is ‘create’ , ‘edit’, ‘delete’ or ‘update log work’.

    • If the mode is ‘create’ the createNewTask(request, response) is called.
    • If it is ‘edit’ the editTask(request, response) is called.
    • If it is ‘delete’ the deleteTask(request, response) is called.
    • If it is ‘log’ the logWork(request, response) is called.

createTask.js

This is used to create a new task. The various functions required for creating a new task are imported using the require function:

  • createSprintName: assigning the sprint in which tasks need to be completed.
  • addActivity: create task and gives details of task
  • getOrgUseAppKey: use to get orgDetails and organization id.
  • getOrgRawData,updateOrgRawData: for obtaining organization’s data by passing orgDomain and for updating organization’s data .
  • getSprint , updateSprint , setSprint : update the sprint if more tasks are added.
  • updateTeamDetails , getTeam : assigning team to complete task.
  • setTask : function present in lib.js.

All the details passed in through the body of the request are stored in variables for easy access.
In the first promise made , we assign a team to perform the task using getTeam , updateTeamDetails. Once the team is assigned then we call the function setTask and addActivity which will provide all the details for creating tasks.
Then the second promise is made , we have to assign the sprint in which tasks need to be completed. This will be done by using getSprint and updateSprint. If the sprint is undefined the setSprint function is called with all the required details as parameters to create a new sprint.
When API resolves all the promises and returns to UI and the task is created then return “ Task created successfully” else return “ error creating task”.

deleteTask.js :

The deleteTask.js is used to delete a particular task which was already created.The API receives all the data from task data sent by the user and it also computes new data which are required.In deleteTaskPromise promise, API tries to get the document AppKey=appKey from Organization.
Using getOrgUseAppKey. For each document it gets an Organization Domain.
First in the 1st promise, it will get the taskId document from the Task collection of Organization Domain Document.Then the API will update SprintNumber to -2 to tell the application it is a deleted task.
Then in the 2nd promise, we will get the sprintId document from Sprints Collection of Organization Domain Document.Then We get the totalNumberOfTask, totalCompletedTask and totalUncompletedTask. If task status is completed then compute new values of totalCompletedTask and totalUncompletedTask.
Then Update the above variables in the firestore.Call addActivity API. Resolve all promises and Return to UI.
If the task got deleted return "deleted task successfully" else return "error deleting task" .

editTask.js :

editTask.js is used to edit the task.The API receives all the data from task data sent by the user and it also computes new data which are required.
In editTaskPromise promise, get all the documents with AppKey = appKey in the Organizations collection. Using getOrgUseAppKey. For each item get the Organization Domain.
If editedSprintNumber is not equal to previousId then in the first promise, get the task data from previousSprintId document of Sprints collection in Organization Domain document.After this, compute the new values of task data and Update the task data in firstore.
Then in the 2nd promise, get the editedSprintId document from Sprints collection of documentId document.If Document Exists ,get the task data and compute the new values and then Update the new task data in Firstore in a promise.
Else initialize all the task data and make the new changes in it and then create a new document with editedsprintId name in Sprints collection .
In the 3rd promise, get the taskId document from the tasks collection of the Organization Domain document.
Then Update all the new task data in it and store it in firestore.Call addActivity API .Then Resolve all promises and return to UI. If the task is updated successfully return "edited task successfully" else return "error editing task"

logwork.js :

logwork.js is used to store the log data for tasks and store it in a firestore.
In logTaskPromise promise, get all the documents with AppKey=appKey and get the organization domain from the document.Then in the first promise, get the document with taskId document in Tasks collection of Organization Domain document.
Get the logWorkTotalTime and compute the new value of it.Then If status is completed, compute completion date.Then Update this data in the same document in the firestore.
Then in the second promise, get the document with the AppDeatils document in the RawData collection of Organization Domain documents. Using getOrgUseAppKey.
Get the totalCompletedTask and totalUncompletedTask.Then If status is completed compute new values of the above variables.Then Update this data in the same document in the firestore.
Then in the second promise, get a document with fullSprintId document in Sprints collection of Organization Domain document.
Get the totalCompletedTask and totalUncompletedTask.Then If status is completed compute new values of the above variables.
Then Update this data in the same document in the firestore.Call addActivity APIResolve all the promises and return to UI.
If the work is logged return "logged work successfully" else return "error logging work"

lib.js :

setTask is called with all the fields present in the firestore database. To get to the particular task, move through:
-> Organizations -> orgDomain ->Tasks-> taskId
Here, the fields are set to the values passed as parameters and a promise is returned.
updateTask works similar to setTask except only the fields which need to be updated are passed as parameters in the form of a JSON object.
getTask requires the orgDomain and taskId as the parameters and returns the task details corresponding to that particular taskId, if it exists.


6. PATCHES

The patch API is used for updating the products as the updates are given in the form of patches.
The patch API reside under following structure:

patch.js :

The patch.js file is the entry point for all patch related API calls. Every API call made is redirected to the patch.js file. First the required functions are imported using the require function which is the easiest way to include modules that exist in separate files.
The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.
The onRequest() event has two arguments - request and response.

  • Request object gives you access to the properties of the HTTP request sent by the client
  • Response object gives you a way to send a response back to the client.

The cors support is also enabled using the cors code block.
The mode is fetched from the body of the data brought by the request and checked if the mode is **"patch1" , "patch2", "patch3" , "patch4" or "patchModerator".

  • If the mode is "patch1" the patch1(request, response) is called.
  • If it is "patch2" the patch2(request, response) is called.
  • If it is "patch3" the patch3(request, response) is called.
  • If it is "patch4" the patch4(request, response) is called.
  • If it is "parchModerator" the patchModerator(request, response)is called.

patchModerator.js :

patchModerator.js file is used to create a patch document by using getPatchData() , setPatch() both the functions present in lib.
Then in the first promise we fetch a patch document by using getPatchData().
If the patch is undefined then the setPatch() function is called with all the fields present in the firestore database.
After the promise resolve if the document is created then return "patch document created successfully" or else "error in creating patch document"

setPatch.js :

setPatch.js file is used to create other patches. By using getPatchData() , setPatch() both the functions present in lib. We fetch data from patch1 using getPatchData() if the patch is undefined , setPatch() function is called to create patch1 which fixes all the counters of the team.
Now We fetch data from patch2 using getPatchData() if the patch is undefined , setPatch() function is called to create patch2 which adds a new field to all the tasks with default value.
Now We fetch data from patch3 using getPatchData if the patch is undefined , setPatch() function is called to create patch3 which allows the user to change a particular field in relevant tasks, enter field name and field value to get the task details.

lib.js :

The lib.js file is the only place within the API where the db is accessed. This db is exported from the lib.js within the application folder.

  • setPatch() function is called with all the fields present in the firestore database and to create a patch.
  • updatePatchData() works similar to setTask() except only the fields which need to be updated are passed as parameters in the form of a JSON object.
  • getPatchData() function is called to check if the patch exists or not.

patch1.js :

Patch1.js file is used to fix counters of all the sprints and teams .

First the firebase-firestore is set up using admin access. Then in the first promise we will fetch orgDomain and teamId data to get to the teamDoc using getTeamUseTeamId() and log "executing promise 1 of patch 1." If the total sprint is 0, call createSprintId() . Now create Backlog and Deleted with Default Values if they don't exist by using createBacklogAndDeleted(). Now call sprintCounters().

Then in promise 2 we have to assign task to team through,
Organization > orgDomain > tasks > teamId > team
Then log "executing promise 2 of patch 1"
Then call updateTeamDetails() to update the JSON file here.
If both promises are resolved then return "patch1 executed successfully". And do updatePatchData to log "counters updated" or else log "error occurred in updating counters".
Now call function sprintCounters() , if it shows the added sprint then show status “completed” or else updateSprint to resolve the promise.
Now call function createSprintId() , if it shows sprint no. -1 then return "Backlog" and if sprint no. is -2 then return "deleted"
Now call createBackLogAndDeleted() if the doc does not exist then do setSprint and resolve the promise.

patch2.js:

patch2.js file is used to add a new field to all the tasks with a default value. In first promise we have to get to the task through:
Organization > orgDomain > Tasks > task. And log executing promise 1 of patch2. And call update tasks .
After the promise is resolved, show "OK , patch2 is executed".
And call updatePatchData() to get orgDomain and uid.
If everything goes well log "counters updated" or else log "patch error in updating counters".

patch3.js:

patch3.js file is used to allow the user to change a particular field in relevant tasks, enter field name and field value to get the task details. In first promise we have to get to the field value through:
Organization -> orgDomain -> Tasks -> oldFieldValue -> task. And log executing promise 1 of patch3. And call updateTask() .
After the promise is resolved, show “OK , patch3 is executed”.
And call updatePatchData() to get orgDomain and uid.
If everything goes well log "updated" or else log "patch error in updating value".

patch4.js:

patch4.js file is used to update the uid of previous activities. In promise 1 we get to the activities through:
Organization> orgDomain > Activity > activities.
call updateActivities() to get to the actions through Organization >orgDomain > Activity > activityId > Action > actions .
And log “activity length is” if the length is greater than 0 then log “Action” “for Activity” . Then call updateAction() to get uid .
After the promise is resolved successfully , show "ok , patch4 executed" and "activities updated" else show "patch error in updating activities."

patch5.js:

It updates the user's Id(UId) to a new value if there’s no uid before or if the user updates it.


7. PERFORMANCE CHART

The performanceChart API is used to display performance charts and sprint evaluation graphs.
The performanceChart API reside under following structure:

getUserPerformanceChartData takes input data such as sprint number,assignee,etc.

performanceChart.js provides various charts and graphs according to the situation.

performanceChartData.js


8. SPRINTS

The Sprints API is used for creating, updating, setting, and getting sprints. The Sprints API reside in the following structure:

sprints.js:

The sprints.js file is the entry point for all sprint related API calls. Every API call made is redirected to the sprints.js file. First the required functions are imported using the require function which is the easiest way to include modules that exist in separate files.
The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.
The onRequest() event has two arguments - request and response

  • Request object gives you access to the properties of the HTTP request sent by the client
  • Response object gives you a way to send a response back to the client.

The cors support is also enabled using the cors code block.
The mode is fetched from the body of the data brought by the request and checked if the mode is "create" or "update".
If "create" the createNewSprint(request, response) is called, else if it is "update" the updateSprintStatus(request, response) is called.

createNewSprint.js:

This is used to create a new sprint. The various functions required for creating a new sprint are imported using the require function:

  • createSprintName() - used to create the name of the sprint.
    • If the sprintId is -1, the sprint is under backlog.
    • If the sprintId is -2 is deleted.
    • Else the sprintName is 'S' + sprintId.
  • getSprint(), setSprint(), updateSprint() - functions present in lib.js
  • getOrgUseAppKey() - obtain the organization where AppKey is equal to the one passed.
  • getTeamUseTeamId() - obtain the Team Name using the Team Id.
  • updateTeamDetails() - function present in ../teams/lib to update the details of a team.

All the details passed in through the body of the request are stored in variables for easy access.
The teamName is obtained using the getTeamUseTeamId( ) function and the getSprint(orgDomain, teamName, newSprintIdString) is called to check if the sprint is undefined or not.
If the sprint is undefined the setSprint( ) function is called with all the required details as parameters. Else, the updateSprint( ) is called. The promise is now returned to the point of calling the createNewSprint().
If the Sprint is created successfully, return "Sprint Created Successfully" else return "Error Creating Sprint".

updateSprintStatus.js:

The updateSprintStatus works very similar to createNewSprint. The sprintStatus is obtained from the body of the request along with the currentSprintName, appKey and teamId.
We obtain the team as well as organization and create a json named updateSprintStatusInputJson. This json is passed to the updateSprint function present in lib.js.
If the update is made successfully the promise is returned along with the message "Sprint updated successfully". Else the error is returned along with "Error Updating Sprint".

lib.js:

The lib.js file is the only place within the API where the db is accessed. This db is exported from the lib.js within the application folder. There are three functions present within the lib.js:

  1. setSprint()
  2. updateSprint()
  3. getSprint()
  • setSprint() function is called with all the fields present in the firestore database. To get to the particular sprint, move through:

    Organizations > orgDomain >Teams > teamName >Sprints > SprintName.
    Here, the fields are set to the values passed as parameters and a promise is returned.

  • updateSprint() function works similar to setSprint() except only the fields which need to be updated are passed as parameters in the form of a JSON object.
  • Lastly, the getSprint() function is called to obtain the data of a particular sprint by passing in the sprintName as parameter. If the sprint exists, the sprint data is returned in the form of a promise.

9. TEAMS

The Teams API is used for various functions including:

  1. setTeam- for setting details of new team
  2. updateTeamDetails - update Team Details with given parameters
  3. getTeam - fetch Team Details using Team Name
  4. getTeamUseTeamId - get Team Name using Team Id
  5. createTeam - for creating a new team with given details
  6. updateTeam - for updating the team details (this uses updateTeamDetails and getTeam)
  7. addMember - for adding a new member to the team
  8. removeMember - for removing an existing member from the team.
  9. getAllTeamData - to get all the team data in the organization.
  10. getAllLabels - to get all the labels data in the specified format.

teams.js:

The teams.js file is the entry point for all team related API calls. Every API call made is redirected to the teams.js file. First the required functions are imported using the require function which is the easiest way to include modules that exist in separate files.
The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.
The onRequest() event has two arguments - request and response

  • Request object gives you access to the properties of the HTTP request sent by the client
  • Response object gives you a way to send a response back to the client.

The cors support is also enabled using the cors code block.

The mode is fetched from the body of the data brought by the request and checked if the mode is "create" , "update", "add-member" or "remove-member".

  • If the mode is "create" the createTeam(request, response) is called.
  • If it is "update" the updateTeam(request, response) is called.
  • If it is "add-member" the addMember(request, response) is called.
  • If it is "remove-member" the removeMember(request, response) is called.

createTeam.js:

This is used to create a new team. The various functions required for creating a new team are imported using the require function:

  • firebase-admin() - for CRUD operations from an Admin perspective
  • setTeam, getTeam() - functions present in lib.js
  • getOrg() - for obtaining organization’s data by passing orgDomain
  • updateOrg() - for updating organization’s data
  • setSprint() - for setting of sprint details

All the details passed in through the body of the request are stored in variables for easy access.
The organization is updated with the new teamId of the team to be created. This is done using getOrg() and updateOrg().
Using getTeam we determine if the team already exists or not. If it returns undefined the team doesn’t exist and therefore the setTeam() is called to create and set the new team.
However if the getTeam() doesn’t return undefined, this indicates the team already exists and the result is "Error: Team Exists! Use update team". The result is returned in the form of a promise.
Since this is a new team, the sprints (backlog, deleted) for this team are also defined. If everything works, the result is "Team Created Successfully" else it is "Error Creating Team".

updateTeam.js:

This is used to update an existing team. The various functions required for updating the team are imported using the require function: updateTeamDetails(), getTeam() - functions present in lib.js
All the details passed in through the body of the request are stored in variables for easy access.
Using getTeam() we determine if the team already exists or not. If it doesn’t return undefined, the team exists and therefore the updateTeam() works successfully and the result is "Team Updated Successfully".
However if the getTeam() returns undefined, this indicates the team doesn’t exist and the result is "Error: Team doesn't exist". The result is returned in the form of a promise.

addMembers.js:

This is used to add a member to a team. The various functions required for adding member are imported using the require function:

  • updateTeamDetails() - functions present in lib.js
  • sendVerificationEmail() - for sending the added member a verification mail.
    The "add" variable stores the member to be added. This variable is checked to see if it is an empty string. If not, the add variable is pushed into teamMembers.
    The teamMembers are made as a JSON object.
    The updateTeamDetails() and sendVerification() functions are called and the result is "Member added Successfully". If the add variable is empty the result is "Member not found" and the result is returned as a response.

getAllTeamData.js:

This is used to get all the data of a team within the organization. The data returned here is stored in the service:

  • getAllTeams() - function present in lib.js to get the team data from DB.

getAllLabels.js:

This is used to get all the labels of all the teams present in the organization. It returns in a custom structure for easy usage. The structure is as follows.

image

All the details passed in through the body of the request are stored in variables for easy access.
The data can be accessed with the following format.

teamsLabelsJson["TeamName"]["Scope"]["DisplayName"].ColorCode

removeMember.js:

The email of the team member to be removed will be passed through the request. The index of this is stored in the ‘index’ variable.

If the index is not -1, the splice method is used for removing the member’s email from the team. The splice method accepts two parameters - the starting index and the number of items to be deleted.

The team is now updated by using the updateTeamDetails() and the result is "Member removed Successfully". If the removal is not successful, or if the index passed is -1, the result will be "Error while removing member". The result is returned in the response.

lib.js:

The lib.js file is the only place within the API where the db is accessed. This db is exported from the lib.js within the application folder.

There are four functions present within the lib.js:

  • setTeam() is called with all the fields present in the firestore database. To get to the particular team, move through:

    Organizations > orgDomain >Teams > teamName
    Here, the fields are set to the values passed as parameters and a promise is returned.

  • updateTeamDetails() works similar to setTeam() except only the fields which need to be updated are passed as parameters in the form of a JSON object.
  • getTeam() requires the orgDomain and teamName as the parameters and returns the team details corresponding to that particular teamName, if it exists.
  • getTeamUseTeamId() is a function that requires the orgDomain and teamId as the parameters. This is used to fetch the team details using the teamId.

10. USERS

The Users API is used for creating, updating, setting, and getting sprints. The Users API reside in the following structure:

users.js:

The users.js file is the entry point for all team related API calls. Every API call made is redirected to the users.js file. First the required functions are imported using the require function which is the easiest way to include modules that exist in separate files. The functions.https is used to create a function that handles HTTP events. The event handler for an HTTP function listens for the onRequest() event.
The onRequest() event has two arguments - request and response

  • Request object gives you access to the properties of the HTTP request sent by the client.
  • Response object gives you a way to send a response back to the client.

The cors support is also enabled using the cors code block.
The mode is fetched from the body of the data brought by the request and checked if the mode is:

  • If the mode is "create" the createNewUser(request, response) is called.
  • If it is "update" the updateUser(request, response) is called.
  • If it is "update-theme" the updateTheme(request, response) is called.
  • If it is "verify" the verifyUser(request, response) is called.

createNewUser.js:

This is used to create a new user. The various functions required for creating a new user are imported using the require function:

  • setApplication() - for setting details of the application
  • getApplicationData() - for fetching the details of a particular application
  • setUser(), getUser() - functions defined in lib.js

All the details passed in through the body of the request are stored in variables for easy access.
Using the userId that is passed, a new user is created using the setUser function. After successful creation, the user is logged in to the application and the result is "User Logged In Successfully". Else it is "Error LogIn/SignUp User".

updateUser.js:

This is used to update an existing user. The various functions required for updating an user are imported using the require function:

  • updateUser()- function defined in lib.js

All the details passed in through the body of the request are stored in variables for easy access.
The details to be updated are bundled into a JSON object and this, along with the UserId is passed as parameters when calling the updateUser() function.
This function updates the user details and if successful returns User Profile updated successfully" else it returns "Error".

addUserEmail.js:

This function is used to send a verification email to a user. The various functions required for updating an user are imported using the require function:

  • sendMail() - function defined in ../email/lib.js - this send an email to the user in the given template format.

All the details passed in through the body of the request are stored in variables for easy access.
And these details are passed in to the sendMail function and the result returned is ‘0’ if the mail is successfully sent or it returns "Error".

updateDateOfJoining.js:

This function is used to update the date of joining for a particular user. The various functions required for updating the date of joining are imported using the require function:

  • updateUser(), getUserUseEmail() - functions defined in lib.js

The updateDateOfJoining() accepts two parameters - memberEmail and date(new date to be updated). The getUserUseEmail() function is used to obtain the user’s id using the memberEmail.

Using the UserId, if the previousDateOfJoining is null, the DateOfJoining is updated to the new date and added to a JSON object. The updateUser function is called by passing the UserId and the JSON object just created.
The result is returned in the form of a Promise.

updateTheme.js:

This function is used to update the theme of the application. The various functions required for updating the theme are imported using the require function:

  • updateUser() - function defined in lib.js

All the details passed in through the body of the request are stored in variables for easy access.
The appTheme is bundled into a JSON object. This object along with the UserId, is passed as parameters in the updateUser function call and the response is returned. If the theme is not updated successfully the error is returned as response.

verifyUser.js:

This function is used to verify a user upon login. The various functions required for verifying the user are imported using the require function:

  • getOrg() function to retrieve the organization the user belongs to by passing the orgDomain.
  • getTeam() function to retrieve the team the user belongs to by passing the orgDomain and the teamName
  • getUserUseEmail(), updateUser() functions defined in lib.js

All the details passed in through the body of the request are stored in variables for easy access.
Using the getTeam() function we obtain the details of the team the user is in. In the team, if the user is present in teamMembers, we use getOrg() to obtain the organization the user is in.
The organization and the team the user is in, is updated using a JSON object which is passed into the updateUser() function.
If this verifying process is completed successfully, the response is returned as "User Verified Successfully" else it is returned as "Error".

lib.js:

The lib.js file is the only place within the API where the db is accessed. This db is exported from the lib.js within the application folder.

There are four functions present within the lib.js file:

  • setUser()
  • updateUser()
  • getUser()
  • getUserUseEmail()

setUser() is called with all the fields present in the firestore database. To get to the particular user, move through:

Users > Uid

Here, the fields are set to the values passed as parameters and a promise is returned.

updateUser() works similar to setTeam() except only the fields which need to be updated are passed as parameters in the form of a JSON object.
getUser() requires the Uid (UserId) as the parameter and returns the user details corresponding to that particular Uid, if it exists.
getUserUseEmail() requires the user’s email as the parameter and this returns the details of the user corresponding to that email.


Clone this wiki locally