Просмотр исходного кода

:recycle: adding back queue

neo
toj 2 лет назад
Родитель
Сommit
08fbd08675

+ 29
- 0
backend/lib/models/match-queue.js Просмотреть файл

@@ -0,0 +1,29 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const User = require('./user')
4
+const queueSchema = require('../schemas/match-queues')
5
+
6
+module.exports = class MatchQueue extends Schwifty.Model {
7
+    static get tableName() {
8
+        return 'match_queues'
9
+    }
10
+    static get relationMappings() {
11
+        return {
12
+            user: {
13
+                relation: Schwifty.Model.HasOneThroughRelation,
14
+                modelClass: User,
15
+                join: {
16
+                    from: 'match_queues.target_id',
17
+                    through: {
18
+                        from: 'profiles.profile_id',
19
+                        to: 'profiles.user_id',
20
+                    },
21
+                    to: 'users.user_id',
22
+                },
23
+            },
24
+        }
25
+    }
26
+    static get joiSchema() {
27
+        return queueSchema.single
28
+    }
29
+}

+ 12
- 0
backend/lib/models/response-key.js Просмотреть файл

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const responseKeySchema = require('../schemas/response-keys')
4
+
5
+module.exports = class ResponseKey extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'response_keys'
8
+    }
9
+    static get joiSchema() {
10
+        return responseKeySchema.single
11
+    }
12
+}

+ 12
- 0
backend/lib/models/response.js Просмотреть файл

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const responseSchema = require('../schemas/response')
4
+
5
+module.exports = class Response extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'responses'
8
+    }
9
+    static get joiSchema() {
10
+        return responseSchema.single
11
+    }
12
+}

+ 8
- 0
backend/lib/schemas/groupings.js Просмотреть файл

@@ -2,6 +2,13 @@ const Joi = require('joi')
2 2
 
3 3
 const profileSchema = require('./profiles')
4 4
 
5
+/**
6
+ * Groupings
7
+ * A represents a match, an organization, or anything else
8
+ * that relates multiple profiles to each other.
9
+ */
10
+
11
+// validator is used to validate route input/output
5 12
 const validator = Joi.object({
6 13
     grouping_id: Joi.number(),
7 14
     grouping_name: Joi.string(),
@@ -12,6 +19,7 @@ const validator = Joi.object({
12 19
 
13 20
 const list = Joi.array().items(validator).label('grouping__list_validator')
14 21
 
22
+// single is used to define database models
15 23
 const single = Joi.object({
16 24
     grouping_id: Joi.number(),
17 25
     grouping_name: Joi.string(),

+ 38
- 0
backend/lib/schemas/match-queues.js Просмотреть файл

@@ -0,0 +1,38 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Match Queue
5
+ * A match queue record stores prematched target-profiles
6
+ * to display *in order* for the logged-in profile.
7
+ *
8
+ * example:
9
+ * { profile_id: 2, target_id: 54 }
10
+ * { profile_id: 2, target_id: 27 }
11
+ * { profile_id: 2, target_id: 83 }
12
+ *
13
+ * This example will display profiles 54, 27, 83 to
14
+ * profile 2 when they login.
15
+ */
16
+
17
+// validator is used to validate route input/output
18
+const validator = Joi.object({
19
+    match_queue_id: Joi.number(),
20
+    profile_id: Joi.number().required(),
21
+    target_id: Joi.number().required(),
22
+}).label('queue__single_validator')
23
+
24
+const list = Joi.array().items(validator).label('queue__list_validator')
25
+
26
+// single is used to define database models
27
+const single = Joi.object({
28
+    match_queue_id: Joi.number(),
29
+    profile_id: Joi.number().required(),
30
+    target_id: Joi.number().required(),
31
+    _is_deleted: Joi.boolean().required(),
32
+}).label('queue__single')
33
+
34
+module.exports = {
35
+    single,
36
+    validator,
37
+    list,
38
+}

+ 6
- 0
backend/lib/schemas/memberships.js Просмотреть файл

@@ -1,5 +1,11 @@
1 1
 const Joi = require('joi')
2 2
 
3
+/**
4
+ * Memberships
5
+ * A membership relates a profile to a grouping.
6
+ */
7
+
8
+// validator is used to validate route input/output
3 9
 const validator = Joi.object({
4 10
     membership_id: Joi.number(),
5 11
     profile_id: Joi.number(),

+ 3
- 3
backend/lib/schemas/profile.js Просмотреть файл

@@ -1,5 +1,5 @@
1 1
 const Joi = require('joi')
2
-// const surveyResponseSchema = require('./responses')
2
+const responseSchema = require('./responses')
3 3
 const userSchema = require('./users')
4 4
 const associationSchema = require('./tag-associations')
5 5
 
@@ -13,8 +13,8 @@ const associationSchema = require('./tag-associations')
13 13
 const validator = Joi.object({
14 14
     profile_id: Joi.number(),
15 15
     user: userSchema.single,
16
-    // responses: surveyResponseSchema.list,
17
-    // reveal: Joi.array().items(),
16
+    responses: responseSchema.list,
17
+    reveal: Joi.array().items(),
18 18
     tags: associationSchema.list,
19 19
     profile_description: Joi.string().allow(null, ''),
20 20
 }).label('profile__single_validator')

+ 9
- 0
backend/lib/schemas/response-keys.js Просмотреть файл

@@ -1,5 +1,13 @@
1 1
 const Joi = require('joi')
2 2
 
3
+/**
4
+ * Response Keys
5
+ * A response key is a question in the onboarding survey.
6
+ * We track the questions we ask to aggregate analytics 
7
+ * about survey effectiveness.
8
+ */
9
+
10
+// validator is used to validate route input/output
3 11
 const validator = Joi.object({
4 12
     response_key_id: Joi.number().required(),
5 13
     response_key_category: Joi.string().required(),
@@ -9,6 +17,7 @@ const validator = Joi.object({
9 17
 
10 18
 const list = Joi.array().items(validator).label('question__list_validator')
11 19
 
20
+// single is used to define database models
12 21
 const single = Joi.object({
13 22
     response_key_id: Joi.number().required(),
14 23
     response_key_category: Joi.string().required(),

+ 8
- 0
backend/lib/schemas/responses.js Просмотреть файл

@@ -1,5 +1,12 @@
1 1
 const Joi = require('joi')
2 2
 
3
+/**
4
+ * Responses
5
+ * A response records how a profile answers
6
+ * a specific question (response-key).
7
+ */
8
+
9
+// validator is used to validate route input/output
3 10
 const validator = Joi.object({
4 11
     response_key_id: Joi.number(),
5 12
     response_id: Joi.number(),
@@ -9,6 +16,7 @@ const validator = Joi.object({
9 16
 
10 17
 const list = Joi.array().items(validator).label('response__list_validator')
11 18
 
19
+// single is used to define database models
12 20
 const single = Joi.object({
13 21
     response_key_id: Joi.number(),
14 22
     response_id: Joi.number(),

Загрузка…
Отмена
Сохранить