Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Challenge by Juun #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IntellijIdea files
*.iml
.idea
.vscode
out
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Talanov Maxim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
## Front End Code Challenge

### React Client App

Configuration files app `./src/config`

Runs the app in the development mode.

`npm start`

Build the app for production.

`npm run build`

### api-server
- Mongo (local) `mongodb://localhost:27018`

- Runs the app in the development mode.

`npm run dev`

- Runs the app in the production mode.

`npm run start`

### Mongo DB default user (admin) credential
- user name: Jane
- email: [email protected]
- password: Jane123!@#

This is Limbic's React/React Native Coding Challenge which will allow us to get a glimpse into our candidates' overall developer skills.

You are free to create a React web app, or a React Native mobile app, it's up to you. We'd rather you use something you are comfortable with so that time isn't wasted on project setup and we can get a real feel for your coding patterns and understanding of best practices with React and/or React Native, regardless of the end use case.
Expand Down
21 changes: 21 additions & 0 deletions api-server/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "11"
}
}
]
],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }]
],
"env": {
"dev": {
"sourceMaps": "inline",
"retainLines": true
}
}
}
13 changes: 13 additions & 0 deletions api-server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
logs
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
*/bin
*/obj
README.md
LICENSE
.vscode
10 changes: 10 additions & 0 deletions api-server/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["airbnb-base", "prettier"],
"parser": "babel-eslint",
"rules": {
"no-console": 0,
"no-underscore-dangle": 0,
"camelcase": 0,
"no-unused-vars": 0
}
}
3 changes: 3 additions & 0 deletions api-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
.env
24 changes: 24 additions & 0 deletions api-server/.sample-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# host options
PORT=3003
HOST='http://localhost'
FRONTEND_HOST='http://localhost:3000'

# mongo uri
MONGO_URI='mongodb://mongo/test'

# secrets for api token
SECRET_TOKEN_ACCESS='secret'
EXPIRE_TOKEN_ACCESS='1d'

SECRET_TOKEN_REFRESH='secret'
EXPIRE_TOKEN_REFRESH='30d'

SECRET_TOKEN_RESTORE_PASSWORD='secret'
EXPIRE_TOKEN_RESTORE_PASSWORD='5min'

TOKEN_LIMIT_COUNT_DIVICE=5

#mail options
API_KEY_MAILGUN='test'
DOMAIN_MAILGUN='test'
FROM_DEFAULT_MAIL='Test <[email protected]>'
6 changes: 6 additions & 0 deletions api-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:10.13-alpine
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install
COPY . .
EXPOSE 3003
118 changes: 118 additions & 0 deletions api-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Node Js Express Api Server

Configuration file app `.sample-env` rename to `.env`.

Runs the app from Docker

`sudo docker-compose up`

Host app `http://localhost:3003`

AdminMongo `http://0.0.0.0:1234` (Mongo uri in docker containers `mongodb://mongo`)

Mongo (local) `mongodb://localhost:27018`

Runs the app in the development mode.

`npm run dev`

Runs the app in the production mode.

`npm run start`

## Method API

### Register new user

`POST: api/auth/signup`

Params

`email:[email protected] name:test`

Password auto generate, find in local email to (open mail client) `/api-server/logs/mail`

### Get token

`POST: /api/auth/signin`

Params

`email:[email protected] password:test`

### Refresh token

`POST: api/auth/refresh-tokens`

Params

`refreshToken:idtoken::token`

### Restore password

`POST: api/auth/restore-password`

Params

`email:[email protected]`

### Confirm restore password

`POST: api/auth/confirm-restore-password`

Params

`token:token`

Token find in local email to `/api-server/logs/mail`

### Logout (with Authorization: Bearer token)

`POST: api/auth/logout`

### Exemple url Users List (with Authorization: Bearer token)

`GET: api/users`

## Error and logging

`/api-server/logs` Write logs error\combined log to prod mode

`/api-server/logs/mail` Dev mode catch send email and save .eml file

For logging use `winston` to `/api-server/src/utils/logger.js`

Http request console log `morgan`

Email sending errors are also additionally logged with the error type `EMAIL_ERROR`.

Handle error to `/api-server/src/middleware/ErrorHandler.js`

### Error validation

For validate data use AJV (https://github.com/epoberezkin/ajv)

Schemas validation to `/api-server/src/schemas`

Example validation route `router.post("/auth/signin", Validate.prepare(authSchemas.signin)`

Example validation error (http code 422):

```js
{
"code": 422,
"message": "Unprocessable Entity",
"errorValidation": {
"fields": {
"email": [
"Should have required property 'email'"
],
"password": [
"Should have required property 'password'"
]
}
}
}
```

The project will change over time, if you have advice on how to do better write to me `minorforyounot[replace]gmail.com`
24 changes: 24 additions & 0 deletions api-server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '2.1'

services:
backend:
build: .
ports:
- 3003:3003
volumes:
- ./:/usr/src/app
command: npm run dev
links:
- mongo
mongo:
image: mongo
ports:
- 27018:27017
adminmongo:
image: mrvautin/adminmongo
environment:
- HOST=0.0.0.0
ports:
- 1234:1234
links:
- mongo
5 changes: 5 additions & 0 deletions api-server/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
3 changes: 3 additions & 0 deletions api-server/logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
*/
!.gitignore
14 changes: 14 additions & 0 deletions api-server/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"ignore": ["node_modules"],
"env": {
"NODE_ENV": "development",
"BABEL_DISABLE_CACHE": 1,
"PORT": 3003,
"URL": "http://localhost"
},
"execMap": {
"js": "babel-node"
},
"ext": ".js,.json,.gql",
"watch": "./"
}
Loading