### Creating Functions
--- 

**The official documentation for Cloud Functions is found at: [Cloud Functions Documenation](https://firebase.google.com/docs/functions)**

> **To run your updated function code, remember to `npm run build` when inside the functions directory, as the functions are all imported to `index.ts` which is then built and pointed to as the main file for executing functions**

Firebase allows for the use of two different types of functions, [V1 and V2](https://firebase.google.com/docs/functions/version-comparison). At the time of writing this documentaion, V2 functions are not well implemented for testing purposes and are much more difficult to run configurations and mocks with.

For that reason, we will be using V1 functions since it it is still on LTS and will not be deprecated in the near future.

An example is below:

```typescript
export const newProviderCreated = functions.firestore
    .document('/Collection/{documentId}')
    .onCreate(async (change, context): Promise<any> => {
    
    const { documentId } = context.params;
    const documentRef = change.data();
    
    const nameUppercased: string = documentRef.name ?? 'generic name';
    // Assume the documents stored in `Collection` have a name field.
    await change.ref.update({ name: nameUppercased.toUpperCase() });

    return true;
});
```

The above function will grab a reference to the document that was created (which is captured by the `onCreate` background trigger) and converts the value of the name field to uppercase and saves it in the database.

There are many more different triggers and functions we can use for back-end logic rather than keeping it in the front-end.

We recommend to use callable functions as they allow for flexibility without having to use a third party package like `axios` to send requests.

> NOTE: Please use the [https-result model](../src/models/https-result.models.ts) as the return for most functions to mimic the `response` of an https call. This allows you to return a status with a body message, a status code, a custom message and a custom result.