Browse Source

Merge branch 'master' into schemas

tags/0.0.1
J 4 years ago
parent
commit
3405721ae5

+ 1
- 1
backend/lib/routes/membership/join.js View File

@@ -62,7 +62,6 @@ module.exports = {
62 62
                 // TODO: LIMIT the amount of groupings by checking type
63 63
                 // !: You should only be able to match with the target_id ONCE
64 64
                 // !: You should only be associated with a single company too
65
-                console.log('---')
66 65
 
67 66
                 /** User membership service method to create membership */
68 67
                 const memberships = await membershipService.joinGrouping(
@@ -72,6 +71,7 @@ module.exports = {
72 71
                     role,
73 72
                 )
74 73
                 // console.log(memberships)
74
+
75 75
                 return h
76 76
                     .response({
77 77
                         ok: true,

+ 1
- 1
backend/lib/routes/profile/patch-queue.js View File

@@ -51,7 +51,7 @@ module.exports = {
51 51
             const { include_profile, reinsert } = request.query
52 52
             const { profileService, matchQueueService } =
53 53
                 request.server.services()
54
-            console.log('reinsert', reinsert)
54
+            // console.log('reinsert', reinsert)
55 55
             const updatedQueue = await matchQueueService.markAsDeleted(
56 56
                 profile_id,
57 57
                 target_id,

+ 0
- 8
backend/lib/routes/profile/queue.js View File

@@ -59,14 +59,6 @@ module.exports = {
59 59
                 data: queueIds
60 60
             }
61 61
 
62
-            // HELP: I think there's an issue here
63
-            // queueIds spits out the queue profiles in the correct order
64
-            // ~However~ when it goes through getProfilesFor
65
-            // it comes back in literal database order regardless of is_deleted status
66
-            // console.log(
67
-            //     'include_profile results',
68
-            //     await profileService.getProfilesFor(queueIds),
69
-            // )
70 62
             if(include_profile) {
71 63
                 res.data = await profileService.getProfilesFor(queueIds)
72 64
             }

+ 1
- 1
backend/lib/routes/profile/score.js View File

@@ -43,7 +43,7 @@ module.exports = {
43 43
         tags: ['api'],
44 44
         /** Protect this route with authentication? */
45 45
         auth: false,
46
-
46
+        cors: true,
47 47
         handler: async function (request, h) {
48 48
             const { profileService, matchQueueService } =
49 49
                 request.server.services()

+ 0
- 2
backend/lib/routes/user/current.js View File

@@ -30,8 +30,6 @@ module.exports = {
30 30
         tags: ['api'],
31 31
         auth: 'default_jwt',
32 32
         handler: async function (request, h) {
33
-            // console.log('current')
34
-            // console.log(request)
35 33
             try {
36 34
                 const auth = {
37 35
                     credentials: request.auth.credentials,

+ 0
- 1
backend/lib/routes/user/list-profiles.js View File

@@ -68,7 +68,6 @@ module.exports = {
68 68
                 userId,
69 69
                 type,
70 70
             )
71
-            console.log('get profiles - const profiles / in list-profiles.js', profiles)
72 71
             try {
73 72
                 return {
74 73
                     ok: true,

+ 0
- 2
backend/lib/services/match.js View File

@@ -51,7 +51,6 @@ class Person {
51 51
         }
52 52
 
53 53
         this.swapWith = p => {
54
-            console.log('%s & %s swap partners', this.name, p.name)
55 54
             const thisFiance = this.fiance
56 55
             const pFiance = p.fiance
57 56
             this.engageTo(pFiance)
@@ -80,7 +79,6 @@ module.exports = class MatchService extends Schmervice.Service {
80 79
         for (let d = 0; d < diff; d++) {
81 80
             smallerList.push({ profile_id: `${d}-dummy`, queue: [] })
82 81
         }
83
-        console.log('---')
84 82
         let allPeople = [...seekers, ...posters]
85 83
         const queuesById = allPeople.reduce((queuesById, profile) => {
86 84
             queuesById[profile.profile_id] = profile.queue

+ 1
- 1
backend/lib/services/matchqueue.js View File

@@ -13,7 +13,7 @@ module.exports = class MatchQueueService extends Schmervice.Service {
13 13
         const { MatchQueue } = this.server.models()
14 14
         return await MatchQueue.query()
15 15
             .where('profile_id', profileId)
16
-            .andWhere('is_deleted', false)
16
+            .where('is_deleted', 0)
17 17
     }
18 18
     /**
19 19
      * Returns queues by profile id by user type

+ 14
- 5
backend/lib/services/profile.js View File

@@ -116,15 +116,24 @@ module.exports = class ProfileService extends Schmervice.Service {
116 116
 
117 117
     async getProfilesFor(profileIdArray, type) {
118 118
         const { Profile } = this.server.models()
119
-
119
+        // profilesEntries is profiles in database row order 
120 120
         const profilesEntries = await Profile.query()
121 121
             .whereIn('profile_id', profileIdArray)
122 122
             .withGraphFetched('responses')
123 123
             .withGraphFetched('user')
124 124
 
125
-        return profilesEntries.map(profile => {
126
-            return new CompleteProfile(profile, type)
127
-        })
125
+        // taking the info from profilesEntries
126
+        // to repack into completeProfiles
127
+        // in same order as profileIdArray
128
+        const completeProfiles = []
129
+        profileIdArray.forEach(pid => {
130
+            profilesEntries.forEach(entry => {
131
+                if (entry.profile_id == pid) {
132
+                    completeProfiles.push(new CompleteProfile(entry, type))
133
+                }
134
+            })
135
+        })  
136
+        return completeProfiles
128 137
     }
129 138
 
130 139
     /**
@@ -299,7 +308,7 @@ module.exports = class ProfileService extends Schmervice.Service {
299 308
             parseInt(zipCode),
300 309
         )
301 310
         if (!zipInfo) {
302
-            console.log('zip:', zipCode)
311
+            console.error('zip:', zipCode)
303 312
         }
304 313
 
305 314
         return {

+ 0
- 4402
frontend/package-lock.json
File diff suppressed because it is too large
View File


+ 16
- 16
frontend/package.json View File

@@ -9,28 +9,28 @@
9 9
         "format": "prettier .  --write"
10 10
     },
11 11
     "dependencies": {
12
-        "joi": "^17.4.0",
13 12
         "pubnub": "^5.0.0",
14
-        "vue": "^3.0.5",
15
-        "vue-router": "^4.0.12"
13
+        "joi": "^17.6.0",
14
+        "vue": "^3.2.31",
15
+        "vue-router": "^4.0.14"
16 16
     },
17 17
     "devDependencies": {
18
-        "@prettier/plugin-pug": "^1.17.3",
19
-        "@vitejs/plugin-vue": "^1.2.2",
20
-        "@vue/compiler-sfc": "^3.0.5",
21
-        "autoprefixer": "^10.2.5",
22
-        "eslint": "^8.3.0",
23
-        "eslint-config-prettier": "^8.3.0",
24
-        "eslint-plugin-vue": "^8.1.1",
25
-        "naive-ui": "^2.20.3",
26
-        "postcss": "^8.2.13",
27
-        "postcss-calc": "^8.0.0",
28
-        "postcss-import": "^14.0.1",
18
+        "@prettier/plugin-pug": "^1.19.2",
19
+        "@vitejs/plugin-vue": "^2.2.4",
20
+        "@vue/compiler-sfc": "^3.2.31",
21
+        "autoprefixer": "^10.4.2",
22
+        "eslint": "^8.11.0",
23
+        "eslint-config-prettier": "^8.5.0",
24
+        "eslint-plugin-vue": "^8.5.0",
25
+        "naive-ui": "^2.26.4",
26
+        "postcss": "^8.4.8",
27
+        "postcss-calc": "^8.2.4",
28
+        "postcss-import": "^14.0.2",
29 29
         "precss": "^4.0.0",
30 30
         "pug": "^3.0.2",
31 31
         "pug-plain-loader": "^1.1.0",
32
-        "sugarss": "^3.0.3",
33
-        "vite": "^2.2.3",
32
+        "sugarss": "^4.0.1",
33
+        "vite": "^2.8.6",
34 34
         "vite-fs": "^0.0.2",
35 35
         "watch": "^1.0.2"
36 36
     }

+ 23
- 13
frontend/src/components/ProfileCardList.vue View File

@@ -3,15 +3,16 @@ section.profile_card_list.w-full
3 3
     .profile_card_list_container.w-full
4 4
         .swipe(
5 5
             :config='config'
6
-            :key='profile.uid'
6
+            :key='profile.pid'
7 7
             @throwout='swipped(profile)'
8
-            v-for='profile in profiles'
8
+            v-for='(profile, i) in profiles'
9
+            :style='{"z-index": 1000-i}'
9 10
         )
10 11
             .card.b-solid.rounded.p-0.bg-cover(
11 12
                 :style='{ "background-image": `url(${profile.avatar})` }'
12 13
             )
13 14
                 .card__content
14
-                    h3.p-1.mv-0.b-solid.rounded {{ profile.name }}
15
+                    h3.p-1.mv-0.b-solid.rounded {{ profile.pid  }} {{ profile.name }}
15 16
                 nav.swipe_icons.w-full.f-row.between
16 17
                     //- Accept
17 18
                     button.p-1(@click='accept') Accept
@@ -22,9 +23,10 @@ section.profile_card_list.w-full
22 23
 </template>
23 24
 
24 25
 <script setup>
25
-import { computed, defineProps } from 'vue'
26
-import { updateQueueByProfileId } from '../services/queue.service'
26
+import { computed, defineProps, defineEmits } from 'vue'
27
+import { updateQueueByProfileId, fetchMembershipsByProfileId, postMembershipByProfileId } from '../services'
27 28
 
29
+const emit = defineEmits(['reloadQueue'])
28 30
 // TODO: Please review this conversion from script to script setup
29 31
 // converted from the props section
30 32
 const props = defineProps({
@@ -32,14 +34,14 @@ const props = defineProps({
32 34
         type: [Object, Array],
33 35
         default: () => [
34 36
             {
35
-                uid: '1',
37
+                pid: '1',
36 38
                 name: 'Full Name',
37 39
                 avatar: 'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/newborn-baby-boy-sleeping-peacefully-wearing-knit-royalty-free-image-1589459736.jpg?crop=0.669xw:1.00xh;0.228xw,0&resize=640:*',
38 40
                 metadata: { age: '21', rawMetadata: 'Some Text Here!' },
39 41
             },
40 42
         ],
41 43
     },
42
-    uid: {
44
+    pid: {
43 45
         type: Number,
44 46
         default: 9999,
45 47
     },
@@ -54,7 +56,7 @@ const reject = () => {
54 56
 
55 57
 
56 58
 const swipped = profile => {
57
-    const index = props.profiles.findIndex(u => u.uid == profile.uid)
59
+    const index = props.profiles.findIndex(u => u.pid == profile.pid)
58 60
     // TODO: bug, fix this
59 61
     props.profiles.splice(index, 1)
60 62
     profile.id = Date.now() + (Math.random() * 100000).toFixed()
@@ -67,16 +69,23 @@ const onRequest = () => {
67 69
     const data = { ...currentCard }
68 70
 }
69 71
 // AHP Button behavior
70
-const accept = () => {
72
+
73
+const accept = async () => {
71 74
     console.log('accepted aka do NOT reinsert')
72 75
     // need to pass these arguments (profileId, targetId, status)
73 76
     // the url structure is
74 77
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
75 78
     // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
76
-    const profileId = props.uid
77
-    const targetId = props.profiles[0].uid
79
+    const profileId = props.pid
80
+    const targetId = props.profiles[0].pid
78 81
     updateQueueByProfileId(profileId, targetId, false)
79 82
     // TODO: next step is grouping/membership
83
+    const checkMembership = await fetchMembershipsByProfileId(profileId)
84
+    if (!checkMembership.length) {
85
+        console.log('Make membership')
86
+        postMembershipByProfileId({ profileId, targetId })
87
+    }
88
+    emit('reloadQueue')
80 89
 }
81 90
 const hold = () => {
82 91
     console.log('held? do we need this?')
@@ -84,9 +93,10 @@ const hold = () => {
84 93
 const pass = () => {
85 94
     console.log('passed aka do reinsert')
86 95
     // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=true`)
87
-    const profileId = props.uid
88
-    const targetId = props.profiles[0].uid
96
+    const profileId = props.pid
97
+    const targetId = props.profiles[0].pid
89 98
     updateQueueByProfileId(profileId, targetId, true)
99
+    emit('reloadQueue')
90 100
 }
91 101
 
92 102
 // from the data() section

+ 10
- 3
frontend/src/components/Sidebar.vue View File

@@ -1,12 +1,16 @@
1 1
 <template lang="pug">
2
-
3
-aside.sidebar.p-1
2
+aside.sidebar.p-1.f-col.between
4 3
     h3 Messages
5 4
     .search
6 5
         input
7 6
         label search
8 7
 
9 8
     messages(:title="title" :users="users")
9
+    .spacer.f-grow
10
+    .temp-control-box.f-row.start.center
11
+        p.t-up.p-0 current user
12
+        input(v-model='mypid' style="width: 50px")
13
+        button(@click="$emit('updatePid', mypid)").t-up.p-0 switch
10 14
 </template>
11 15
 
12 16
 <script>
@@ -16,7 +20,7 @@ export default {
16 20
     components: { messages }, 
17 21
     data: () => ({
18 22
         title:'Messages from Matches',
19
-        uid: 111,
23
+        mypid: 45,
20 24
         users: [
21 25
             {
22 26
                 name: 'Bob McRob',
@@ -32,6 +36,9 @@ export default {
32 36
             },
33 37
         ],
34 38
     }),
39
+    created() {
40
+        this.$emit('updatePid', this.mypid)
41
+    }
35 42
 }
36 43
 </script>
37 44
 

+ 2
- 4
frontend/src/components/form.vue View File

@@ -107,7 +107,7 @@ const isValid = step => {
107 107
 /**
108 108
  * Save or take the-nNext step in the form
109 109
  */
110
-const next = e => {
110
+const next = async e => {
111 111
     const validity = isValid(state.step - 1)
112 112
     if (validity.error) return console.error(validity.error)
113 113
     if (state.step === props.form.length) {
@@ -128,12 +128,10 @@ const next = e => {
128 128
         // Bc we don't want to pass the 1st question to backend & we want profileId
129 129
         // Necessary atm bc we manually added question in Survey class (entity)
130 130
         const profileId = idWithResponseVal.shift().val
131
-        // TODO: pass maxDistance from an input value somewhere later
132
-        const maxDistance = 10
131
+        const maxDistance = 100
133 132
         saveSurveyByProfileID(idWithResponseVal, profileId)
134 133
         alert('Responses submitted!')
135 134
         resetAnswers()
136
-        // TODO: score here after save survey responses
137 135
         scoreSurveyByProfileId(profileId, maxDistance)
138 136
         state.step = 1
139 137
     } else if (state.step < props.form.length) {

+ 3
- 1
frontend/src/services/grouping.service.js View File

@@ -25,11 +25,13 @@ const postMembershipByProfileId = async ({
25 25
     targetId,
26 26
     groupingType = 'match',
27 27
 }) => {
28
+    const utcDateInSeconds = Date.now()/1000
28 29
     const membership = {
29 30
         target_id: targetId,
30 31
         grouping_type: groupingType,
31
-        grouping_name: `delete_${profileId}_${targetId}`,
32
+        grouping_name: `${utcDateInSeconds}_${profileId}_${targetId}`,
32 33
     }
34
+    console.log('Membership Created')
33 35
     const createdMembershipRecord = await db.post(
34 36
         `/membership/${profileId}/join`,
35 37
         membership,

+ 1
- 1
frontend/src/services/queue.service.js View File

@@ -22,7 +22,7 @@ const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
22 22
     // targetId - the id of the profile viewed by the profileId
23 23
     // reinsert - if profileId accepted targetId, FALSE reinsert so no reinsert; if profileId passed targetId, TRUE reinsert so reinsert at end
24 24
     //
25
-    const updateQueue = db.patch(
25
+    const updateQueue = await db.patch(
26 26
         `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
27 27
         // HELP: responseScheme says the structure should be array of either:
28 28
         // 1) NUMBER

+ 1
- 1
frontend/src/services/survey.service.js View File

@@ -71,7 +71,7 @@ const updateSurveyByProfileId = async (surveyResponses, profileId) => {
71 71
 }
72 72
 
73 73
 const scoreSurveyByProfileId = async (profileId, maxDistance) => {
74
-    const scoreSurvey = db.get(`/profile/${profileId}/score?max_distance=${maxDistance}`)
74
+    const scoreSurvey = await db.get(`/profile/${profileId}/score?max_distance=${maxDistance}`)
75 75
     return scoreSurvey
76 76
 }
77 77
 

+ 8
- 6
frontend/src/views/Matches.vue View File

@@ -1,19 +1,21 @@
1 1
 <template lang="pug">
2
-article.match
3
-    h1 Match Page
2
+sidebar
3
+main.f-col.start.w-full
4
+    article.match
5
+        h1 Match Page
6
+    mainNav
4 7
 </template>
5 8
 
6 9
 <script>
7 10
 import { defineComponent } from 'vue'
11
+import sidebar from '../components/Sidebar.vue'
12
+import mainNav from '../components/MainNav.vue'
8 13
 
9 14
 // import icon from '@/components/icon.vue'
10 15
 // import card from '@/components/card.vue'
11 16
 
12 17
 export default defineComponent({
13
-    components: {
14
-        // card,
15
-        // icon,
16
-    },
18
+    components: { sidebar, mainNav },
17 19
 })
18 20
 </script>
19 21
 

+ 21
- 6
frontend/src/views/home.vue View File

@@ -1,9 +1,10 @@
1 1
 <template lang="pug">
2
-sidebar
2
+sidebar(@updatePid="setPid")
3 3
 main.f-col.start.w-full
4
-    article#home
4
+    article#home(v-if='!loading')
5 5
         h1(v-if='user') {{ user.user_name }}
6
-        profile-card-list(:profiles='swipables' :uid='mypid')
6
+        profile-card-list(:profiles='swipables' :pid='parseInt(mypid)' @reloadQueue='getQueue')
7
+    p(v-else) Loading...
7 8
     main-nav
8 9
 </template>
9 10
 
@@ -26,6 +27,7 @@ export default {
26 27
         swipables: [],
27 28
         user: null,
28 29
         mypid: null,
30
+        loading: true
29 31
     }),
30 32
     mounted() {
31 33
         this.setupChatter()
@@ -52,11 +54,21 @@ export default {
52 54
             c.setup(testAccountUUID)
53 55
             console.log('---')
54 56
         },
57
+        setPid(pid) {
58
+            this.mypid = pid
59
+            this.getQueue()
60
+        },
61
+        async getQueue() {
62
+            this.loading = true
63
+            const queueList = await fetchQueueByProfileId(this.mypid)
64
+            this.processQueue(queueList)
65
+            this.loading = false
66
+        },
55 67
         processQueue(queueList) {
56 68
             const formattedList = []
57 69
             queueList.forEach(profile => {
58 70
                 const formatted = {
59
-                        uid: profile.profile_id,
71
+                        pid: profile.profile_id,
60 72
                         name: profile.user_name,
61 73
                         avatar: profile.user_media,
62 74
                     }
@@ -86,7 +98,7 @@ export default {
86 98
             parsed.profiles.forEach(p => {
87 99
                 // console.log(parsed)
88 100
                 const user = findUser(p)
89
-                p.uid = p.profile_id
101
+                p.pid = p.profile_id
90 102
                 p.name = user.user_name
91 103
                 p.email = user.user_email
92 104
                 p.avatar = p.user_media[0]
@@ -100,7 +112,6 @@ export default {
100 112
                 })
101 113
                 this.swipables.push(p)
102 114
             })
103
-            console.log('swipables', this.swipables)
104 115
         },
105 116
     },
106 117
 }
@@ -114,4 +125,8 @@ main
114 125
         height: 100%
115 126
         width: 100%
116 127
         flex-direction: column
128
+
129
+    input, button
130
+        position: relative
131
+        z-index: 1000
117 132
 </style>

Loading…
Cancel
Save