maeda 3 lat temu
rodzic
commit
87a41b6805

+ 281
- 0
backend/db/data-generator/mock.js Wyświetl plik

@@ -115,6 +115,287 @@ module.exports = {
115 115
             tag_id: 5,
116 116
             is_deleted: false,
117 117
         },
118
+        {
119
+            tag_association_id: 10,
120
+            profile_id: 4,
121
+            grouping_id: null,
122
+            tag_id: 1,
123
+            is_deleted: false,
124
+        },
125
+        {
126
+            tag_association_id: 11,
127
+            profile_id: 5,
128
+            grouping_id: null,
129
+            tag_id: 1,
130
+            is_deleted: false,
131
+        },
132
+        {
133
+            tag_association_id: 12,
134
+            profile_id: 6,
135
+            grouping_id: null,
136
+            tag_id: 3,
137
+            is_deleted: false,
138
+        },
139
+        {
140
+            tag_association_id: 13,
141
+            profile_id: 7,
142
+            grouping_id: null,
143
+            tag_id: 8,
144
+            is_deleted: false,
145
+        },
146
+        {
147
+            tag_association_id: 14,
148
+            profile_id: 8,
149
+            grouping_id: null,
150
+            tag_id: 7,
151
+            is_deleted: false,
152
+        },
153
+        {
154
+            tag_association_id: 15,
155
+            profile_id: 9,
156
+            grouping_id: 1,
157
+            tag_id: 2,
158
+            is_deleted: false,
159
+        },
160
+        {
161
+            tag_association_id: 16,
162
+            profile_id: 10,
163
+            grouping_id: 2,
164
+            tag_id: 2,
165
+            is_deleted: false,
166
+        },
167
+        {
168
+            tag_association_id: 17,
169
+            profile_id: 11,
170
+            grouping_id: 2,
171
+            tag_id: 3,
172
+            is_deleted: false,
173
+        },
174
+        {
175
+            tag_association_id: 18,
176
+            profile_id: 12,
177
+            grouping_id: 3,
178
+            tag_id: 4,
179
+            is_deleted: false,
180
+        },
181
+        {
182
+            tag_association_id: 19,
183
+            profile_id: 13,
184
+            grouping_id: 3,
185
+            tag_id: 7,
186
+            is_deleted: false,
187
+        },
188
+        {
189
+            tag_association_id: 20,
190
+            profile_id: 14,
191
+            grouping_id: 4,
192
+            tag_id: 6,
193
+            is_deleted: false,
194
+        },
195
+        {
196
+            tag_association_id: 21,
197
+            profile_id: 15,
198
+            grouping_id: 1,
199
+            tag_id: 1,
200
+            is_deleted: false,
201
+        },
202
+        {
203
+            tag_association_id: 22,
204
+            profile_id: 16,
205
+            grouping_id: 1,
206
+            tag_id: 2,
207
+            is_deleted: false,
208
+        },
209
+        {
210
+            tag_association_id: 23,
211
+            profile_id: 17,
212
+            grouping_id: null,
213
+            tag_id: 6,
214
+            is_deleted: false,
215
+        },
216
+        {
217
+            tag_association_id: 24,
218
+            profile_id: 18,
219
+            grouping_id: null,
220
+            tag_id: 8,
221
+            is_deleted: false,
222
+        },
223
+        {
224
+            tag_association_id: 25,
225
+            profile_id: 19,
226
+            grouping_id: null,
227
+            tag_id: 3,
228
+            is_deleted: false,
229
+        },
230
+        {
231
+            tag_association_id: 26,
232
+            profile_id: 20,
233
+            grouping_id: null,
234
+            tag_id: 3,
235
+            is_deleted: false,
236
+        },
237
+        {
238
+            tag_association_id: 27,
239
+            profile_id: 21,
240
+            grouping_id: 2,
241
+            tag_id: 1,
242
+            is_deleted: false,
243
+        },
244
+        {
245
+            tag_association_id: 28,
246
+            profile_id: 22,
247
+            grouping_id: 2,
248
+            tag_id: 1,
249
+            is_deleted: false,
250
+        },
251
+        {
252
+            tag_association_id: 29,
253
+            profile_id: 23,
254
+            grouping_id: 3,
255
+            tag_id: 2,
256
+            is_deleted: false,
257
+        },
258
+        {
259
+            tag_association_id: 30,
260
+            profile_id: 24,
261
+            grouping_id: 4,
262
+            tag_id: 4,
263
+            is_deleted: false,
264
+        },
265
+        {
266
+            tag_association_id: 31,
267
+            profile_id: 25,
268
+            grouping_id: 5,
269
+            tag_id: 3,
270
+            is_deleted: false,
271
+        },
272
+        {
273
+            tag_association_id: 32,
274
+            profile_id: 26,
275
+            grouping_id: 1,
276
+            tag_id: 4,
277
+            is_deleted: false,
278
+        },
279
+        {
280
+            tag_association_id: 33,
281
+            profile_id: 27,
282
+            grouping_id: null,
283
+            tag_id: 3,
284
+            is_deleted: false,
285
+        },
286
+        {
287
+            tag_association_id: 34,
288
+            profile_id: 28,
289
+            grouping_id: null,
290
+            tag_id: 3,
291
+            is_deleted: false,
292
+        },
293
+        {
294
+            tag_association_id: 35,
295
+            profile_id: 29,
296
+            grouping_id: null,
297
+            tag_id: 7,
298
+            is_deleted: false,
299
+        },
300
+        {
301
+            tag_association_id: 36,
302
+            profile_id: 30,
303
+            grouping_id: null,
304
+            tag_id: 6,
305
+            is_deleted: false,
306
+        },
307
+        {
308
+            tag_association_id: 37,
309
+            profile_id: 31,
310
+            grouping_id: 3,
311
+            tag_id: 4,
312
+            is_deleted: false,
313
+        },
314
+        {
315
+            tag_association_id: 38,
316
+            profile_id: 32,
317
+            grouping_id: 3,
318
+            tag_id: 5,
319
+            is_deleted: false,
320
+        },
321
+        {
322
+            tag_association_id: 39,
323
+            profile_id: 33,
324
+            grouping_id: 3,
325
+            tag_id: 5,
326
+            is_deleted: false,
327
+        },
328
+        {
329
+            tag_association_id: 40,
330
+            profile_id: 34,
331
+            grouping_id: 4,
332
+            tag_id: 7,
333
+            is_deleted: false,
334
+        },
335
+        {
336
+            tag_association_id: 41,
337
+            profile_id: 35,
338
+            grouping_id: 4,
339
+            tag_id: 8,
340
+            is_deleted: false,
341
+        },
342
+        {
343
+            tag_association_id: 42,
344
+            profile_id: 36,
345
+            grouping_id: 1,
346
+            tag_id: 1,
347
+            is_deleted: false,
348
+        },
349
+        {
350
+            tag_association_id: 43,
351
+            profile_id: 37,
352
+            grouping_id: 1,
353
+            tag_id: 2,
354
+            is_deleted: false,
355
+        },
356
+        {
357
+            tag_association_id: 44,
358
+            profile_id: 38,
359
+            grouping_id: null,
360
+            tag_id: 2,
361
+            is_deleted: false,
362
+        },
363
+        {
364
+            tag_association_id: 45,
365
+            profile_id: 39,
366
+            grouping_id: null,
367
+            tag_id: 6,
368
+            is_deleted: false,
369
+        },
370
+        {
371
+            tag_association_id: 46,
372
+            profile_id: 40,
373
+            grouping_id: null,
374
+            tag_id: 5,
375
+            is_deleted: false,
376
+        },
377
+        {
378
+            tag_association_id: 47,
379
+            profile_id: 41,
380
+            grouping_id: null,
381
+            tag_id: 6,
382
+            is_deleted: false,
383
+        },
384
+        {
385
+            tag_association_id: 48,
386
+            profile_id: 42,
387
+            grouping_id: 1,
388
+            tag_id: 8,
389
+            is_deleted: false,
390
+        },
391
+        {
392
+            tag_association_id: 49,
393
+            profile_id: 43,
394
+            grouping_id: 1,
395
+            tag_id: 7,
396
+            is_deleted: false,
397
+        },
398
+
118 399
     ],
