|
|
@@ -1,48 +1,52 @@
|
|
1
|
|
-const zipcoder = require ('./profile/zipcoder')
|
|
|
1
|
+const zipcoder = require('./profile/zipcoder')
|
|
|
2
|
+const Schmervice = require('@hapipal/schmervice')
|
|
2
|
3
|
|
|
3
|
|
-const byProfileType = (profileList, userProfile) => {
|
|
4
|
|
- const isUserOpposite = userProfile.is_poster == 1 ? 0 : 1
|
|
5
|
|
- return profileList.filter(profile => (profile.user.is_poster == isUserOpposite))
|
|
6
|
|
-}
|
|
7
|
|
-const byNullZip = (profileList) => {
|
|
8
|
|
- return profileList.filter(profile => {
|
|
9
|
|
- return zipcoder.getZipCodeFromProfile(profile) ? true : false
|
|
10
|
|
- })
|
|
11
|
|
-}
|
|
12
|
|
-const byDistance = (profileList, max) => {
|
|
13
|
|
- return profileList.filter(profile => {
|
|
14
|
|
- const profileDistance = Math.floor(parseFloat(profile.distance) * 100)
|
|
15
|
|
- const adjustedMaxDistance = Math.floor(parseFloat(max) * 100)
|
|
16
|
|
- return profileDistance <= adjustedMaxDistance
|
|
17
|
|
- })
|
|
18
|
|
-}
|
|
|
4
|
+module.exports = class FilterService extends Schmervice.Service {
|
|
|
5
|
+ constructor(...args) {
|
|
|
6
|
+ super(...args)
|
|
|
7
|
+ }
|
|
19
|
8
|
|
|
20
|
|
-const byDuration = (profileList, duration) => {
|
|
21
|
|
- return profileList.filter(profile => {
|
|
22
|
|
- // TODO find duration
|
|
23
|
|
- return profile.duration == duration
|
|
24
|
|
- })
|
|
25
|
|
-}
|
|
|
9
|
+ byProfileType(profileList, userProfile) {
|
|
|
10
|
+ const isUserOpposite = userProfile.is_poster === 1 ? 0 : 1
|
|
|
11
|
+ return profileList.filter(
|
|
|
12
|
+ profile => profile.user.is_poster === isUserOpposite,
|
|
|
13
|
+ )
|
|
|
14
|
+ }
|
|
26
|
15
|
|
|
27
|
|
-const byPresence = (profileList, presence) => {
|
|
28
|
|
- return profileList.filter(profile => {
|
|
29
|
|
- // TODO find presence
|
|
30
|
|
- return profile.presence == presence
|
|
31
|
|
- })
|
|
32
|
|
-}
|
|
|
16
|
+ byNullZip(profileList) {
|
|
|
17
|
+ return profileList.filter(profile => {
|
|
|
18
|
+ return zipcoder.getZipCodeFromProfile(profile) ? true : false
|
|
|
19
|
+ })
|
|
|
20
|
+ }
|
|
33
|
21
|
|
|
34
|
|
-const byCertifications = (profileList, certifications) => {
|
|
35
|
|
- return profileList.filter(profile => {
|
|
36
|
|
- // TODO find certifications
|
|
37
|
|
- return profile.certifications == certifications
|
|
38
|
|
- })
|
|
39
|
|
-}
|
|
|
22
|
+ byDistance(profileList, max) {
|
|
|
23
|
+ return profileList.filter(profile => {
|
|
|
24
|
+ const profileDistance = Math.floor(
|
|
|
25
|
+ parseFloat(profile.distance) * 100,
|
|
|
26
|
+ )
|
|
|
27
|
+ const adjustedMaxDistance = Math.floor(parseFloat(max) * 100)
|
|
|
28
|
+ return profileDistance <= adjustedMaxDistance
|
|
|
29
|
+ })
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
|
32
|
+ byDuration(profileList, duration) {
|
|
|
33
|
+ return profileList.filter(profile => {
|
|
|
34
|
+ // TODO find duration
|
|
|
35
|
+ return profile.duration === duration
|
|
|
36
|
+ })
|
|
|
37
|
+ }
|
|
40
|
38
|
|
|
41
|
|
-module.exports = {
|
|
42
|
|
- byProfileType,
|
|
43
|
|
- byNullZip,
|
|
44
|
|
- byDistance,
|
|
45
|
|
- byDuration,
|
|
46
|
|
- byPresence,
|
|
47
|
|
- byCertifications,
|
|
48
|
|
-}
|
|
|
39
|
+ byPresence(profileList, presence) {
|
|
|
40
|
+ return profileList.filter(profile => {
|
|
|
41
|
+ // TODO find presence
|
|
|
42
|
+ return profile.presence === presence
|
|
|
43
|
+ })
|
|
|
44
|
+ }
|
|
|
45
|
+
|
|
|
46
|
+ byCertifications(profileList, certifications) {
|
|
|
47
|
+ return profileList.filter(profile => {
|
|
|
48
|
+ // TODO find certifications
|
|
|
49
|
+ return profile.certifications === certifications
|
|
|
50
|
+ })
|
|
|
51
|
+ }
|
|
|
52
|
+}
|