Kaynağa Gözat

:recycle: added missing files; whoops | using grouping schema to validate incoming membership records

tags/0.0.1
TOJ 4 yıl önce
ebeveyn
işleme
5efa3fd0c4

+ 1
- 1
backend/lib/routes/membership/active.js Dosyayı Görüntüle

40
         tags: ['api'],
40
         tags: ['api'],
41
         /** Protect this route with authentication? */
41
         /** Protect this route with authentication? */
42
         auth: false,
42
         auth: false,
43
-
43
+        cors: true,
44
         handler: async function (request, h) {
44
         handler: async function (request, h) {
45
             const { membershipService } = request.services()
45
             const { membershipService } = request.services()
46
             const membershipType = request.query.type
46
             const membershipType = request.query.type

+ 1
- 1
backend/lib/routes/user/list-profiles.js Dosyayı Görüntüle

52
         tags: ['api'],
52
         tags: ['api'],
53
         /** Protect this route with authentication? */
53
         /** Protect this route with authentication? */
54
         auth: false,
54
         auth: false,
55
-
55
+        cors: true,
56
         handler: async function (request, h) {
56
         handler: async function (request, h) {
57
             const { userService, profileService } = request.server.services()
57
             const { userService, profileService } = request.server.services()
58
             const userId = request.params.user_id
58
             const userId = request.params.user_id

docs/routes.md → docs/frontend/routes.md Dosyayı Görüntüle


+ 10
- 2
frontend/src/App.vue Dosyayı Görüntüle

13
 import { profileForm } from '@/utils/forms'
13
 import { profileForm } from '@/utils/forms'
14
 import { Connector } from '@/utils/db'
14
 import { Connector } from '@/utils/db'
15
 
15
 
16
-import { fetchProfilesByUserId } from '@/services'
16
+import {
17
+    fetchProfilesByUserId,
18
+    fetchMembershipsByProfileId,
19
+} from '@/services'
17
 
20
 
18
 import helloWorld from '@/components/HelloWorld.vue'
21
 import helloWorld from '@/components/HelloWorld.vue'
19
 import card from '@/components/card.vue'
22
 import card from '@/components/card.vue'
58
 
61
 
59
         const t = async () => {
62
         const t = async () => {
60
             const tempProfiles = await fetchProfilesByUserId(1)
63
             const tempProfiles = await fetchProfilesByUserId(1)
61
-            console.log(tempProfiles)
64
+            const groupings = []
65
+            for(let p of tempProfiles) {
66
+                const memberships = await fetchMembershipsByProfileId(p.profile_id)
67
+                groupings.push(memberships)
68
+            }
69
+            console.log(groupings)
62
         }
70
         }
63
         t()
71
         t()
64
         return {
72
         return {

+ 5
- 8
frontend/src/entities/grouping/grouping.js Dosyayı Görüntüle

6
 /** Class representing a grouping */
6
 /** Class representing a grouping */
7
 class Grouping extends _baseRecord {
7
 class Grouping extends _baseRecord {
8
     /**
8
     /**
9
-     * Create the grouping.
9
+     * Create the grouping based on membership
10
      * @extends _baseRecord
10
      * @extends _baseRecord
11
-     * @param {string} email
12
-     * @param {object} grouping - spread destructured args
11
+     * @param {object} membership - spread destructured args
13
      * @return {Grouping} the grouping instance object
12
      * @return {Grouping} the grouping instance object
14
      */
13
      */
15
-    constructor({ ...grouping }) {
14
+    constructor({ ...membership }) {
16
         super()
15
         super()
17
 
16
 
18
         this.type = this.constructor.name.toLowerCase()
17
         this.type = this.constructor.name.toLowerCase()
19
 
18
 
20
-        /**  Fields */
21
-        this.groupingId = groupingId
22
-        this.groupingName = groupingName
23
-        this.groupingType = groupingType
19
+        /** Pass destructured data to the module system */
20
+        Object.assign(this, membership)
24
 
21
 
25
         return this
22
         return this
26
     }
23
     }

+ 4
- 4
frontend/src/entities/grouping/grouping.schema.js Dosyayı Görüntüle

17
         type: Joi.string(),
17
         type: Joi.string(),
18
 
18
 
19
         /** our fields */
19
         /** our fields */
20
-        groupingId: Joi.number().required(),
21
-        groupingName: Joi.string().required(),
22
-        groupingType: Joi.string().required()
20
+        grouping_id: Joi.number().required(),
21
+        grouping_name: Joi.string(),
22
+        grouping_type: Joi.string()
23
     }),
23
     }),
24
     /** fields required before saving */
24
     /** fields required before saving */
25
-    required: [ 'groupingId', 'groupingName', 'groupingType' ],
25
+    required: [ 'grouping_id', 'grouping_name', 'grouping_type' ],
26
     validate(instance) {
26
     validate(instance) {
27
         return this.properties.validate(instance)
27
         return this.properties.validate(instance)
28
     }
28
     }

+ 23
- 0
frontend/src/services/grouping.service.js Dosyayı Görüntüle

1
+import { db } from '../utils/db'
2
+import { Grouping } from '../entities'
3
+
4
+/**
5
+ * Get Memberships associated with a single Profile from the database and
6
+ * create a class from the data and
7
+ * validate the incoming against the schema
8
+ * @param {number} profileId
9
+ * @returns {array} instantiated Profile objects (see: /entites/profile)
10
+ */
11
+const fetchMembershipsByProfileId = async profileId => {
12
+    const membershipsForProfileId = await db.get(`/membership/${profileId}`)
13
+    const validGroupingInstances = []
14
+    for(let membership of membershipsForProfileId) {
15
+        const grouping = new Grouping(membership)
16
+        if(grouping.isValid()) {
17
+            validGroupingInstances.push(grouping)
18
+        }
19
+    }
20
+    return validGroupingInstances
21
+}
22
+
23
+export { fetchMembershipsByProfileId }

+ 2
- 1
frontend/src/services/index.js Dosyayı Görüntüle

1
-export * from './profile.service'
1
+export * from './profile.service'
2
+export * from './grouping.service'

+ 8
- 7
frontend/src/services/profile.service.js Dosyayı Görüntüle

2
 import { Profile } from '../entities/profile'
2
 import { Profile } from '../entities/profile'
3
 
3
 
4
 /**
4
 /**
5
- * Get a single Profile from the database and
5
+ * Get Profiles associated with a single user from the database and
6
  * create a class from the data and
6
  * create a class from the data and
7
- * validate the incoming
7
+ * validate the incoming against the schema
8
  * @param {number} userId
8
  * @param {number} userId
9
+ * @returns {array} instantiated Profile objects (see: /entites/profile)
9
  */
10
  */
10
 const fetchProfilesByUserId = async userId => {
11
 const fetchProfilesByUserId = async userId => {
11
     const profilesForUserId = await db.get(`/user/${userId}/profiles`)
12
     const profilesForUserId = await db.get(`/user/${userId}/profiles`)
12
-    const profileInstances = []
13
-    profilesForUserId.map(profileData => {
13
+    const validProfileInstances = []
14
+    for(let profileData of profilesForUserId) {
14
         const profile = new Profile(profileData)
15
         const profile = new Profile(profileData)
15
         if(profile.isValid()) {
16
         if(profile.isValid()) {
16
-            profileInstances.push(profile)
17
+            validProfileInstances.push(profile)
17
         }
18
         }
18
-    })
19
-    return profileInstances
19
+    }
20
+    return validProfileInstances
20
 }
21
 }
21
 
22
 
22
 export { fetchProfilesByUserId }
23
 export { fetchProfilesByUserId }

Loading…
İptal
Kaydet