Procházet zdrojové kódy

Merge branch 'SIIMEE-T-7-reveal' of fyindr/siimee into dev

tags/0.0.2
maeda před 3 roky
rodič
revize
71934c5ee8

+ 9
- 8
backend/db/data-generator/mock.js Zobrazit soubor

@@ -43,49 +43,49 @@ module.exports = {
43 43
         {
44 44
             tag_association_id: 1,
45 45
             profile_id: 1,
46
-            membership_id: null,
46
+            grouping_id: null,
47 47
             tag_id: 1,
48 48
             is_deleted: false,
49 49
         },
50 50
         {
51 51
             tag_association_id: 2,
52 52
             profile_id: 2,
53
-            membership_id: null,
53
+            grouping_id: null,
54 54
             tag_id: 1,
55 55
             is_deleted: false,
56 56
         },
57 57
         {
58 58
             tag_association_id: 3,
59 59
             profile_id: 3,
60
-            membership_id: null,
60
+            grouping_id: null,
61 61
             tag_id: 1,
62 62
             is_deleted: false,
63 63
         },
64 64
         {
65 65
             tag_association_id: 4,
66 66
             profile_id: 45,
67
-            membership_id: null,
67
+            grouping_id: null,
68 68
             tag_id: 1,
69 69
             is_deleted: false,
70 70
         },
71 71
         {
72 72
             tag_association_id: 5,
73 73
             profile_id: 45,
74
-            membership_id: 1,
74
+            grouping_id: 2,
75 75
             tag_id: 4,
76 76
             is_deleted: false,
77 77
         },
78 78
         {
79 79
             tag_association_id: 6,
80 80
             profile_id: 45,
81
-            membership_id: 1,
81
+            grouping_id: 2,
82 82
             tag_id: 5,
83 83
             is_deleted: false,
84 84
         },
85 85
         {
86 86
             tag_association_id: 7,
87 87
             profile_id: 2,
88
-            membership_id: 1,
88
+            grouping_id: 2,
89 89
             tag_id: 5,
90 90
             is_deleted: false,
91 91
         },
@@ -94,7 +94,8 @@ module.exports = {
94 94
         {
95 95
             response_key_id: 1,
96 96
             response_key_category: 'visionary_vs_implementer',
97
-            response_key_prompt: 'While managing your team, do you find success in your employees being more Visionary or Implementer?',
97
+            response_key_prompt:
98
+                'While managing your team, do you find success in your employees being more Visionary or Implementer?',
98 99
             response_key_description: 'first round draft scoring question',
99 100
         },
100 101
         {

+ 1
- 1
backend/db/migrations/20220403111037_create_tag_associations_table.js Zobrazit soubor

@@ -2,7 +2,7 @@ exports.up = function (knex) {
2 2
     return knex.schema.createTable('tag_associations', function (table) {
3 3
         table.increments('tag_association_id').primary()
4 4
         table.integer('profile_id').notNullable()
5
-        table.integer('membership_id')
5
+        table.integer('grouping_id')
6 6
         table.integer('tag_id').notNullable()
7 7
         table.boolean('is_deleted').notNullable()
8 8
     })

+ 4
- 0
backend/lib/plugins/profile.js Zobrazit soubor

@@ -21,6 +21,8 @@ const ProfileMatchRoute = require('../routes/profile/match')
21 21
 const ProfileQueueRoute = require('../routes/profile/queue')
22 22
 const ProfileGetRoute = require('../routes/profile/get')
23 23
 const ProfilePatchQueueRoute = require('../routes/profile/patch-queue')
24
+const TagRevealRoute = require('../routes/tag/reveal')
25
+const TagGetRoute = require('../routes/tag/get')
24 26
 
25 27
 module.exports = {
26 28
     name: 'profile-plugin',
@@ -53,5 +55,7 @@ module.exports = {
53 55
         await server.route(ProfileQueueRoute)
54 56
         await server.route(ProfileGetRoute)
55 57
         await server.route(ProfilePatchQueueRoute)
58
+        await server.route(TagRevealRoute)
59
+        await server.route(TagGetRoute)
56 60
     },
57 61
 }

+ 87
- 0
backend/lib/routes/tag/get.js Zobrazit soubor

@@ -0,0 +1,87 @@
1
+'use strict'
2
+
3
+const apiSchema = require('../../schemas/api')
4
+const errorSchema = require('../../schemas/errors')
5
+const params = require('../../schemas/params')
6
+const Joi = require('joi')
7
+
8
+const pluginConfig = {
9
+    handlerType: 'get',
10
+    docs: {
11
+        description: 'Get tags based on membership id',
12
+        notes: 'returns from the Tag Associations Table',
13
+    },
14
+}
15
+
16
+const responseSchemas = {
17
+    tags: Joi.array().items(Joi.object()),
18
+    error: errorSchema.single,
19
+}
20
+
21
+const validators = {
22
+    params: Joi.object({
23
+        profile_id: params.profileId,
24
+        grouping_id: params.groupingId,
25
+    }),
26
+    query: Joi.object({ category: Joi.string() }),
27
+}
28
+
29
+module.exports = {
30
+    method: 'GET',
31
+    path: '/{profile_id}/tags/{grouping_id}',
32
+    options: {
33
+        ...pluginConfig.docs,
34
+        tags: ['api'],
35
+        /** Protect this route with authentication? */
36
+        auth: false,
37
+        cors: true,
38
+        handler: async function (request, h) {
39
+            const { grouping_id, profile_id } = request.params
40
+            const { profileService } = request.server.services()
41
+            const { category } = request.query
42
+            const revealedTags = await profileService.getTagsFor(
43
+                profile_id,
44
+                grouping_id,
45
+                category,
46
+            )
47
+            try {
48
+                return h
49
+                    .response({
50
+                        ok: true,
51
+                        handler: pluginConfig.handlerType,
52
+                        data: revealedTags,
53
+                    })
54
+                    .code(200)
55
+            } catch (err) {
56
+                return h
57
+                    .response({
58
+                        ok: false,
59
+                        handler: pluginConfig.handlerType,
60
+                        data: { error: `${err}` },
61
+                    })
62
+                    .code(409)
63
+            }
64
+        },
65
+        /** Validate based on validators object */
66
+        validate: {
67
+            ...validators,
68
+            failAction: 'log',
69
+        },
70
+
71
+        /** Validate the server response */
72
+        response: {
73
+            status: {
74
+                200: apiSchema.single
75
+                    .append({
76
+                        data: responseSchemas.tags,
77
+                    })
78
+                    .label('tags_res'),
79
+                409: apiSchema.single
80
+                    .append({
81
+                        data: responseSchemas.error,
82
+                    })
83
+                    .label('error_single_res'),
84
+            },
85
+        },
86
+    },
87
+}

+ 91
- 0
backend/lib/routes/tag/reveal.js Zobrazit soubor

@@ -0,0 +1,91 @@
1
+'use strict'
2
+
3
+const apiSchema = require('../../schemas/api')
4
+const errorSchema = require('../../schemas/errors')
5
+const params = require('../../schemas/params')
6
+const Joi = require('joi')
7
+
8
+const pluginConfig = {
9
+    handlerType: 'reveal',
10
+    docs: {
11
+        description: 'Reveals part of a profile based on tag',
12
+        notes: 'returns from the Tag Associations Table',
13
+    },
14
+}
15
+
16
+const responseSchemas = {
17
+    tags: Joi.array().items(Joi.object()),
18
+    error: errorSchema.single,
19
+}
20
+
21
+const validators = {
22
+    params: params.profileId.append({ tag_id: Joi.number() }),
23
+    payload: Joi.object({
24
+        profile_id: Joi.number(),
25
+        membership_id: Joi.string().optional(),
26
+    }),
27
+}
28
+
29
+module.exports = {
30
+    method: 'POST',
31
+    path: '/{profile_id}/reveal/{tag_id}',
32
+    options: {
33
+        ...pluginConfig.docs,
34
+        tags: ['api'],
35
+        /** Protect this route with authentication? */
36
+        auth: false,
37
+        cors: true,
38
+        handler: async function (request, h) {
39
+            const { profile_id, tag_id } = request.params
40
+            const { profileService } = request.server.services()
41
+
42
+            const revealedTags = await profileService.revealProfileInfo({
43
+                profile_id,
44
+                tag_id,
45
+                is_deleted: false,
46
+            })
47
+            try {
48
+                const tag = profileService.tagLookup[tag_id]
49
+                if (!tag || tag.tag_category != 'reveal') {
50
+                    throw `cannot reveal ${tag} tag`
51
+                }
52
+                return h
53
+                    .response({
54
+                        ok: true,
55
+                        handler: pluginConfig.handlerType,
56
+                        data: revealedTags,
57
+                    })
58
+                    .code(200)
59
+            } catch (err) {
60
+                return h
61
+                    .response({
62
+                        ok: false,
63
+                        handler: pluginConfig.handlerType,
64
+                        data: { error: `${err}` },
65
+                    })
66
+                    .code(409)
67
+            }
68
+        },
69
+        /** Validate based on validators object */
70
+        validate: {
71
+            ...validators,
72
+            failAction: 'log',
73
+        },
74
+
75
+        /** Validate the server response */
76
+        response: {
77
+            status: {
78
+                200: apiSchema.single
79
+                    .append({
80
+                        data: responseSchemas.tags,
81
+                    })
82
+                    .label('reveal_res'),
83
+                409: apiSchema.single
84
+                    .append({
85
+                        data: responseSchemas.error,
86
+                    })
87
+                    .label('error_single_res'),
88
+            },
89
+        },
90
+    },
91
+}

+ 10
- 3
backend/lib/schemas/params.js Zobrazit soubor

@@ -1,12 +1,19 @@
1 1
 const Joi = require('joi')
2 2
 
3 3
 module.exports = {
4
-    profileId: Joi.object({ profile_id: Joi.number() }).label('profile_id_param'),
4
+    profileId: Joi.object({ profile_id: Joi.number() }).label(
5
+        'profile_id_param',
6
+    ),
7
+    groupingId: Joi.object({ grouping_id: Joi.number() }).label(
8
+        'grouping_id_param',
9
+    ),
5 10
     profileInclude: Joi.object({ include_profile: Joi.bool() }),
6 11
     userId: Joi.object({ user_id: Joi.number() }).label('user_id_param'),
7 12
     userName: Joi.object({
8 13
         name: Joi.string().min(3).max(11),
9 14
         all: Joi.array(),
10 15
     }).label('user_name_param'),
11
-    userEmail: Joi.object({ user_email: Joi.string() }).label('user_email_param')
12
-}
16
+    userEmail: Joi.object({ user_email: Joi.string() }).label(
17
+        'user_email_param',
18
+    ),
19
+}

+ 1
- 1
backend/lib/schemas/tags.js Zobrazit soubor

@@ -12,7 +12,7 @@ const singleTag = Joi.object({
12 12
 const singleTagAssociation = Joi.object({
13 13
     tag_association_id: Joi.number(),
14 14
     profile_id: Joi.number().required(),
15
-    membership_id: Joi.number(),
15
+    grouping_id: Joi.number(),
16 16
     tag_id: Joi.number().required(),
17 17
     is_deleted: Joi.boolean().required(),
18 18
 }).label('tag_association_single')

+ 32
- 1
backend/lib/services/profile/index.js Zobrazit soubor

@@ -11,7 +11,7 @@ module.exports = class ProfileService extends Schmervice.Service {
11 11
         super(...args)
12 12
         /** Scores available in the db to map against score indices*/
13 13
         this.scoreLookup = {}
14
-        /** Tags available in the db to map against tagg_associations*/
14
+        /** Tags available in the db to map against tag_associations*/
15 15
         this.tagLookup = {}
16 16
         // this.responseKeyLookup = ResponseKey.query()
17 17
     }
@@ -345,4 +345,35 @@ module.exports = class ProfileService extends Schmervice.Service {
345 345
         const end = await this._latLonForZip(end_zip)
346 346
         return haversine(start, end, { unit: distanceUnit })
347 347
     }
348
+
349
+    /**
350
+     * Use the db to grab tag associations
351
+     * by profile and match them to tag types
352
+     * @param {number} profileId
353
+     * @param {object}
354
+     */
355
+    async getTagsFor(profileId, groupingId, category) {
356
+        const { TagAssociation } = this.server.models()
357
+        await this._setTagLookup()
358
+        let associations = groupingId
359
+            ? await TagAssociation.query()
360
+                  .where('grouping_id', groupingId)
361
+                  .andWhere('profile_id', profileId)
362
+            : await TagAssociation.query().andWhere('profile_id', profileId)
363
+        return associations
364
+            .map(assoc => ({
365
+                ...assoc,
366
+                tag: this.tagLookup[assoc.tag_id],
367
+            }))
368
+            .filter(tagWithAssoc => {
369
+                return category
370
+                    ? tagWithAssoc.tag.tag_category == category
371
+                    : true
372
+            })
373
+    }
374
+    async revealProfileInfo(association) {
375
+        const { TagAssociation } = this.server.models()
376
+        await TagAssociation.query().insert(association)
377
+        return await this.getTagsFor(association.profile_id)
378
+    }
348 379
 }

+ 1
- 0
frontend/src/components/PairsList.vue Zobrazit soubor

@@ -18,6 +18,7 @@ section.pairs-list
18 18
                     p since: {{ pair.grouping.createdAt }}
19 19
                     p updated: {{ pair.grouping.lastUpdatedAt }}
20 20
                     p paired: {{ pair.grouping.is_paired }}
21
+                    p revealed tags: {{ pair.grouping.tags }}
21 22
     p(v-else) No {{ tabName }} profiles.
22 23
 </template>
23 24
 

+ 2
- 2
frontend/src/components/ProfileCard.vue Zobrazit soubor

@@ -57,8 +57,8 @@ import TagList from './TagList.vue'
57 57
 import PairingButton from './PairingButton.vue'
58 58
 
59 59
 const router = useRouter()
60
-const isPaired = ref(true)
61
-// const isPaired = ref(false)
60
+// const isPaired = ref(true)
61
+const isPaired = ref(false)
62 62
 
63 63
 const props = defineProps({
64 64
     card: {

+ 1
- 0
frontend/src/entities/grouping/grouping.js Zobrazit soubor

@@ -15,6 +15,7 @@ class Grouping extends _baseRecord {
15 15
         super()
16 16
 
17 17
         this.type = this.constructor.name.toLowerCase()
18
+        this.tags = []
18 19
 
19 20
         /** Pass destructured data to the module system */
20 21
         Object.assign(this, membership)

+ 1
- 0
frontend/src/entities/grouping/grouping.schema.js Zobrazit soubor

@@ -15,6 +15,7 @@ const groupingSchema = {
15 15
         _id: Joi.string(),
16 16
         lastUpdatedAt: Joi.string(),
17 17
         type: Joi.string(),
18
+        tags: Joi.array(),
18 19
 
19 20
         /** our fields */
20 21
         grouping_id: Joi.number().required(),

+ 0
- 1
frontend/src/services/chat.service.js Zobrazit soubor

@@ -121,7 +121,6 @@ class Chatter {
121 121
      * @param {array} channels
122 122
      */
123 123
     subscribe({ channels }) {
124
-        console.log('subscribing to:', channels)
125 124
         _providerMethods.subscribe({ channels })
126 125
     }
127 126
     /**

+ 3
- 0
frontend/src/services/grouping.service.js Zobrazit soubor

@@ -13,6 +13,9 @@ const fetchMembershipsByProfileId = async profileId => {
13 13
     const validGroupingInstances = []
14 14
     for (let membership of membershipsForProfileId) {
15 15
         const grouping = new Grouping(membership)
16
+        grouping.tags = await db.get(
17
+            `/profile/${profileId}/tags/${grouping.grouping_id}`,
18
+        )
16 19
         if (grouping.isValid()) {
17 20
             // Reformat incoming profile data into Profile entity
18 21
             grouping.profile = new Profile(grouping.profile)

Načítá se…
Zrušit
Uložit