aboutsummaryrefslogtreecommitdiffstats
path: root/app/Models
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-08-22 11:12:36 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-08-22 11:12:36 +0200
commitb018adf240679ec59a7344e30be39400f1ecd8af (patch)
treec076635761667dad302716b498088f1047281e46 /app/Models
downloadferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.tar.gz
ferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.tar.zst
ferdium-server-b018adf240679ec59a7344e30be39400f1ecd8af.zip
Initial commit
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Service.js12
-rw-r--r--app/Models/Token.js9
-rw-r--r--app/Models/Traits/NoTimestamp.js16
-rw-r--r--app/Models/User.js43
4 files changed, 80 insertions, 0 deletions
diff --git a/app/Models/Service.js b/app/Models/Service.js
new file mode 100644
index 0000000..0ca72fd
--- /dev/null
+++ b/app/Models/Service.js
@@ -0,0 +1,12 @@
1'use strict'
2
3/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4const Model = use('Model')
5
6class Service extends Model {
7 user() {
8 return this.belongsTo('App/Models/User', 'userId', 'id')
9 }
10}
11
12module.exports = Service
diff --git a/app/Models/Token.js b/app/Models/Token.js
new file mode 100644
index 0000000..e089e87
--- /dev/null
+++ b/app/Models/Token.js
@@ -0,0 +1,9 @@
1'use strict'
2
3/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4const Model = use('Model')
5
6class Token extends Model {
7}
8
9module.exports = Token
diff --git a/app/Models/Traits/NoTimestamp.js b/app/Models/Traits/NoTimestamp.js
new file mode 100644
index 0000000..edd07f0
--- /dev/null
+++ b/app/Models/Traits/NoTimestamp.js
@@ -0,0 +1,16 @@
1'use strict'
2
3class NoTimestamp {
4 register (Model) {
5 Object.defineProperties(Model, {
6 createdAtColumn: {
7 get: () => null,
8 },
9 updatedAtColumn: {
10 get: () => null,
11 }
12 })
13 }
14}
15
16module.exports = NoTimestamp
diff --git a/app/Models/User.js b/app/Models/User.js
new file mode 100644
index 0000000..0bb1547
--- /dev/null
+++ b/app/Models/User.js
@@ -0,0 +1,43 @@
1'use strict'
2
3/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
4const Model = use('Model')
5
6/** @type {import('@adonisjs/framework/src/Hash')} */
7const Hash = use('Hash')
8
9class 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 services () {
39 return this.hasMany('App/Models/Service', 'id', 'userId')
40 }
41}
42
43module.exports = User