Skip to content

Commit

Permalink
added all events endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ahnaf committed Sep 9, 2024
1 parent 3922029 commit 7a14bdd
Show file tree
Hide file tree
Showing 33 changed files with 2,969 additions and 731 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Deploy to Railway

on:
push:
branches:
- develop
paths-ignore:
- 'README.md'

env:
AZURE_WEBAPP_NAME: bookify
NODE_VERSION: '20.x'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Create .env file
run: |
echo "SQLITE_DB=${{ secrets.SQLITE_DB }}" >> .env
echo "TYPEORM_CLI=${{ secrets.TYPEORM_CLI }}" >> .env
echo "APP_PORT=${{ secrets.APP_PORT }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env
echo "OAUTH_REDIRECT_URL=${{ secrets.OAUTH_REDIRECT_URL }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "${{ secrets.ROOMS }}" > ./src/config/rooms.ts
- name: Install Dependencies
run: npm install

- name: Run database migrations
run: npm run migration:run

- name: Build project
run: npm run build

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app

- name: Install Railway
run: npm i -g @railway/cli

- name: Deploy
run: railway up --service bookify
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
72 changes: 72 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy to Azure App Service

on:
push:
branches:
- main
paths-ignore:
- 'README.md'

env:
AZURE_WEBAPP_NAME: bookify
NODE_VERSION: '20.x'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v3

- name: Setup Node.js version
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'

- name: Create .env file
run: |
echo "SQLITE_DB=${{ secrets.SQLITE_DB }}" >> .env
echo "TYPEORM_CLI=${{ secrets.TYPEORM_CLI }}" >> .env
echo "APP_PORT=${{ secrets.APP_PORT }}" >> .env
echo "NODE_ENV=${{ secrets.NODE_ENV }}" >> .env
echo "OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }}" >> .env
echo "OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }}" >> .env
echo "OAUTH_REDIRECT_URL=${{ secrets.OAUTH_REDIRECT_URL }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "${{ secrets.ROOMS }}" > ./src/config/rooms.ts
- name: Install Dependencies
run: npm install

- name: Run database migrations
run: npm run migration:run

- name: Build project
run: npm run build

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: .

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: .
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

*.sqlite

