Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #52 from NavigoLearn/master
Browse files Browse the repository at this point in the history
Pushing V2 to production branch
  • Loading branch information
sopyb authored Sep 12, 2023
2 parents c0659af + d0911e9 commit 3ef35f0
Show file tree
Hide file tree
Showing 105 changed files with 6,489 additions and 10,996 deletions.
18 changes: 12 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"node"
],
"extends": [
"eslint:recommended",
Expand Down Expand Up @@ -31,13 +32,15 @@
"semi": 1,
"indent": [
"warn",
2
2,
{ "SwitchCase": 1 }
],
"quotes": [
"warn",
"single"
],
"node/no-process-env": 1,
"no-process-env": "error",
"node/no-process-env": "error",
"node/no-unsupported-features/es-syntax": [
"error",
{
Expand All @@ -51,9 +54,12 @@
],
"node/no-missing-import": 0,
"node/no-unpublished-import": 0,
"@typescript-eslint/unbound-method": ["error", {
"ignoreStatic": true
}]
"@typescript-eslint/unbound-method": [
"error",
{
"ignoreStatic": true
}
]
},
"settings": {
"node": {
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/eslintcodescan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# ESLint is a tool for identifying and reporting on patterns
# found in ECMAScript/JavaScript code.
# More details at https://github.com/eslint/eslint
# and https://eslint.org

name: ESLint

on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '18 4 * * 6'

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: write # required to comit eslint fix
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install ESLint
run: |
npm install --save-dev [email protected]
npm install --save-dev @microsoft/[email protected]
- name: Run ESLint
run: npx eslint .
--config .eslintrc.json
--ext .js,.jsx,.ts,.tsx
--format @microsoft/eslint-formatter-sarif
--output-file eslint-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: eslint-results.sarif
wait-for-processing: true
37 changes: 37 additions & 0 deletions .github/workflows/eslintfix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: ESLint Fix on Push to Master

on:
push:
branches:
- master

jobs:
eslint-fix:
name: Fix ESLint Issues
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install ESLint
run: |
npm install --save-dev [email protected]
npm install --save-dev @microsoft/[email protected]
- name: Run ESLint with --fix
run: npx eslint . --config .eslintrc.json --ext .js,.jsx,.ts,.tsx --fix
continue-on-error: true

- name: Commit files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "Fix ESLint issues"
continue-on-error: true

- name: Push changes
uses: ad-m/github-push-action@29f05e01bb17e6f28228b47437e03a7b69e1f9ef
with:
branch: ${{ github.ref_name }}
github_token: ${{ secrets.PAT }}
continue-on-error: true
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'
token: ${{ secrets.envAccessToken }}
token: ${{ secrets.PAT }}
- uses: actions/setup-node@v1
with:
node-version: '18.x'
Expand Down
113 changes: 74 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Navigo Learn API [![CodeFactor](https://www.codefactor.io/repository/github/navigolearn/api/badge/master)](https://www.codefactor.io/repository/github/navigolearn/api/overview/master)
# Navigo Learn API

| Build Status | Badge |
|:------------:|:--------------------------------------------------------------------------------------------------------:|
| Production | ![Build Status](https://github.com/navigolearn/api/actions/workflows/test.yml/badge.svg?branch=prod) |
| Master | ![Build Status](https://github.com/navigolearn/api/actions/workflows/test.yml/badge.svg?branch=master) |

## ! This is a work in progress !

Expand All @@ -17,41 +22,71 @@ MariaDB.

Documentation for the api can be found [here](docs/paths/README.md).

## Available Scripts

### `npm run dev`

Run the server in development mode.

### `npm test`

Run all unit-tests with hot-reloading.

### `npm test -- --testFile="name of test file" (i.e. --testFile=Users).`

Run a single unit-test.

### `npm run test:no-reloading`

Run all unit-tests without hot-reloading.

### `npm run lint`

Check for linting errors.

### `npm run build`

Build the project for production.

### `npm start`

Run the production build (Must be built first).

### `npm start -- --env="name of env file" (default is production).`

Run production build with a different env file.

## Additional Notes

- If `npm run dev` gives you issues with bcrypt on MacOS you may need to
run: `npm rebuild bcrypt --build-from-source`.
# Getting Started

## Prerequisites

- [Node.js](https://nodejs.org/en/) - v16 or higher
- [MariaDB](https://mariadb.org/) - v10.6 or higher
- [Git](https://git-scm.com/) - v2.32 or higher

## Installation

1. Clone the repo
```sh
git clone [email protected]:NavigoLearn/API.git
```

2. Install NPM packages
```sh
npm install
```

3. Create a MariaDB database
```sh
CREATE DATABASE navigo_learn;
USE navigo_learn;
CREATE USER 'navigo_learn'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON navigo_learn.* TO 'navigo_learn'@'localhost';
```

4. Rename the env.example folder to env and fill in the values for
development.env

5. Run tests to make sure everything works
```sh
npm test
```

6. Run the server
```sh
npm run dev
```

## Structure of the Project

The project is split into 4 main folders:

- `src` - Contains all the source code for the project.
- `spec` - Contains all the unit-tests for the project.
- `docs` - Contains all the documentation for the project.
- `env` - Contains all the environment files for the project. (rename the
env.example folder to env to use it)

### `src`

The `src` folder is split into multiple main folders:

- `constants` - Contains constants used in the project. (HTTP status codes, env
variables, etc.)
- `controllers` - Contains the controllers of the project.
- `middleware` - Contains middleware used in the project. (session, etc.)
- `models` - Contains the data models for the project. (Roadmap, User, etc.)
- `routes` - Contains the routers pointing to controllers. (auth, users, etc.)
- `sql` - Contains sql files used in the project. (create tables, metrics, etc.)
- `utils` - Contains utility functions used in the project. (databaseDriver,
etc.)
- `validators` - Contains the validators used in the project. (user, roadmap,
etc.)
- `index.ts` - The entry point.
- `server.ts` - The server.
36 changes: 36 additions & 0 deletions docs/available-scripts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### `npm run dev`

Run the server in development mode.

### `npm test`

Run all unit-tests with hot-reloading.

### `npm test -- --testFile="name of test file" (i.e. --testFile=Users).`

Run a single unit-test.

### `npm run test:no-reloading`

Run all unit-tests without hot-reloading.

### `npm run lint`

Check for linting errors.

### `npm run build`

Build the project for production.

### `npm start`

Run the production build (Must be built first).

### `npm start -- --env="name of env file" (default is production).`

Run production build with a different env file.

## Additional Notes

- If `npm run dev` gives you issues with bcrypt on MacOS you may need to
run: `npm rebuild bcrypt --build-from-source`.
2 changes: 1 addition & 1 deletion env
Submodule env updated from fcef61 to a9f299
36 changes: 36 additions & 0 deletions env.example/development.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Environment ##
NODE_ENV=development

## Server ##
PORT=3001
HOST=localhost

## Setup jet-logger ##
JET_LOGGER_MODE=CONSOLE
JET_LOGGER_FILEPATH=jet-logger.log
JET_LOGGER_TIMESTAMP=TRUE
JET_LOGGER_FORMAT=LINE

## Authentication ##
COOKIE_DOMAIN=localhost
COOKIE_PATH=/
SECURE_COOKIE=false
COOKIE_SECRET=xxxxxxxxxxxxxx
# expires in 3 days
COOKIE_EXP=259200000

## Database Authentication
MARIADB_HOST=localhost
MARIADB_USER=xxxxxxx
MARIADB_PASSWORD=xxxxxx
MARIADB_DATABASE=xxxxxxx

## Google Authentication
GOOGLE_CLIENT_ID=xxxxxxxxx
GOOGLE_CLIENT_SECRET=xxxxxxxxx
GOOGLE_REDIRECT_URI=xxxxxxxxxxx

## GITHUB Authentication
GITHUB_CLIENT_ID=xxxxxxxxxxx
GITHUB_CLIENT_SECRET=xxxxxxxxxxxx
GITHUB_REDIRECT_URI=xxxxxxxxxxxxxx
36 changes: 36 additions & 0 deletions env.example/production.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Environment ##
NODE_ENV=production

## Server ##
PORT=3001
HOST=localhost

## Setup jet-logger ##
JET_LOGGER_MODE=CONSOLE
JET_LOGGER_FILEPATH=jet-logger.log
JET_LOGGER_TIMESTAMP=TRUE
JET_LOGGER_FORMAT=LINE

## Authentication ##
COOKIE_DOMAIN=localhost
COOKIE_PATH=/
SECURE_COOKIE=false
COOKIE_SECRET=xxxxxxxxxxxxxx
# expires in 3 days
COOKIE_EXP=259200000

## Database Authentication
MARIADB_HOST=localhost
MARIADB_USER=xxxxxxx
MARIADB_PASSWORD=xxxxxx
MARIADB_DATABASE=xxxxxxx

## Google Authentication
GOOGLE_CLIENT_ID=xxxxxxxxx
GOOGLE_CLIENT_SECRET=xxxxxxxxx
GOOGLE_REDIRECT_URI=xxxxxxxxxxx

## GITHUB Authentication
GITHUB_CLIENT_ID=xxxxxxxxxxx
GITHUB_CLIENT_SECRET=xxxxxxxxxxxx
GITHUB_REDIRECT_URI=xxxxxxxxxxxxxx
Loading

0 comments on commit 3ef35f0

Please sign in to comment.