Skip to content

Commit 81554f3

Browse files
committed
Initial (again) commit
0 parents  commit 81554f3

27 files changed

+5980
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_size = 2
6+
indent_style = space
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.env.example

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HOST=127.0.0.1
2+
PORT=3333
3+
NODE_ENV=development
4+
5+
APP_NAME=AdonisJs
6+
APP_URL=http://${HOST}:${PORT}
7+
8+
CACHE_VIEWS=false
9+
10+
APP_KEY=
11+
12+
DB_CONNECTION=sqlite
13+
DB_HOST=127.0.0.1
14+
DB_PORT=3306
15+
DB_USER=root
16+
DB_PASSWORD=
17+
DB_DATABASE=adonis
18+
19+
HASH_DRIVER=bcrypt

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Node modules
2+
node_modules
3+
4+
# Adonis directory for storing tmp files
5+
tmp
6+
7+
# Environment variables, never commit this file
8+
.env
9+
10+
# The development sqlite file
11+
database/development.sqlite

.node_version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.10.0

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.10.0

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Adonis API application
2+
3+
This is the boilerplate for creating an API server in AdonisJs, it comes pre-configured with.
4+
5+
1. Bodyparser
6+
2. Authentication
7+
3. CORS
8+
4. Lucid ORM
9+
5. Migrations and seeds
10+
11+
## Setup
12+
13+
Use the adonis command to install the blueprint
14+
15+
```bash
16+
adonis new yardstick --api-only
17+
```
18+
19+
or manually clone the repo and then run `npm install`.
20+
21+
22+
### Migrations
23+
24+
Run the following command to run startup migrations.
25+
26+
```js
27+
adonis migration:run
28+
```

ace

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Ace Commands
6+
|--------------------------------------------------------------------------
7+
|
8+
| The ace file is just a regular Javascript file but with no extension. You
9+
| can call `node ace` followed by the command name and it just works.
10+
|
11+
| Also you can use `adonis` followed by the command name, since the adonis
12+
| global proxies all the ace commands.
13+
|
14+
*/
15+
16+
const { Ignitor } = require('@adonisjs/ignitor')
17+
18+
new Ignitor(require('@adonisjs/fold'))
19+
.appRoot(__dirname)
20+
.fireAce()
21+
.catch(console.error)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
class ConvertEmptyStringsToNull {
4+
async handle ({ request }, next) {
5+
if (Object.keys(request.body).length) {
6+
request.body = Object.assign(
7+
...Object.keys(request.body).map(key => ({
8+
[key]: request.body[key] !== '' ? request.body[key] : null
9+
}))
10+
)
11+
}
12+
13+
await next()
14+
}
15+
}
16+
17+
module.exports = ConvertEmptyStringsToNull

app/Models/Token.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict'
2+
3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4+
const Model = use('Model')
5+
6+
class Token extends Model {
7+
}
8+
9+
module.exports = Token

app/Models/Traits/NoTimestamp.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
class NoTimestamp {
4+
register (Model) {
5+
Object.defineProperties(Model, {
6+
createdAtColumn: {
7+
get: () => null,
8+
},
9+
updatedAtColumn: {
10+
get: () => null,
11+
}
12+
})
13+
}
14+
}
15+
16+
module.exports = NoTimestamp

app/Models/User.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict'
2+
3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4+
const Model = use('Model')
5+
6+
/** @type {import('@adonisjs/framework/src/Hash')} */
7+
const Hash = use('Hash')
8+
9+
class User extends Model {
10+
static boot () {
11+
super.boot()
12+
13+
/**
14+
* A hook to hash the user password before saving
15+
* it to the database.
16+
*/
17+
this.addHook('beforeSave', async (userInstance) => {
18+
if (userInstance.dirty.password) {
19+
userInstance.password = await Hash.make(userInstance.password)
20+
}
21+
})
22+
}
23+
24+
/**
25+
* A relationship on tokens is required for auth to
26+
* work. Since features like `refreshTokens` or
27+
* `rememberToken` will be saved inside the
28+
* tokens table.
29+
*
30+
* @method tokens
31+
*
32+
* @return {Object}
33+
*/
34+
tokens () {
35+
return this.hasMany('App/Models/Token')
36+
}
37+
}
38+
39+
module.exports = User

0 commit comments

Comments
 (0)