Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
fe76abb
init project
rafael4141 Feb 7, 2023
494d51a
feature: add gitignore
rafael4141 Feb 7, 2023
ca228f2
feature: add typescript in project and configure
rafael4141 Feb 7, 2023
fa1767f
feature: add eslint and configure
rafael4141 Feb 7, 2023
8703b6e
chore: update rules of eslint
rafael4141 Feb 9, 2023
c177bc5
chore: update .gitignore
rafael4141 Feb 9, 2023
1cd370f
chore: update tsconfig
rafael4141 Feb 9, 2023
36e7e0a
feature: add brewery domain
rafael4141 Feb 9, 2023
1d576db
chore: add command build
rafael4141 Feb 9, 2023
1a014ba
chore: add command start
rafael4141 Feb 9, 2023
6b1fc82
chore: add package ts-node
rafael4141 Feb 9, 2023
c7b90da
chore: add command dev
rafael4141 Feb 9, 2023
aed156c
chore: add @types/node package
rafael4141 Feb 9, 2023
5c5d9ad
chore: add prisma package
rafael4141 Feb 9, 2023
fe949a0
feature: add prisma schema
rafael4141 Feb 9, 2023
1fd7342
feture: add migration
rafael4141 Feb 9, 2023
7d25731
feature: add seed
rafael4141 Feb 9, 2023
2810468
chore: add command of seed
rafael4141 Feb 9, 2023
08d361e
feature: add docker-compose.yml and postgres database
rafael4141 Feb 9, 2023
ccf8a5b
chore: add jest package and config jest
rafael4141 Feb 9, 2023
4729e43
chore: add command test:watch
rafael4141 Feb 9, 2023
ae0099e
chore: add faker-js package
rafael4141 Feb 9, 2023
4b1bac0
chore: include src and tests
rafael4141 Feb 9, 2023
f97dd97
refactor: rename domain Brewery for BreweryEntity
rafael4141 Feb 9, 2023
52de56b
chore: add babel and configure
rafael4141 Feb 9, 2023
131c704
feat: ensure call LoadBreweries
rafael4141 Feb 9, 2023
5c729f2
test: ensure call LoadBreweries
rafael4141 Feb 9, 2023
93081fa
feat: ensure return 500 if LoadBreweries thorws
rafael4141 Feb 10, 2023
76ad5e4
test: ensure return 500 if LoadBreweries thorws
rafael4141 Feb 10, 2023
888339f
feat: ensure return 200 on success
rafael4141 Feb 10, 2023
f44333c
test: ensure return 200 on success
rafael4141 Feb 10, 2023
e97e6d4
feat: ensure return 204 if LoadBreweries return empty
rafael4141 Feb 10, 2023
7c64d9a
test: ensure return 204 if LoadBreweries return empty
rafael4141 Feb 10, 2023
74458b5
chore: define strict boolean expressions for off
rafael4141 Feb 10, 2023
f2ffa2d
refactor: make params optional
rafael4141 Feb 10, 2023
ea535b9
feat: ensure call LoadBreweriesRepository
rafael4141 Feb 10, 2023
a13ae56
test: ensure call LoadBreweriesRepository
rafael4141 Feb 10, 2023
5048058
refactor: move sut creation to a factory method
rafael4141 Feb 10, 2023
259c8fd
test: should throw if LoadBreweriesRepository throws
rafael4141 Feb 10, 2023
4b8b059
feat: ensure return breweries on success
rafael4141 Feb 10, 2023
c58ef68
test: ensure return breweries on success
rafael4141 Feb 10, 2023
ee7c4ea
chore: add rule strictNullChectks
rafael4141 Feb 10, 2023
dca1c7d
refactor: correct the name of the given address
rafael4141 Feb 10, 2023
66380b3
refactor: correct the name of the given address
rafael4141 Feb 10, 2023
55e21a7
feat: ensure return breweries on success
rafael4141 Feb 10, 2023
32ab114
test: ensure return breweries on success
rafael4141 Feb 10, 2023
e8051fb
refactor: changing the expected result for an array with data
rafael4141 Feb 10, 2023
ecb3d60
test: ensure return [] if database is empty
rafael4141 Feb 10, 2023
71d1950
chore: add package express and @types/express
rafael4141 Feb 11, 2023
850c967
chore: add package ts-node-dev
rafael4141 Feb 11, 2023
94e9999
chore: add ts-node-dev in command dev
rafael4141 Feb 11, 2023
696124f
chore: rule changes
rafael4141 Feb 11, 2023
01078fc
refactor: removed option to be null the abv property
rafael4141 Feb 11, 2023
fa8b11f
refactor: add id proprety
rafael4141 Feb 11, 2023
f69d4b4
feat: add usecase factory loadBreweries
rafael4141 Feb 11, 2023
e47af17
feat: add controller factory of loadBreweries
rafael4141 Feb 11, 2023
5423ef8
feat: add method map that transforms the data coming from the prisma …
rafael4141 Feb 11, 2023
4da58ec
refactor: return breweries if it exists in the database if not return…
rafael4141 Feb 11, 2023
c90e975
refactor: remove static string
rafael4141 Feb 11, 2023
59a2d37
chore: add role strictNullCheck with false and esModuleInterop with true
rafael4141 Feb 11, 2023
1fc4971
feat: add express router adapter
rafael4141 Feb 11, 2023
b9bc3e7
feat: add body parser and content type from setupMiddlewares content
rafael4141 Feb 11, 2023
0407fef
feat: add setup routes
rafael4141 Feb 11, 2023
fdb2bb2
feat: add brewery get route
rafael4141 Feb 11, 2023
f25e487
feat: add setup app
rafael4141 Feb 11, 2023
82f8da3
feat: add server creation
rafael4141 Feb 11, 2023
d06349a
chore: add supertest and @types/supertest
rafael4141 Feb 11, 2023
adfd777
Revert "feat: add method map that transforms the data coming from the…
rafael4141 Feb 11, 2023
54aa020
Revert "Revert "feat: add method map that transforms the data coming …
rafael4141 Feb 11, 2023
ddfc440
Revert "feat: add method map that transforms the data coming from the…
rafael4141 Feb 11, 2023
bbdb192
test: ensure return 200 if there are breweries in the dabase
rafael4141 Feb 11, 2023
8f7ea94
test: ensure return 204 if there are no breweries in the database
rafael4141 Feb 11, 2023
7f493b2
feat: add migration where alter the column abv for not null
rafael4141 Feb 11, 2023
5ce1bdd
feat: ensure call DeleteBrewery with correct values
rafael4141 Feb 11, 2023
581244c
test: ensure call DeleteBrewery with correct values
rafael4141 Feb 11, 2023
961c6d7
refactor: change result of DeleteBrewery to void
rafael4141 Feb 11, 2023
71ec26c
refactor: move sut creation for factory method
rafael4141 Feb 11, 2023
7d7e1b3
feat: ensure return 204 on success
rafael4141 Feb 11, 2023
97f1bc2
test: ensure return 204 on success
rafael4141 Feb 11, 2023
d494c90
feat: ensure return 500 if DeleteBrewery throws
rafael4141 Feb 11, 2023
b69585e
test: ensure return 500 if DeleteBrewery throws
rafael4141 Feb 11, 2023
aa15a69
feat: ensure call DeleteBreweryRepository with correct values
rafael4141 Feb 11, 2023
cb928c1
test: ensure call DeleteBreweryRepository with correct values
rafael4141 Feb 11, 2023
b4de95a
refactor: move sut creation for factory method
rafael4141 Feb 11, 2023
05aefb0
test: ensure return if DeleteBreweryRepository throws
rafael4141 Feb 11, 2023
da70830
feat: ensure return brewery on success
rafael4141 Feb 11, 2023
b2ae432
test: ensure return brewery on success
rafael4141 Feb 11, 2023
e5a9b52
feat: ensure return 204 on success
rafael4141 Feb 11, 2023
78acb47
test: ensure return 204 on success
rafael4141 Feb 11, 2023
36abfd1
feat: ensure call AddBrewery with correct values
rafael4141 Feb 11, 2023
6f7be97
test: ensure call AddBrewery with correct values
rafael4141 Feb 11, 2023
a05486a
refactor: rename method for it()
rafael4141 Feb 11, 2023
bd991f6
refactor:
rafael4141 Feb 12, 2023
6eb799c
feat: ensure call AddBreweryRepository with correct values
rafael4141 Feb 12, 2023
2f47223
test: ensure call AddBreweryRepository with correct values
rafael4141 Feb 12, 2023
637782f
rafactor: move sut creation for factory method
rafael4141 Feb 12, 2023
2ac6e61
test: ensure throw if AddBreweryRepository throws
rafael4141 Feb 12, 2023
44c8b78
feat: ensure return brewery on success
rafael4141 Feb 12, 2023
18f2993
test: ensure return brewery on success
rafael4141 Feb 12, 2023
8c13f72
feat: add middleware cors
rafael4141 Feb 12, 2023
6cc5713
feat: ensure return 204 on success
rafael4141 Feb 12, 2023
3d9145c
test: ensure return 204 on success
rafael4141 Feb 12, 2023
b4e8f38
refactor: move sut creation for factory method
rafael4141 Feb 12, 2023
23f735c
feat: ensure retrun 500 if AddBrewery throws
rafael4141 Feb 12, 2023
ca4652d
test: ensure retrun 500 if AddBrewery throws
rafael4141 Feb 12, 2023
ed5d0c0
feat: ensure call UpdateBrewery with correct values
rafael4141 Feb 12, 2023
e224469
test: ensure call UpdateBrewery with correct values
rafael4141 Feb 12, 2023
78f6714
refactor: move sut creation for factory method
rafael4141 Feb 12, 2023
0a0fac4
test: ensure return 204 on success
rafael4141 Feb 12, 2023
7f73a95
feat: ensure return 500 if UpdateBrewery throws
rafael4141 Feb 12, 2023
b47923d
test: ensure return 500 if UpdateBrewery throws
rafael4141 Feb 12, 2023
ac73b70
feat: ensure call UpdateBreweryRepository with correct values
rafael4141 Feb 12, 2023
9eaa9a4
test: ensure call UpdateBreweryRepository with correct values
rafael4141 Feb 12, 2023
401eaee
refactor: rename test
rafael4141 Feb 12, 2023
09dd32c
feat: ensure return brewery on success
rafael4141 Feb 12, 2023
e26d513
test: ensure return brewery on success
rafael4141 Feb 12, 2023
31ba006
feat: ensure return 204 on success
rafael4141 Feb 12, 2023
daccf7d
test: ensure return 204 success
rafael4141 Feb 12, 2023
3ece0f4
feat: ensure call LoadBreweryRepository with correct values
rafael4141 Feb 13, 2023
d516c12
test: ensure call LoadBreweryRepository with correct values
rafael4141 Feb 13, 2023
0b93341
test: ensure throw if LoadBreweryRepository thorws
rafael4141 Feb 13, 2023
1d2166f
feat: ensure return true on success
rafael4141 Feb 13, 2023
17fdafa
test: ensure return true on success
rafael4141 Feb 13, 2023
6cc673a
test: ensure return false if not exists brewery in database
rafael4141 Feb 13, 2023
84dc116
feat: ensure return 403 if not exists brewery in database
rafael4141 Feb 13, 2023
8d88140
test: ensure return 403 if not exists brewery in database
rafael4141 Feb 13, 2023
69e3cde
feat: ensure return brewery on success
rafael4141 Feb 13, 2023
38fc7dc
test: ensure return brewery on success
rafael4141 Feb 13, 2023
277c777
feat: add loadBreweryRepository on factory of makeDbDeleteBrewery
rafael4141 Feb 13, 2023
9a31286
refactor: refactor return loadBreweryRepository for return brewery or…
rafael4141 Feb 13, 2023
0408547
refactor: move sut creation for factory method
rafael4141 Feb 13, 2023
fb458ed
feat: ensure call LoadBreweryRepository with correct values
rafael4141 Feb 13, 2023
c14a250
test: ensure call LoadBreweryRepository with correct values
rafael4141 Feb 13, 2023
99c1067
feat: ensure return true on success
rafael4141 Feb 13, 2023
ccd5e13
test: ensure return true on success
rafael4141 Feb 13, 2023
1d4e59e
test: ensure return false if not exists brewery in database
rafael4141 Feb 13, 2023
edb91dc
test: ensure throw if LoadBreweryRepository throws
rafael4141 Feb 13, 2023
1182ee6
test: ensure throw if UpdateBreweryRepository throws
rafael4141 Feb 13, 2023
b3d2981
feat: ensure return 403 if not exists brewery in database
rafael4141 Feb 13, 2023
ff90bc3
test: ensure return 403 if not exists brewery in database
rafael4141 Feb 13, 2023
604a263
feat: add loadBreweryRepository in factory of makeDbUpdateBrewery
rafael4141 Feb 13, 2023
5869671
test: ensure return 403 if the id is not valid
rafael4141 Feb 13, 2023
5ff8a41
test: ensure return 403 if the id is not valid
rafael4141 Feb 13, 2023
7899239
feat: ensure return 204 on seccess and add query param to express-ada…
rafael4141 Feb 13, 2023
2a30088
test: ensure return 403 if the id not valid
rafael4141 Feb 13, 2023
025545a
style: add off @typescript-eslint/restrict-plus-operands
rafael4141 Feb 13, 2023
170f2e8
refactor: remove tests for build
rafael4141 Feb 13, 2023
6a0332c
chore: add swagger and remove tag --passWithNoTest of command test
rafael4141 Feb 13, 2023
6305032
chore: add coverage
rafael4141 Feb 13, 2023
bb112dd
feat: add docs of swagger
rafael4141 Feb 13, 2023
66edceb
build: add docker with params necessary for build
rafael4141 Feb 13, 2023
fb356d3
add postman collection
rafael4141 Feb 13, 2023
1436955
docs: add Readme to configuration to show construction project
rafael4141 Feb 14, 2023
fc21687
build: change server port
rafael4141 Feb 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": "standard-with-typescript",
"overrides": [
],
"parserOptions": {
"project":"./tsconfig.json",
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/restrict-plus-operands": "off"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
dist/
.env
coverage
118 changes: 118 additions & 0 deletions Brewery.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"info": {
"_postman_id": "14c505cc-2781-43e3-94d1-50639a26ae15",
"name": "Brewery",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Load",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:3001/api/brewery",
"protocol": "http",
"host": [
"localhost"
],
"port": "3001",
"path": [
"api",
"brewery"
]
}
},
"response": []
},
{
"name": "Add",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"abv\": 91061,\r\n \"ibu\": 40165,\r\n \"address\": \"49401 Hoppe Forks\",\r\n \"category\": \"Industrial\",\r\n \"city\": \"San Rafael\",\r\n \"coordinates\": [ 15771.06, 89112.66 ],\r\n \"country\": \"Montserrat\",\r\n \"description\": \"Omnis expedita vitae. Alias debitis sit minima officiis quaerat placeat eaque commodi. Dicta deleniti accusantium facilis natus porro. Ab aliquam animi minus asperiores architecto similique sapiente eveniet. Veniam explicabo vero harum tempore excepturi delectus.\",\r\n \"name\": \"Miller, Grimes and Lakin\",\r\n \"state\": \"Nevada\",\r\n \"website\": \"unknown-meteorology.net\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3001/api/brewery",
"protocol": "http",
"host": [
"localhost"
],
"port": "3001",
"path": [
"api",
"brewery"
]
}
},
"response": []
},
{
"name": "Update",
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"id\": \"000cbca6-d62f-4c0a-89f7-66449994a4a9\",\r\n \"abv\": 91061,\r\n \"ibu\": 40165,\r\n \"address\": \"49401 Hoppe Forks\",\r\n \"category\": \"Industrial\",\r\n \"city\": \"San Rafael\",\r\n \"coordinates\": [ 15771.06, 89112.66 ],\r\n \"country\": \"Montserrat\",\r\n \"description\": \"Omnis expedita vitae. Alias debitis sit minima officiis quaerat placeat eaque commodi. Dicta deleniti accusantium facilis natus porro. Ab aliquam animi minus asperiores architecto similique sapiente eveniet. Veniam explicabo vero harum tempore excepturi delectus.\",\r\n \"name\": \"Miller, Grimes and Lakin\",\r\n \"state\": \"Nevada\",\r\n \"website\": \"unknown-meteorology.net\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:3001/api/brewery",
"protocol": "http",
"host": [
"localhost"
],
"port": "3001",
"path": [
"api",
"brewery"
]
}
},
"response": []
},
{
"name": "Delete",
"request": {
"method": "DELETE",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "http://localhost:3001/api/brewery/?id=000046a8-9e67-4a6a-b7de-56b2fb6726fc",
"protocol": "http",
"host": [
"localhost"
],
"port": "3001",
"path": [
"api",
"brewery",
""
],
"query": [
{
"key": "id",
"value": "000046a8-9e67-4a6a-b7de-56b2fb6726fc"
}
]
}
},
"response": []
}
]
}
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM node:alpine AS builder

