generated from shillerben/adonis-fullstack-app
Initial commit
This commit is contained in:
17
app/Middleware/ConvertEmptyStringsToNull.js
Normal file
17
app/Middleware/ConvertEmptyStringsToNull.js
Normal file
@@ -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
app/Models/Token.js
Normal file
9
app/Models/Token.js
Normal file
@@ -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
app/Models/Traits/NoTimestamp.js
Normal file
16
app/Models/Traits/NoTimestamp.js
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
class NoTimestamp {
|
||||
register (Model) {
|
||||
Object.defineProperties(Model, {
|
||||
createdAtColumn: {
|
||||
get: () => null,
|
||||
},
|
||||
updatedAtColumn: {
|
||||
get: () => null,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoTimestamp
|
||||
39
app/Models/User.js
Normal file
39
app/Models/User.js
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict'
|
||||
|
||||
/** @type {import('@adonisjs/framework/src/Hash')} */
|
||||
const Hash = use('Hash')
|
||||
|
||||
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
|
||||
const Model = use('Model')
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user