Sfoglia il codice sorgente

:recycle: uisng grouping_id for tag_associations and storing on group

tags/0.0.2
j 3 anni fa
parent
commit
1ad700d3da

+ 9
- 8
backend/db/data-generator/mock.js Vedi File

@@ -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 Vedi File

@@ -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
     })

+ 2
- 0
backend/lib/plugins/profile.js Vedi File

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

+ 87
- 0
backend/lib/routes/tag/get.js Vedi File

@@ -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
+}

+ 0
- 3
backend/lib/routes/tag/reveal.js Vedi File

@@ -2,7 +2,6 @@
2 2
 
3 3
 const apiSchema = require('../../schemas/api')
4 4
 const errorSchema = require('../../schemas/errors')
5
-const profileSchema = require('../../schemas/profiles')
6 5
 const params = require('../../schemas/params')
7 6
 const Joi = require('joi')
8 7
 
@@ -45,8 +44,6 @@ module.exports = {
45 44
                 tag_id,
46 45
                 is_deleted: false,
47 46
             })
48
-            console.log('revealed :', revealedTags)
49
-
50 47
             try {
51 48
                 const tag = profileService.tagLookup[tag_id]
52 49
                 if (!tag || tag.tag_category != 'reveal') {

+ 10
- 3
backend/lib/schemas/params.js Vedi File

@@ -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 Vedi File

@@ -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')

+ 17
- 10
backend/lib/services/profile/index.js Vedi File

@@ -352,21 +352,28 @@ module.exports = class ProfileService extends Schmervice.Service {
352 352
      * @param {number} profileId
353 353
      * @param {object}
354 354
      */
355
-    async _getTagsForProfile(profileId) {
355
+    async getTagsFor(profileId, groupingId, category) {
356 356
         const { TagAssociation } = this.server.models()
357 357
         await this._setTagLookup()
358
-        const associations = await TagAssociation.query().where(
359
-            'profile_id',
360
-            profileId,
361
-        )
362
-        return associations.map(assoc => {
363
-            const tagInfo = this.tagLookup[assoc.tag_id]
364
-            return { ...assoc, tag: tagInfo }
365
-        })
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
+            })
366 373
     }
367 374
     async revealProfileInfo(association) {
368 375
         const { TagAssociation } = this.server.models()
369 376
         await TagAssociation.query().insert(association)
370
-        return await this._getTagsForProfile(association.profile_id)
377
+        return await this.getTagsFor(association.profile_id)
371 378
     }
372 379
 }

+ 1
- 0
frontend/src/components/PairsList.vue Vedi File

@@ -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 Vedi File

@@ -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 Vedi File

@@ -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 Vedi File

@@ -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(),

+ 3
- 0
frontend/src/services/grouping.service.js Vedi File

@@ -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)

Loading…
Annulla
Salva