WORKDIR /app

COPY package*.json .
COPY prisma ./prisma/

RUN npm install

COPY . .

RUN npm run build

FROM node:alpine

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/dist ./dist

EXPOSE 3001

CMD ["npm", "run", "start"]

33 changes: 33 additions & 0 deletions Readme-for-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Routes
GET /api/brewery => Return all breweries

POST /api/brewery => Add new brewery

PUT /api/brewery => Update a brewery

DELETE /api/brewery/?id=breweryId => Delete a brewery using a query

DELETE /api/brewery/:breweryId => Delete a brewery using a route param

# App Start

## Intallation Dependencies
```bash
$ npm install
```

## Running the app
```bash
$ docker compose up -d
```

App is running in http://localhost:3001

## Test

```bash
# generate coverage
$ npm run test
```

### Swagger in route http://localhost:3001/api-docs
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
}
5 changes: 5 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd ./app
npm rum build
npx prisma migrate dev
npm run seed
npm run start
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

services:
db:
container_name: db
image: postgres
ports:
- '5432:5432'
restart: always
volumes:
- postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: brewery

app:
build: .
container_name: 'app'
restart: always
environment:
- DATABASE_URL=postgresql://root:root@db:5432/brewery
- PORT=3001
volumes:
- .:/app
ports:
- '3001:3001'
links:
- db
depends_on:
- db
command: /app/config.sh

volumes:
postgres:
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
clearMocks: true,
collectCoverage: true,
coverageDirectory: "coverage",
};
Loading