# dotenv environment variable files
.env
.env.development
Expand Down
133 changes: 64 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,95 @@
![image](https://github.com/user-attachments/assets/c624fbc6-5673-4c85-ae4a-74d298b73089)

# Get started
1. Place the `.env.development` file or `.env` file in the root dir
2. place the `rooms.ts` file in `src/config` which contains the room specific infos
3. [optional] Place the `dump.sql` file in the root dir if you want to create the database for the first time using docker container
2. To obtain the list of meeting spaces that are allocated for your organization, use the [Google directory API](https://developers.google.com/admin-sdk/directory/reference/rest/v1/resources.calendars/list?apix_params=%7B%22customer%22%3A%22my_customer%22%2C%22maxResults%22%3A20%7D) to obtain the list and format them according to `src/calender/interfaces/room.interface.ts`. Finally place the file as `rooms.ts` file in `src/config`.
3. Run `npm run migration:run` to create the migrations
4. Run the app using: `npm run start:dev`
5. Run the client using `npm run start:client`


## How it works

### List available rooms

```bash
rooms <min-seat-count> <start-time> <duration>

# e.g:
# rooms 1 -> shows list of available roo
curl
--location --globoff '{{baseUrl}}/rooms' \
--header 'Authorization: Bearer <token>'
```

### Book room

```bash
book <min-seat-count> <start-time> <duration> <floor?>
curl
--location --globoff '{{baseUrl}}/room' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"startTime": "2024-08-31T10:30:00+06:00",
"duration": 30,
"seats": 1,
"floor": 1,
"createConference": true,
"title": "Quick meeting API",
"attendees": []
}'

# e.g:
# book 1 3:30pm 30m f2 -> finds the closest available room on f2 with a min room capactiy of 1.
```

### Update room

```bash
rooms --booked

room --id=1 duration=+30m
# todo
```


### Delete room

```bash

rooms --booked
unbook --id=1
curl
--location --globoff --request DELETE '{{baseUrl}}/room' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"eventId": "4r4bddp2bfkgg1tic1vh84sit8"
}'

```

## Todo

```
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix_params=%7B%22resource%22%3A%7B%22timeMin%22%3A%222024-08-27T00%3A00%3A00%2B02%3A00%22%2C%22timeMax%22%3A%222024-09-27T23%3A59%3A59%2B02%3A00%22%2C%22items%22%3A%5B%7B%22id%22%3A%22Ada%20Bit%2010%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22c_1888flqi3ecr4gb0k9armpk8k9ics%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22RESOURCE_ID_3%40resource.calendar.google.com%22%7D%5D%7D%7D
in the playground paste this request:
{
"timeMin": "2024-08-27T00:00:00+02:00",
"timeMax": "2024-09-27T23:59:59+02:00",
"timeZone": "Asia/Dhaka",
"items": [
{
"id": "Ada Bit [email protected]"
},
{
"id": "[email protected]"
},
{
"id": "[email protected]"
}
]
}
```
- add some sort of mutex or a buffer to prevent race conditions

## Commands

## Github actions

The following env secrets needs to be configured in the github repository:

```bash
npm run start:database
APP_PORT=
AZURE_WEBAPP_PUBLISH_PROFILE=
ROOMS=
SQLITE_DB=
TYPEORM_CLI=
```

# Database setup
## Deployment

## Starting from scratch

A database dump file is required. Paste the dump file (`dump.sql`) in the root directory and run the following commands to create a docker container and initialize the database with the dump file.
Make sure to create the following environment secrets in the Azure App service:

```bash
npm run start:database
APP_PORT=
AZURE_WEBAPP_PUBLISH_PROFILE=
JWT_SECRET=
OAUTH_CLIENT_ID=
OAUTH_CLIENT_SECRET=
OAUTH_REDIRECT_URL=
SQLITE_DB=
TYPEORM_CLI=
APP_DOMAIN=
```

## Note

Make sure you have the `.env` file. Not the `.env.development`, as the docker env variables are loaded from `.env` by default.
## Commands

### Entering docker container's mysql

Expand All @@ -94,27 +98,7 @@ docker exec -it <containerid> sh # to enter a container's bash
mysql -uroot -proot # to enter mysql
```

### MySql workbench
When connecting the database with a workbench, make sure to turn the following values (if required):

- allowPublicKeyRetrieval=true
- useSSL=false

More: https://stackoverflow.com/a/50438872

## Importing database dump for existing container

Assuming you have the dump file `dump.sql` in the root dir, the following steps must be followed:

Run steps (1-3) if you are running it with docker container:

1. Find the docker container id using `docker ps`
2. Copy the dump file into the docker container: `docker cp dump.sql <container_id>:/dump.sql`
3. Enter into the docker container's shell: `docker exec -it <container_id> /bin/bash`
4. Run this command: `mysql -u<user_name> -p<password> oj_db < dump.sql` where `user_name`=root and `password`=root


## Migrations
### Migrations

Once you get into production you'll need to synchronize model changes into the database. Typically, it is unsafe to use `synchronize: true` for schema synchronization on production once you get data in your database. Here is where migrations come to help.

Expand Down Expand Up @@ -180,3 +164,14 @@ TypeORM is able to automatically generate migration files with schema changes yo
npm run migration:generate
```
You don't need to write the queries on your own. The rule of thumb for generating migrations is that you generate them after **each** change you made to your models.


## Reference

- [Google Free busy API](https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix_params=%7B%22resource%22%3A%7B%22timeMin%22%3A%222024-08-27T00%3A00%3A00%2B02%3A00%22%2C%22timeMax%22%3A%222024-09-27T23%3A59%3A59%2B02%3A00%22%2C%22items%22%3A%5B%7B%22id%22%3A%22Ada%20Bit%2010%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22c_1888flqi3ecr4gb0k9armpk8k9ics%40resource.calendar.google.com%22%7D%2C%7B%22id%22%3A%22RESOURCE_ID_3%40resource.calendar.google.com%22%7D%5D%7D%7D )

- [Resources API](https://developers.google.com/admin-sdk/directory/reference/rest/v1/resources.calendars/list?apix_params=%7B%22customer%22%3A%22my_customer%22%2C%22maxResults%22%3A20%7D)

- [Hosting on Azure App Service](https://docs.github.com/en/actions/use-cases-and-examples/deploying/deploying-nodejs-to-azure-app-service)

- [Azure file system](https://github.com/projectkudu/kudu/wiki/Understanding-the-Azure-App-Service-file-system)
Loading

0 comments on commit 7a14bdd

Please sign in to comment.