-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de393c3
commit 53333c6
Showing
31 changed files
with
829 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"used":[3500,3501,3502,3503,3504,3505]} | ||
{"used":[3500,3501,3502,3503,3504,3505,3506]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SERVER_PORT=3500 | ||
|
||
PRISMA_MANAGEMENT_API_SECRET=wsflk897dh%£ | ||
|
||
LOGGING_DRIVER=json-file | ||
|
||
DB_HOST= | ||
DB_PORT= | ||
DB_NAME= | ||
DB_USER= | ||
DB_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": [ | ||
"airbnb-base" | ||
], | ||
"rules": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.env | ||
node_modules | ||
generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:13 | ||
RUN curl -o- -L https://yarnpkg.com/install.sh | bash | ||
RUN yarn global add prisma | ||
|
||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
RUN yarn install | ||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# User | ||
|
||
Generated Express.js microservice using our [generator](../../generator). | ||
|
||
To run this service use the [launcher script](../launcher.sh) as described in the [readme](../README.md). | ||
|
||
# Description | ||
|
||
Service to manage users | ||
|
||
# Install | ||
|
||
* Run `yarn install` | ||
* Install prisma CLI: https://v1.prisma.io/docs/1.34/prisma-cli-and-configuration/using-the-prisma-cli-alx4/ | ||
* Run `prisma generate` | ||
|
||
These steps are necessary to have autocompletion. | ||
Now you can start coding but make sure to not edit code that will be overriden by the generator. In case you want to do any change in the service contracts, you need to do it through the [specification](../specification). | ||
|
||
# Documentation | ||
|
||
A generated swagger documentation can be found at the route `/documentation` through the api-gateway. | ||
|
||
You can also find the postman collection file under [services/documentation/postman/user-postman.json](../documentation/postman/user-postman.json). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type User { | ||
id: ID! @id | ||
firstName: String! | ||
lastName: String! | ||
email: String! @unique | ||
password: String! | ||
createdAt: DateTime! @createdAt | ||
updatedAt: DateTime! @updatedAt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: '3' | ||
services: | ||
app: | ||
volumes: | ||
- ./src:/app/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
version: '3' | ||
services: | ||
app: | ||
ports: | ||
- '${SERVER_PORT:-3506}:3500' | ||
networks: | ||
- kafka_broker | ||
|
||
prisma: | ||
networks: | ||
- postgres | ||
environment: | ||
PRISMA_CONFIG: | | ||
port: 4466 | ||
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET:-wsflk897dh%£} | ||
databases: | ||
default: | ||
connector: postgres | ||
host: postgres | ||
port: 5432 | ||
user: postgres | ||
password: postgres | ||
postgres: | ||
image: postgres:10.3 | ||
restart: always | ||
networks: | ||
- postgres | ||
environment: | ||
POSTGRES_DB: prisma | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
volumes: | ||
- postgres-${ENV:-dev}:/var/lib/postgresql/data | ||
|
||
networks: | ||
kafka_broker: | ||
external: true | ||
postgres: | ||
driver: bridge | ||
|
||
volumes: | ||
postgres-dev: | ||
postgres-test: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
version: "3" | ||
services: | ||
app: | ||
build: . | ||
command: sh -c "./wait-for-it.sh -t 15 prisma:4466 --strict -- prisma generate && prisma deploy && yarn lint-check && yarn ${ENV:-dev}" | ||
volumes: | ||
- /app/node_modules | ||
- /app/generated/prisma-client | ||
networks: | ||
- app | ||
depends_on: | ||
- prisma | ||
logging: | ||
driver: ${LOGGING_DRIVER:-json-file} | ||
environment: | ||
PRISMA_MANAGEMENT_API_SECRET: ${PRISMA_MANAGEMENT_API_SECRET:-wsflk897dh%£} | ||
restart: always | ||
|
||
prisma: | ||
image: prismagraphql/prisma:1.34 | ||
restart: always | ||
networks: | ||
- app | ||
logging: | ||
driver: ${LOGGING_DRIVER:-json-file} | ||
environment: | ||
PRISMA_CONFIG: | | ||
port: 4466 | ||
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET:-wsflk897dh%£} | ||
databases: | ||
default: | ||
connector: postgres | ||
host: ${DB_HOST} | ||
port: ${DB_PORT} | ||
database: ${DB_NAME} | ||
schema: public | ||
user: ${DB_USER} | ||
password: ${DB_PASSWORD} | ||
networks: | ||
app: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "user", | ||
"description": "", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"start": "node src/index.js", | ||
"dev": "nodemon src/index.js", | ||
"prod": "node src/index.js", | ||
"test": "jest --testTimeout=20000 --runInBand", | ||
"lint-check": "eslint ./ --ext js", | ||
"lint-fix": "eslint ./ --ext js --fix" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1", | ||
"express-routes-versioning": "^1.0.1", | ||
|
||
"prisma-client-lib": "^1.34.10", | ||
"winston": "^3.2.1" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.3.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"jest": "^25.2.2", | ||
"nodemon": "^1.18.9", | ||
"supertest": "^4.0.2" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"collectCoverage": true, | ||
"coverageReporters": [ | ||
"text-summary" | ||
], | ||
"coveragePathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/generated/" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
endpoint: http://prisma:4466 | ||
datamodel: datamodel.prisma | ||
generate: | ||
- generator: javascript-client | ||
output: ./generated/prisma-client/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const winston = require('winston'); | ||
|
||
/** | ||
* Check if the body of the request contains the good elements | ||
*/ | ||
const bodyIsValid = (body) => { | ||
const { firstName, lastName, email, password } = body; | ||
if (!firstName || !lastName || !email || !password) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
/** | ||
* Create a user | ||
* @see PUT /users | ||
*/ | ||
module.exports.createUser = async (req, res) => { | ||
if (bodyIsValid(req.body)) { | ||
try { | ||
// TODO: | ||
res.status(200).send({}); | ||
} catch (e) { | ||
winston.error(e); | ||
res.status(500).send({ message: e }); | ||
} | ||
} else { | ||
res.status(400).send({ message: 'Invalid body format' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const winston = require('winston'); | ||
|
||
/** | ||
* Delete a user | ||
* @see DELETE /users/:id | ||
*/ | ||
module.exports.deleteUser = async (req, res) => { | ||
try { | ||
// TODO: | ||
res.status(200).send({}); | ||
} catch (e) { | ||
winston.error(e); | ||
res.status(500).send({ message: e }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const winston = require('winston'); | ||
|
||
/** | ||
* Get a user by id | ||
* @see GET /users/:id | ||
*/ | ||
module.exports.getUserById = async (req, res) => { | ||
try { | ||
// TODO: | ||
res.status(200).send({}); | ||
} catch (e) { | ||
winston.error(e); | ||
res.status(500).send({ message: e }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const winston = require('winston'); | ||
|
||
/** | ||
* Get users | ||
* @see GET /users | ||
*/ | ||
module.exports.getUsers = async (req, res) => { | ||
try { | ||
// TODO: | ||
res.status(200).send({}); | ||
} catch (e) { | ||
winston.error(e); | ||
res.status(500).send({ message: e }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exports.getUsers = require('./getUsers.ctrl').getUsers; | ||
exports.getUserById = require('./getUserById.ctrl').getUserById; | ||
exports.createUser = require('./createUser.ctrl').createUser; | ||
exports.updateUserById = require('./updateUserById.ctrl').updateUserById; | ||
exports.deleteUser = require('./deleteUser.ctrl').deleteUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const winston = require('winston'); | ||
|
||
/** | ||
* Check if the body of the request contains the good elements | ||
*/ | ||
const bodyIsValid = (body) => { | ||
const { firstName, lastName, email, password } = body; | ||
if (!firstName || !lastName || !email || !password) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
/** | ||
* Update a user by id | ||
* @see PUT /users/:id | ||
*/ | ||
module.exports.updateUserById = async (req, res) => { | ||
if (bodyIsValid(req.body)) { | ||
try { | ||
// TODO: | ||
res.status(200).send({}); | ||
} catch (e) { | ||
winston.error(e); | ||
res.status(500).send({ message: e }); | ||
} | ||
} else { | ||
res.status(400).send({ message: 'Invalid body format' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const winston = require('winston'); | ||
const app = require('./server'); | ||
|
||
/** | ||
* Start the server | ||
*/ | ||
app.listen(3500, () => { | ||
winston.info('Server is running on: http://localhost:3500'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { prisma } = require('../generated/prisma-client'); | ||
|
||
// TODO: add your prisma queries here |
Oops, something went wrong.