Explorar el Código

:recycle: added updated models based on db spec

master
TOJ hace 5 años
padre
commit
bf2c790940

+ 5
- 0
backend/lib/index.js Ver fichero

1
 const UserPlugin = require('./plugins/user');
1
 const UserPlugin = require('./plugins/user');
2
+const MembershipPlugin = require('./plugins/membership');
2
 const TestPlugin = require('./plugins/test');
3
 const TestPlugin = require('./plugins/test');
3
 
4
 
4
 exports.plugin = {
5
 exports.plugin = {
12
         await server.register(UserPlugin, {
13
         await server.register(UserPlugin, {
13
             routes: { prefix: `/user` }
14
             routes: { prefix: `/user` }
14
         })
15
         })
16
+
17
+        await server.register(MembershipPlugin, {
18
+            routes: { prefix: `/membership` }
19
+        })
15
     },
20
     },
16
 }
21
 }

+ 11
- 0
backend/lib/models/grouping.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class Grouping extends Schwifty.Model {
5
+    static get tableName() { return 'groupings' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            grouping_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 11
- 0
backend/lib/models/membership.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class Membership extends Schwifty.Model {
5
+    static get tableName() { return 'memberships' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            membership_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 11
- 0
backend/lib/models/message.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class Message extends Schwifty.Model {
5
+    static get tableName() { return 'messages' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            message_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 11
- 0
backend/lib/models/profile.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class Profile extends Schwifty.Model {
5
+    static get tableName() { return 'profiles' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            profile_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 11
- 0
backend/lib/models/response-key.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class ResponseKey extends Schwifty.Model {
5
+    static get tableName() { return 'response_keys' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            response_key_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 11
- 0
backend/lib/models/response.js Ver fichero

1
+const Schwifty = require('@hapipal/schwifty');
2
+const Joi = require('joi');
3
+
4
+module.exports = class Response extends Schwifty.Model {
5
+    static get tableName() { return 'responses' }
6
+    static get joiSchema() {
7
+        return Joi.object({
8
+            response_id: Joi.number().required(),
9
+        })
10
+    }
11
+}

+ 3
- 4
backend/lib/models/user.js Ver fichero

5
     static get tableName() { return 'users' }
5
     static get tableName() { return 'users' }
6
     static get joiSchema() {
6
     static get joiSchema() {
7
         return Joi.object({
7
         return Joi.object({
8
-            id: Joi.number().required(),
9
-            name: Joi.string().required(),
10
-            email: Joi.string().required(),
11
-            password: Joi.string().required(),
8
+            user_id: Joi.number().required(),
9
+            user_name: Joi.string(),
10
+            user_email: Joi.string().required(),
12
         })
11
         })
13
     }
12
     }
14
 }
13
 }

+ 1
- 0
backend/lib/plugins/user.js Ver fichero

9
 const UserCurrentRoute = require('../routes/user/current');
9
 const UserCurrentRoute = require('../routes/user/current');
10
 const UserLoginRoute = require('../routes/user/login');
10
 const UserLoginRoute = require('../routes/user/login');
11
 
11
 
12
+const MembershipService = require('../services/membership');
12
 const UserService = require('../services/user');
13
 const UserService = require('../services/user');
13
 const DisplayService = require('../services/display');
14
 const DisplayService = require('../services/display');
14
 
15
 

+ 4
- 6
backend/lib/routes/user/login.js Ver fichero

5
 const pluginConfig = {
5
 const pluginConfig = {
6
     handlerType: 'user',
6
     handlerType: 'user',
7
     docs: {
7
     docs: {
8
-        post: {
9
-            description: 'login',
10
-            notes: 'Attempt login'
11
-        }
8
+        description: 'login',
9
+        notes: 'Attempt login'
12
     }
10
     }
13
 }
11
 }
14
 
12
 
32
 }
30
 }
33
 
31
 
34
 module.exports = {
32
 module.exports = {
35
-    method: 'post',
33
+    method: 'POST',
36
     path: '/login',
34
     path: '/login',
37
     options: {
35
     options: {
38
-        ...pluginConfig.docs.post,
36
+        ...pluginConfig.docs,
39
         tags: ['api'],
37
         tags: ['api'],
40
         auth: false,
38
         auth: false,
41
         handler: async function (request, h) {
39
         handler: async function (request, h) {

+ 10
- 0
backend/lib/services/display.js Ver fichero

8
         return { ...user, token }
8
         return { ...user, token }
9
     }
9
     }
10
 
10
 
11
+    membershipList() {
12
+        const { Membership } = this.server.models()
13
+        const memberships = Membership.query()
14
+        server.log(Membership)
15
+        return [
16
+            { foo: 'bar', membership_type: 'baz' },
17
+            { foo: 'buz', membership_type: 'biz' },
18
+        ]
19
+    }
20
+
11
     async profile(currentUserId, user, transaction)  {
21
     async profile(currentUserId, user, transaction)  {
12
         const { User } = this.server.models()
22
         const { User } = this.server.models()
13
         const { toProfile } = internals
23
         const { toProfile } = internals

+ 2
- 0
backend/package.json Ver fichero

6
   "scripts": {
6
   "scripts": {
7
     "start": "nodemon server",
7
     "start": "nodemon server",
8
     "migrate": "knex migrate:latest",
8
     "migrate": "knex migrate:latest",
9
+    "unmigrate": "knex migrate:down",
10
+    "seed": "knex seed:run",
9
     "test": "echo \"Error: no test specified\" && exit 1"
11
     "test": "echo \"Error: no test specified\" && exit 1"
10
   },
12
   },
11
   "author": "TOJ",
13
   "author": "TOJ",

Loading…
Cancelar
Guardar