Skip to content

Commit cf8a2b1

Browse files
feat: upload user files and mongo support
1 parent 44eb958 commit cf8a2b1

31 files changed

+787
-116
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.env

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@ DATABASE_PORT=3306
1010
DATABASE_USERNAME=root
1111
DATABASE_PASSWORD=mysql
1212
DATABASE_NAME=graphql
13-
DATABASE_URL="${DATABASE_PROVIDER}://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@localhost:${DATABASE_PORT}/${DATABASE_NAME}"
13+
DATABASE_URL="${DATABASE_PROVIDER}://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@localhost:${DATABASE_PORT}/${DATABASE_NAME}"
14+
15+
MONGO_INITDB_ROOT_USERNAME=mongoadmin
16+
MONGO_INITDB_ROOT_PASSWORD=password
17+
18+
MONGO_DATABASE=test
19+
MONGO_USERNAME=admin
20+
MONGO_PASSWORD=password

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/dist
33
/node_modules
44

5+
# docker
6+
/data
7+
58
# Logs
69
logs
710
*.log

README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
2323
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
2424

25-
### Simple Blog API ( CRUD users, users CRUD posts )
25+
### Simple Blog API ( CRUD users, users CRUD posts, users upload files )
2626

2727
> [Prisma](https://docs.nestjs.com/recipes/prisma) [GraphQL schema-first](https://docs.nestjs.com/graphql/quick-start#schema-first) [Hybrid application](https://docs.nestjs.com/faq/hybrid-application)
2828
29-
This hybrid project uses graphql API query language for clean responses, TCP transport layer for microservice, `@nestjs/testing` which uses jest for unit testing and mysql as the relational database.
29+
This hybrid project uses GraphQL API query language for clean responses, TCP transport layer for microservice, `@nestjs/testing` which uses jest for unit testing and MySQL as the relational database and MongoDB as no-sql database for constantly changing or growing data such as posts.
3030

3131
To connect other microservices uncomment examples in `main.ts`, replace jest with vitest and to use a different database, check the [Prisma docs](https://www.prisma.io/docs/getting-started) e.g.
3232

@@ -56,15 +56,37 @@ datasource db {
5656

5757
### Installation
5858

59-
1. Install dependencies: `npm install`
60-
2. Generate TypeScript type definitions for the GraphQL schema: `npm run generate:typings`
61-
3. Generate a type-safe client to interact with your database: `npm run prisma:gen`
62-
4. Create mariadb/mysql database and create tables: `npm run prisma:push`
63-
5. Start server: `npm run start:dev`
59+
1. Run multi-container Docker applications
60+
61+
```bash
62+
# run mongodb, mongo express container
63+
$ docker-compose -f docker-compose-mongo.yml up -d
64+
# run mysql, phpmyadmincontainer
65+
$ docker-compose up -d
66+
67+
```
68+
2. Install dependencies: `npm install`
69+
3. Generate TypeScript type definitions for the GraphQL schema: `npm run generate:typings`
70+
4. Generate a type-safe client to interact with your database: `npm run prisma:gen`
71+
5. Create mariadb/mysql database and create tables: `npm run prisma:push`
72+
6. Start server: `npm run start:dev`
73+
74+
## Test
75+
76+
```bash
77+
# unit tests
78+
$ npm run test
79+
80+
# e2e tests
81+
$ npm run test:e2e
82+
83+
# test coverage
84+
$ npm run test:cov
85+
```
6486

6587
### Graphql Playground
6688

67-
When the application is running, you can go to [http://localhost:3000/graphql](http://localhost:3001/graphql) to access the GraphQL Playground. See [here](https://docs.nestjs.com/graphql/quick-start#playground) for more.
89+
When the application is running, you can go to [http://localhost:3001/graphql](http://localhost:3001/graphql) to access the GraphQL Playground. See [here](https://docs.nestjs.com/graphql/quick-start#playground) for more.
6890

6991

7092
**Create a New User**

docker-compose-mongo.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
version: "3.8"
2+
3+
services:
4+
mongo:
5+
image: mongo:latest
6+
container_name: mongo
7+
environment:
8+
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
9+
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
10+
security_opt:
11+
- seccomp:unconfined
12+
ports:
13+
- "0.0.0.0:27017:27017"
14+
networks:
15+
- MONGO
16+
volumes:
17+
- type: volume
18+
source: MONGO_DATA
19+
target: /data/db
20+
- type: volume
21+
source: MONGO_CONFIG
22+
target: /data/configdb
23+
mongo-express:
24+
image: mongo-express:1.0.0-18-alpine3.18
25+
container_name: mongo-db-ui
26+
environment:
27+
ME_CONFIG_MONGODB_ADMINUSERNAME: ${MONGO_INITDB_ROOT_USERNAME}
28+
ME_CONFIG_MONGODB_ADMINPASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
29+
ME_CONFIG_MONGODB_SERVER: mongo
30+
ME_CONFIG_MONGODB_PORT: "27017"
31+
ports:
32+
- "0.0.0.0:8081:8081"
33+
networks:
34+
- MONGO
35+
depends_on:
36+
- mongo
37+
restart: unless-stopped
38+
39+
networks:
40+
MONGO:
41+
name: mongo_mongo
42+
43+
volumes:
44+
MONGO_DATA:
45+
name: MONGO_DATA
46+
MONGO_CONFIG:
47+
name: MONGO_CONFIG

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ services:
3535
mysql-phpmyadmin:
3636
aliases:
3737
- mysql
38-
38+
3939
volumes:
4040
mysql-data:

0 commit comments

Comments
 (0)