Skip to content

Commit

Permalink
feat: add base project
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-roque committed Feb 1, 2020
0 parents commit ce6b4d1
Show file tree
Hide file tree
Showing 65 changed files with 24,414 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
docker-compose.yml
docker-data/*
.vsls
.idea
.env
.vscode/
node_modules/
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) 2020 Gabriel Roque

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.
6 changes: 6 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
.dockerignore
.git/
.gitignore
node_modules/
.env.example
8 changes: 8 additions & 0 deletions api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

end_of_line = lf
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
19 changes: 19 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HOST=0.0.0.0
PORT=8080
NODE_ENV=development

APP_NAME=StarWarsBattle
APP_URL=http://${HOST}:${PORT}

CACHE_VIEWS=false

APP_KEY=

DB_CONNECTION=pg
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=adonis_usr
DB_PASSWORD=123456
DB_DATABASE=adonis_db

HASH_DRIVER=bcrypt
11 changes: 11 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Node modules
node_modules

# Adonis directory for storing tmp files
tmp

# Environment variables, never commit this file
.env

# The development sqlite file
database/*.sqlite
12 changes: 12 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:12.2.0-alpine

WORKDIR /api

COPY ./package.json /api
RUN sh -c 'npm install'

COPY ./ /api

EXPOSE 8080

# CMD [ "npm", "start"]
21 changes: 21 additions & 0 deletions api/ace
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

/*
|--------------------------------------------------------------------------
| Ace Commands
|--------------------------------------------------------------------------
|
| The ace file is just a regular Javascript file but with no extension. You
| can call `node ace` followed by the command name and it just works.
|
| Also you can use `adonis` followed by the command name, since the adonis
| global proxies all the ace commands.
|
*/

const { Ignitor } = require('@adonisjs/ignitor')

new Ignitor(require('@adonisjs/fold'))
.appRoot(__dirname)
.fireAce()
.catch(console.error)
17 changes: 17 additions & 0 deletions api/app/Middleware/ConvertEmptyStringsToNull.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

class ConvertEmptyStringsToNull {
async handle ({ request }, next) {
if (Object.keys(request.body).length) {
request.body = Object.assign(
...Object.keys(request.body).map(key => ({
[key]: request.body[key] !== '' ? request.body[key] : null
}))
)
}

await next()
}
}

module.exports = ConvertEmptyStringsToNull
9 changes: 9 additions & 0 deletions api/app/Models/Token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Token extends Model {
}

module.exports = Token
16 changes: 16 additions & 0 deletions api/app/Models/Traits/NoTimestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

class NoTimestamp {
register (Model) {
Object.defineProperties(Model, {
createdAtColumn: {
get: () => null,
},
updatedAtColumn: {
get: () => null,
}
})
}
}

module.exports = NoTimestamp
39 changes: 39 additions & 0 deletions api/app/Models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

/** @type {import('@adonisjs/framework/src/Hash')} */
const Hash = use('Hash')

class User extends Model {
static boot () {
super.boot()

/**
* A hook to hash the user password before saving
* it to the database.
*/
this.addHook('beforeSave', async (userInstance) => {
if (userInstance.dirty.password) {
userInstance.password = await Hash.make(userInstance.password)
}
})
}

/**
* A relationship on tokens is required for auth to
* work. Since features like `refreshTokens` or
* `rememberToken` will be saved inside the
* tokens table.
*
* @method tokens
*
* @return {Object}
*/
tokens () {
return this.hasMany('App/Models/Token')
}
}

module.exports = User
Loading

0 comments on commit ce6b4d1

Please sign in to comment.