Skip to content

Commit 63d102c

Browse files
authored
refactor(#74): change main framework to nest
1 parent 14ed7c0 commit 63d102c

File tree

135 files changed

+7533
-7529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+7533
-7529
lines changed

.env

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
PORT=4000
2-
HOST=http://localhost:
1+
DATABASE_URL="mysql://heroes:heroes@mysql/heroes"
2+
DATABASE_USER=heroes
3+
DATABASE_PASSWORD=heroes
4+
DATABASE_NAME=heroes

.env.example

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
2-
PORT=4000
3-
HOST=http://localhost:
1+
DATABASE_URL=

.eslintrc.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
},
24+
};

.gitignore

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1-
generated
2-
node_modules/
3-
schema-compiled.graphql
4-
src/.DS_Store
5-
.idea/
6-
.env
1+
# compiled output
2+
/dist
3+
/node_modules
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
pnpm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit "$1"

.husky/pre-commit

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run format
5+
npm run lint

.prettierrc

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"useTabs": false,
3-
"printWidth": 80,
4-
"tabWidth": 2,
52
"singleQuote": true,
6-
"trailingComma": "es5",
7-
"jsxBracketSameLine": true,
8-
"semi": true
9-
}
3+
"trailingComma": "all"
4+
}

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:14-alpine AS development
2+
3+
WORKDIR /app
4+
5+
COPY package.json /app/package.json
6+
COPY package-lock.json /app/package-lock.json
7+
8+
RUN npm install
9+
10+
EXPOSE 3000

README.md

+17-29
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ Before you start, make sure you have [Docker](https://docs.docker.com/install/)
5757

5858
### Documentation
5959

60-
Heroes API documention can be found [here](https://github.com/netguru/heroes-api/wiki).
60+
Documentation can be found, after initial setup, for HTTP in [Swagger](http://localhost:3000/swagger/#/), for GraphQL in [GraphQL Playground](http://localhost:3000/graphql).
61+
62+
Old API documentation can be found [here](https://github.com/netguru/heroes-api/wiki).
6163

6264
### Initial setup
6365

@@ -69,48 +71,34 @@ Heroes API documention can be found [here](https://github.com/netguru/heroes-api
6971
`git clone [email protected]:netguru/heroes-api.git`
7072

7173
2. Launch Docker compose to run Prisma's and MySQL's images.
72-
`docker-compose up -d`
73-
74-
3. Install all the dependencies.
75-
`npm install`
74+
`docker compose up -d`
7675

77-
4. Generate prisma instance based on datamodel.
78-
`npm run generate`
76+
3. Open API container's terminal
77+
`docker compose exec api /bin/sh`
7978

80-
5. Deploy database schema into the MySQL database.
81-
`npm run deploy`
79+
4. Deploy database schema into the MySQL database.
80+
`npx prisma db push`
8281

83-
6. Seed the database with default data.
84-
`npm run seed`
82+
5. Seed the database with default data.
83+
`npx prisma db seed`
8584

8685
### Running the project
8786

88-
#### For REST API
89-
90-
- Run in terminal:
91-
`npm run start:rest`
92-
93-
#### For GraphQL
94-
95-
- Run in terminal
96-
`npm run start:graphql`
87+
After the initial setup there's no additional work needed, project is running in the background as a Docker container.
9788

98-
#### Important
89+
- The API is available on your local machine on `http://localhost:3000`.
90+
- Swagger documentation is available on `http://localhost:3000/swagger/`.
91+
- GraphQL playground is available on `http://localhost:3000/graphql`.
9992

100-
- Deploy new schema (after modifying `datamodel.prisma`)
101-
`prisma deploy`
93+
You can stop it by executing `docker compose stop`, and you can resume it by `docker compose start`
10294

103-
- AFTER MODIFYING `prisma.yml`
104-
`npm run generate`
10595

10696
<!-- Authors -->
10797

10898
## Authors
10999

110-
1. <a href="https://github.com/qmixi" target="_blank">Piotr Kumorek</a>
111-
2. <a href="https://github.com/SebastianStj" target="_blank">Sebastian Stój</a>
112-
3. <a href="https://github.com/slawomirkolodziej" target="_blank">Sławek Kołodziej</a>
113-
4. <a href="https://github.com/Kamieniu" target="_blank">Franciszek Stodulski</a>
100+
1. <a href="https://github.com/serrg" target="_blank">Sergiusz Strumiński</a>
101+
2. <a href="https://github.com/jog1t" target="_blank">Kacper Wojciechowski</a>
114102

115103
<!-- LICENSE -->
116104

datamodel/avatar.prisma

-5
This file was deleted.

datamodel/hero.prisma

-7
This file was deleted.

datamodel/type.prisma

-4
This file was deleted.

docker-compose.yml

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
version: '3'
1+
version: '3.4'
22
services:
3-
prisma:
4-
image: prismagraphql/prisma:1.34
5-
restart: always
6-
depends_on:
7-
- mysql
8-
ports:
9-
- '4466:4466'
10-
environment:
11-
PRISMA_CONFIG: |
12-
port: 4466
13-
databases:
14-
default:
15-
connector: mysql
16-
host: mysql
17-
port: 3306
18-
user: root
19-
password: prisma
203
mysql:
21-
image: mysql:5.7
4+
platform: linux/x86_64
5+
image: mysql:8
226
restart: always
237
environment:
24-
MYSQL_ROOT_PASSWORD: prisma
8+
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
9+
MYSQL_USER: $DATABASE_USER
10+
MYSQL_PASSWORD: $DATABASE_PASSWORD
11+
MYSQL_DATABASE: $DATABASE_NAME
2512
volumes:
2613
- mysql:/var/lib/mysql
14+
15+
api:
16+
platform: linux/x86_64
17+
build:
18+
dockerfile: Dockerfile
19+
context: .
20+
target: development
21+
command: npm run start:dev
22+
environment:
23+
DATABASE_URL: $DATABASE_URL
24+
volumes:
25+
- .:/app
26+
- /app/node_modules/
27+
depends_on:
28+
- mysql
29+
ports:
30+
- "3000:3000"
31+
32+
adminer:
33+
image: adminer
34+
restart: always
35+
ports:
36+
- "8080:8080"
37+
2738
volumes:
2839
mysql: ~

gen-schema.ts

-7
This file was deleted.

nest-cli.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"collection": "@nestjs/schematics",
3+
"sourceRoot": "src"
4+
}

0 commit comments

Comments
 (0)