119 400
     response_keys: [
120 401
         {

+ 20
- 4
backend/lib/services/profile/index.js Wyświetl plik

@@ -357,8 +357,8 @@ module.exports = class ProfileService extends Schmervice.Service {
357 357
         await this._setTagLookup()
358 358
         let associations = groupingId
359 359
             ? await TagAssociation.query()
360
-                  .where('grouping_id', groupingId)
361
-                  .andWhere('profile_id', profileId)
360
+                .where('grouping_id', groupingId)
361
+                .andWhere('profile_id', profileId)
362 362
             : await TagAssociation.query().andWhere('profile_id', profileId)
363 363
         return associations
364 364
             .map(assoc => ({
@@ -371,10 +371,26 @@ module.exports = class ProfileService extends Schmervice.Service {
371 371
                     : true
372 372
             })
373 373
     }
374
+
375
+    /**
376
+     * Use the db to grab tag associations
377
+     * by profile, grouping, tag, and insert
378
+     * it if it already exists
379
+     * @param {object} association
380
+     */
374 381
     async revealProfileInfo(association) {
375 382
         const { TagAssociation } = this.server.models()
376
-        await TagAssociation.query().insert(association)
377 383
 
378
-        return await this.getTagsFor(association.profile_id)
384
+        const existingAssociations = await TagAssociation.query()
385
+            .where('profile_id', `${association.profile_id}`)
386
+            .where('grouping_id', `${association.grouping_id}`)
387
+            .where('tag_id', `${association.tag_id}`)
388
+            .where('is_deleted', 0)
389
+        if (!existingAssociations.length) {
390
+            await TagAssociation.query().insert(association)
391
+            return await this.getTagsFor(association.profile_id)
392
+        } else {
393
+            return console.error('tag association already exists')
394
+        }
379 395
     }
380 396
 }

Ładowanie…
Anuluj
Zapisz