# Assign Task

### Input parameters

* TaskID
* Email-Adress of Assigned member

### How to call from app

<pre><code>import { httpsCallable } from 'firebase/functions';

<strong>await httpsCallable(functions, 'assignTask')({ taskId, email })
</strong></code></pre>

### Logic

Miro: <https://miro.com/app/board/uXjVPbexhys=/?share_link_id=959063091369>

As a user, i want to assign tasks directly to an email address.

How to check if user exists? Checkout: <https://stackoverflow.com/questions/51562995/how-can-i-check-if-user-exists-in-firebase>

**TO BE CONTINUED!!!**

<mark style="color:green;">**If the user with email address exists: {**</mark>

1. get uid of user by Email adress
2. ~~get user document in DB (users/uid)~~&#x20;
   1. ~~add the **ProjectId** to the **thirdPartyProjects** array~~
   2. ~~Then add  the **taskId** to the **assignedTasks** array~~

<mark style="color:green;">**}**</mark>

1. ~~Changes in the Project (/projects/projectId)~~
   * ~~Change the databaseStatus of the task in the project document to "assigned".~~
   * ~~Add the email address of the assigned person to members array~~
   * ~~add a field to the tasks array element that has the TaskId "assignedTo" add the uid as value~~

[![Bildschirmfoto 2022-11-08 um 11 24 03](https://user-images.githubusercontent.com/22271360/200467758-bd531934-b7c6-41fe-86c1-ecae0a5beba2.png)](https://user-images.githubusercontent.com/22271360/200467758-bd531934-b7c6-41fe-86c1-ecae0a5beba2.png)

2\. Add user email to "projects/{projectId}/members" array&#x20;

~~3. Move the Tasks from its previous position to here: (/tasks/assigned/all/taskId) and delete the copy in the old database position.~~

3\. Add user (developer) email to "tasks/{taskId}.assignToEmail"

<mark style="color:green;">**If the user with email address exists: {**</mark>

4\. Send First Email:

* to\_email\_adress = email\_of\_assigned\_person
* template\_name = "tasks-assigned->developer"
* data = {taskData: taskData, taskId: taskId}

<mark style="color:green;">**}**</mark>

<mark style="color:red;">**If the user with email address does NOT exists: {**</mark>

Send Emial:

* to\_email\_adress = email\_of\_assigned\_person
* template\_name = "tasks-assigned->new-user"
* data = {taskData: taskData, taskId: taskId}

<mark style="color:red;">**}**</mark>

5\. Send Second Email:

* to\_email\_adress = email\_of\_task\_creator
* template\_name = "tasks-assigned->creator"
* data = {taskData: taskData, taskId: taskId}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tasksource.io/api-documentation/tasks/assign-task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
