Skip to content

Commit

Permalink
Nestjs rewrite
Browse files Browse the repository at this point in the history
**As part of this PR the following has been completed:**

- Rewrote the entire project in NestJS

- Reworked the structure of the project to make it easier to identify key areas. With each new section there are various README files which discuss the section.

- Added various unit tests with Vitest to cover all the pieces of functionality with the help of Cursor

- The project is now type safe, all response interfaces are generated from the Graphql schema. Every other interface is manually maintained as the data is from The Open Movie Database's systems OR the desired types couldn't be automated.

- Any environment variables required are now validated via Joi (Would have used zod but couldn't OR you have to do a lot of work just to get it to work)

- Updated the github actions to use yarn latest version.

- Added a "Discover" module to allow users to quickly search for shows or movies, for now this just mimics what the The Open Movie Database discover page is doing. There still some work that needs doing about this, currently it fetches one one page at a time to get this working at the UI layer it'll need to use an infinite query
  • Loading branch information
AlexMachin1997 authored Oct 31, 2024
2 parents ae914cb + 9f931e9 commit 63adef3
Show file tree
Hide file tree
Showing 273 changed files with 25,160 additions and 11,154 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ root = true
[*]
charset = utf-8
indent_size = 2
indent_style = space
indent_style = tab
insert_final_newline = true
max_line_length = 100
trim_trailing_whitespace = true
Expand All @@ -15,4 +15,4 @@ trim_trailing_whitespace = false
indent_style = tab
[*.scss]
indent_size = 2
indent_style = space
indent_style = tab
12 changes: 1 addition & 11 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
./README.md

node_modules/*

*.test.js

package.json

package-lock.json

./.github/workflows/**/*.yml
.github/
141 changes: 91 additions & 50 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,66 +1,107 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2020": true
},
"extends": ["airbnb-base", "prettier", "plugin:import/errors", "plugin:import/warnings"],
"plugins": ["prettier"],
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11
"project": true,
"tsconfigRootDir": ".",
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "sonarjs", "prettier"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"airbnb-base",
"airbnb-typescript/base",
"plugin:sonarjs/recommended",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:prettier/recommended"
],
"ignorePatterns": ["**/node_modules/**", "dist/**", "*.graphql"],
"rules": {
"array-callback-return": "off",
"import/no-extraneous-dependencies": [
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-duplicate-enum-values": "off",
// These rules are for reference only.
//#region eslint
"class-methods-use-this": "off",
// https://github.com/typescript-eslint/typescript-eslint/issues/1277
"consistent-return": "off",
"func-names": "off",
"max-len": ["error", { "code": 140, "ignoreTemplateLiterals": true, "ignoreUrls": true }],
"newline-per-chained-call": "off",
"no-await-in-loop": "off",
"no-continue": "off",
// https://github.com/airbnb/javascript/issues/1342
"no-param-reassign": ["error", { "props": false }],
// https://github.com/airbnb/javascript/issues/1271
// https://github.com/airbnb/javascript/blob/fd77bbebb77362ddecfef7aba3bf6abf7bdd81f2/packages/eslint-config-airbnb-base/rules/style.js#L340-L358
"no-restricted-syntax": ["error", "ForInStatement", "LabeledStatement", "WithStatement"],
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
"no-void": ["error", { "allowAsStatement": true }],
"object-curly-newline": "off",
"spaced-comment": [
"error",
{
"devDependencies": ["**/*.test.js"]
}
"always",
{ "line": { "markers": ["/", "#region", "#endregion"] } }
],
"no-process-exit": "error",
"no-debugger": 0,
"no-alert": 0,
"no-await-in-loop": 0,
"no-return-assign": ["error", "except-parens"],
"no-restricted-syntax": [2, "ForInStatement", "LabeledStatement", "WithStatement"],
"no-unused-vars": "error",
"prefer-const": [
//#endregion

//#region import
"import/extensions": ["error", "never"],
// https://github.com/benmosher/eslint-plugin-import/issues/1753
"import/named": "off",
"import/no-default-export": "error",
"import/order": [
"error",
{
"destructuring": "all"
"groups": [["builtin", "external", "internal"]],
"newlines-between": "always",
"alphabetize": { "order": "asc", "caseInsensitive": true }
}
],
"arrow-body-style": [2, "as-needed"],
"no-unused-expressions": [
2,
{
"allowTaggedTemplates": true
}
"import/prefer-default-export": "off",
//#endregion

//#region @typescript-eslint
"@typescript-eslint/consistent-type-assertions": [
"error",
{ "assertionStyle": "angle-bracket" }
],
"no-param-reassign": [
2,
"@typescript-eslint/naming-convention": [
"error",
{ "selector": "default", "format": ["strictCamelCase"] },
{ "selector": "variable", "format": ["strictCamelCase", "UPPER_CASE", "StrictPascalCase"] },
// https://github.com/microsoft/TypeScript/issues/9458
{
"props": false
}
"selector": "parameter",
"modifiers": ["unused"],
"format": ["strictCamelCase"],
"leadingUnderscore": "allow"
},
{ "selector": "property", "format": null },
{ "selector": "typeProperty", "format": null },
{ "selector": "typeLike", "format": ["StrictPascalCase"] },
{ "selector": "enumMember", "format": ["UPPER_CASE"] }
],
"no-console": 0,
"default-case": 0,
"import/prefer-default-export": 0,
"func-names": "off",
"space-before-function-paren": 0,
"comma-dangle": 0,
"max-len": 0,
"import/extensions": 2,
"no-underscore-dangle": 0,
"consistent-return": 0,
"radix": 0,
"no-shadow": [
2,
"@typescript-eslint/no-extraneous-class": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
//#endregion

//#region sonarjs
"sonarjs/no-duplicate-string": "off",
"sonarjs/cognitive-complexity": ["error", 25],
//#endregion

"prettier/prettier": [
"error",
{
"hoist": "all",
"allow": ["resolve", "reject", "done", "next", "err", "error"]
"singleQuote": true,
"endOfLine": "auto"
}
],

"quotes": [
2,
"single",
Expand All @@ -69,11 +110,11 @@
"allowTemplateLiterals": true
}
],
"prettier/prettier": [

"@typescript-eslint/array-type": [
"error",
{
"singleQuote": true,
"endOfLine": "auto"
"default": "generic"
}
]
}
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/greeting-action.yml

This file was deleted.

70 changes: 28 additions & 42 deletions .github/workflows/linting-action.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,50 @@
# Job name
name: Application Linting
name: Lint

# When the to run the greeting
on: [pull_request, push]

# Jobs to run for the action (You can have multiple actions in one file)
jobs:
run-linters:
# Job display name
name: Running the eslint checks

# Runs on a Linux based OS
name: Run linters
runs-on: ubuntu-latest

# Run the job on Node 20 and 23 which better support modern testing frameworks
strategy:
matrix:
node-version: [20.x, 21.x, 23.x]

# Steps involved for this particular task
steps:
# Checks out the reporsitoy and enables the use of commands made avaliable in the project ie npm run
# Checks out the repository and enables the use of commands made available in the project ie npm run
- name: Check out Git repository
uses: actions/checkout@v2

# Setup Nodes on the versions specified in the matrix stratergy
- name: Set up Node.js version
- name: Set up Node.js version ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: 12
node-version: ${{ matrix.node-version }}

# Cache the node_modules
- name: Cache node modules
uses: actions/cache@v2
- name: Enable Corepack
run: corepack enable

# Defining the cache env config ie the key
env:
cache-name: cache-node-modules
- name: Set Yarn version
run: yarn set version 4.2.2

# Caching options (https://github.com/actions/cache)
- name: Cache yarn dependencies
uses: actions/cache@v2
env:
cache-name: cache-yarn-dependencies
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm

# Key for caching the files initally
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

# Restore keys
path: |
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ runner.os }}-yarn-
# Installs all the project dependencies e.g. prettier, eslint etc via a custom project script
- name: Install Node.js dependencies
run: npm run allDependencies
- name: Install dependencies
run: yarn install

# Run the linting action
- name: Run linters
uses: samuelmeuli/lint-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # Authorizes the github action via a Github token which is for this repo only (Generated automatically)
eslint: true # Enables eslint
prettier: true # Enables prettier to prettieifer the code when commiting and spots any violations
auto_fix: true # Auto fixes an prettier or eslint violations
git_name: 'TheOpenMovieDB-GraphQL-Example BOT'
git_email: '[email protected]'
commit_message: 'TheOpenMovieDB-GraphQL-Example BOT has fixed an eslint/prettier issue' # Might need removing if it causes the linting to break
run: yarn lint
51 changes: 26 additions & 25 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on: [pull_request, push]
jobs:
test:
# Job display name
name: Running the jest tests
name: Running Vitest tests

# Runs on a Linux based OS
runs-on: ubuntu-latest

# Run the job on 2 different versions of Node (12, 14)
# Run the job on Node 20 and 23 which better support modern testing frameworks
strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [20.x, 21.x, 23.x]

# Steps involved for this particular task
steps:
Expand All @@ -30,35 +30,36 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

# Cache the node_modules
- name: Cache node modules
uses: actions/cache@v2
# Enable Corepack for Yarn
- name: Enable Corepack
run: corepack enable

# Defining the cache env config ie the key
env:
cache-name: cache-node-modules
# Set Yarn version
- name: Set Yarn version
run: yarn set version 4.2.2

# Caching options (https://github.com/actions/cache)
# Cache the yarn dependencies
- name: Cache yarn dependencies
uses: actions/cache@v2
env:
cache-name: cache-yarn-dependencies
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm

# Key for caching the files initally
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

# Restore keys
path: |
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
${{ runner.os }}-yarn-
# Installs all the project dependencies e.g. prettier, eslint etc via a custom project script
- name: Install Node.js dependencies
run: npm run allDependencies
# Install dependencies using Yarn
- name: Install dependencies
run: yarn install

# Run the react-testing-library tests
# Run the Vitest tests
- name: Run all tests
env:
OPEN_MOVIE_DB_API_URI: ${{ secrets.OPEN_MOVIE_DB_API_URI }}
OPEN_MOVIE_DB_API_KEY: ${{ secrets.OPEN_MOVIE_DB_API_KEY }}
run: npm run test
run: yarn test
Loading

0 comments on commit 63adef3

Please sign in to comment.