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
         {
43
         {
44
             tag_association_id: 1,
44
             tag_association_id: 1,
45
             profile_id: 1,
45
             profile_id: 1,
46
-            membership_id: null,
46
+            grouping_id: null,
47
             tag_id: 1,
47
             tag_id: 1,
48
             is_deleted: false,
48
             is_deleted: false,
49
         },
49
         },
50
         {
50
         {
51
             tag_association_id: 2,
51
             tag_association_id: 2,
52
             profile_id: 2,
52
             profile_id: 2,
53
-            membership_id: null,
53
+            grouping_id: null,
54
             tag_id: 1,
54
             tag_id: 1,
55
             is_deleted: false,
55
             is_deleted: false,
56
         },
56
         },
57
         {
57
         {
58
             tag_association_id: 3,
58
             tag_association_id: 3,
59
             profile_id: 3,
59
             profile_id: 3,
60
-            membership_id: null,
60
+            grouping_id: null,
61
             tag_id: 1,
61
             tag_id: 1,
62
             is_deleted: false,
62
             is_deleted: false,
63
         },
63
         },
64
         {
64
         {
65
             tag_association_id: 4,
65
             tag_association_id: 4,
66
             profile_id: 45,
66
             profile_id: 45,
67
-            membership_id: null,
67
+            grouping_id: null,
68
             tag_id: 1,
68
             tag_id: 1,
69
             is_deleted: false,
69
             is_deleted: false,
70
         },
70
         },
71
         {
71
         {
72
             tag_association_id: 5,
72
             tag_association_id: 5,
73
             profile_id: 45,
73
             profile_id: 45,
74
-            membership_id: 1,
74
+            grouping_id: 2,
75
             tag_id: 4,
75
             tag_id: 4,
76
             is_deleted: false,
76
             is_deleted: false,
77
         },
77
         },
78
         {
78
         {
79
             tag_association_id: 6,
79
             tag_association_id: 6,
80
             profile_id: 45,
80
             profile_id: 45,
81
-            membership_id: 1,
81
+            grouping_id: 2,
82
             tag_id: 5,
82
             tag_id: 5,
83
             is_deleted: false,
83
             is_deleted: false,
84
         },
84
         },
85
         {
85
         {
86
             tag_association_id: 7,
86
             tag_association_id: 7,
87
             profile_id: 2,
87
             profile_id: 2,
88
-            membership_id: 1,
88
+            grouping_id: 2,
89
             tag_id: 5,
89
             tag_id: 5,
90
             is_deleted: false,
90
             is_deleted: false,
91
         },
91
         },
94
         {
94
         {
95
             response_key_id: 1,
95
             response_key_id: 1,
96
             response_key_category: 'visionary_vs_implementer',
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
             response_key_description: 'first round draft scoring question',
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
     return knex.schema.createTable('tag_associations', function (table) {
2
     return knex.schema.createTable('tag_associations', function (table) {
3
         table.increments('tag_association_id').primary()
3
         table.increments('tag_association_id').primary()
4
         table.integer('profile_id').notNullable()
4
         table.integer('profile_id').notNullable()
5
-        table.integer('membership_id')
5
+        table.integer('grouping_id')
6
         table.integer('tag_id').notNullable()
6
         table.integer('tag_id').notNullable()
7
         table.boolean('is_deleted').notNullable()
7
         table.boolean('is_deleted').notNullable()
8
     })
8
     })

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

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

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

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

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

1
 const Joi = require('joi')
1
 const Joi = require('joi')
2
 
2
 
3
 module.exports = {
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
     profileInclude: Joi.object({ include_profile: Joi.bool() }),
10
     profileInclude: Joi.object({ include_profile: Joi.bool() }),
6
     userId: Joi.object({ user_id: Joi.number() }).label('user_id_param'),
11
     userId: Joi.object({ user_id: Joi.number() }).label('user_id_param'),
7
     userName: Joi.object({
12
     userName: Joi.object({
8
         name: Joi.string().min(3).max(11),
13
         name: Joi.string().min(3).max(11),
9
         all: Joi.array(),
14
         all: Joi.array(),
10
     }).label('user_name_param'),
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
 const singleTagAssociation = Joi.object({
12
 const singleTagAssociation = Joi.object({
13
     tag_association_id: Joi.number(),
13
     tag_association_id: Joi.number(),
14
     profile_id: Joi.number().required(),
14
     profile_id: Joi.number().required(),
15
-    membership_id: Joi.number(),
15
+    grouping_id: Joi.number(),
16
     tag_id: Joi.number().required(),
16
     tag_id: Joi.number().required(),
17
     is_deleted: Joi.boolean().required(),
17
     is_deleted: Joi.boolean().required(),
18
 }).label('tag_association_single')
18
 }).label('tag_association_single')

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

352
      * @param {number} profileId
352
      * @param {number} profileId
353
      * @param {object}
353
      * @param {object}
354
      */
354
      */
355
-    async _getTagsForProfile(profileId) {
355
+    async getTagsFor(profileId, groupingId, category) {
356
         const { TagAssociation } = this.server.models()
356
         const { TagAssociation } = this.server.models()
357
         await this._setTagLookup()
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
     async revealProfileInfo(association) {
374
     async revealProfileInfo(association) {
368
         const { TagAssociation } = this.server.models()
375
         const { TagAssociation } = this.server.models()
369
         await TagAssociation.query().insert(association)
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
                     p since: {{ pair.grouping.createdAt }}
18
                     p since: {{ pair.grouping.createdAt }}
19
                     p updated: {{ pair.grouping.lastUpdatedAt }}
19
                     p updated: {{ pair.grouping.lastUpdatedAt }}
20
                     p paired: {{ pair.grouping.is_paired }}
20
                     p paired: {{ pair.grouping.is_paired }}
21
+                    p revealed tags: {{ pair.grouping.tags }}
21
     p(v-else) No {{ tabName }} profiles.
22
     p(v-else) No {{ tabName }} profiles.
22
 </template>
23
 </template>
23
 
24
 

+ 2
- 2
frontend/src/components/ProfileCard.vue Vedi File

57
 import PairingButton from './PairingButton.vue'
57
 import PairingButton from './PairingButton.vue'
58
 
58
 
59
 const router = useRouter()
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
 const props = defineProps({
63
 const props = defineProps({
64
     card: {
64
     card: {

+ 1
- 0
frontend/src/entities/grouping/grouping.js Vedi File

15
         super()
15
         super()
16
 
16
 
17
         this.type = this.constructor.name.toLowerCase()
17
         this.type = this.constructor.name.toLowerCase()
18
+        this.tags = []
18
 
19
 
19
         /** Pass destructured data to the module system */
20
         /** Pass destructured data to the module system */
20
         Object.assign(this, membership)
21
         Object.assign(this, membership)

+ 1
- 0
frontend/src/entities/grouping/grouping.schema.js Vedi File

15
         _id: Joi.string(),
15
         _id: Joi.string(),
16
         lastUpdatedAt: Joi.string(),
16
         lastUpdatedAt: Joi.string(),
17
         type: Joi.string(),
17
         type: Joi.string(),
18
+        tags: Joi.array(),
18
 
19
 
19
         /** our fields */
20
         /** our fields */
20
         grouping_id: Joi.number().required(),
21
         grouping_id: Joi.number().required(),

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

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

Loading…
Annulla
Salva