6 커밋

작성자 SHA1 메시지 날짜
  toj c3ca8cf8b0 :recycle: rename response-keys to questions 2 년 전
  toj 08fbd08675 :recycle: adding back queue 2 년 전
  toj a957f45c3f :recycle: tweaking response schemas 2 년 전
  toj 114bc7dd68 :recycle: adding groupings and responses 2 년 전
  toj 9956dbe859 :recycle: cleaning up schemas and models 2 년 전
  toj f7a39946a8 :recycle: adding membership models 2 년 전

+ 42
- 0
backend/lib/models/grouping.js 파일 보기

@@ -0,0 +1,42 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const groupingSchema = require('../schemas/groupings')
4
+const Profile = require('./profile')
5
+const Tag = require('./tag')
6
+
7
+module.exports = class Grouping extends Schwifty.Model {
8
+    static get tableName() {
9
+        return 'groupings'
10
+    }
11
+    static get relationMappings() {
12
+        return {
13
+            profiles: {
14
+                relation: Schwifty.Model.ManyToManyRelation,
15
+                modelClass: Profile,
16
+                join: {
17
+                    from: 'groupings.grouping_id',
18
+                    through: {
19
+                        from: 'memberships.grouping_id',
20
+                        to: 'memberships.profile_id',
21
+                    },
22
+                    to: 'profiles.profile_id',
23
+                },
24
+            },
25
+            tags: {
26
+                relation: Schwifty.Model.HasManyRelation,
27
+                modelClass: Tag,
28
+                join: {
29
+                    from: 'groupings.grouping_id',
30
+                    through: {
31
+                        from: 'tag_associations.grouping_id',
32
+                        to: 'tag_associations.tag_id',
33
+                    },
34
+                    to: 'tags.tag_id',
35
+                },
36
+            },
37
+        }
38
+    }
39
+    static get joiSchema() {
40
+        return groupingSchema.single
41
+    }
42
+}

+ 29
- 0
backend/lib/models/match-queue.js 파일 보기

@@ -0,0 +1,29 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const User = require('./user')
4
+const queueSchema = require('../schemas/match-queues')
5
+
6
+module.exports = class MatchQueue extends Schwifty.Model {
7
+    static get tableName() {
8
+        return 'match_queues'
9
+    }
10
+    static get relationMappings() {
11
+        return {
12
+            user: {
13
+                relation: Schwifty.Model.HasOneThroughRelation,
14
+                modelClass: User,
15
+                join: {
16
+                    from: 'match_queues.target_id',
17
+                    through: {
18
+                        from: 'profiles.profile_id',
19
+                        to: 'profiles.user_id',
20
+                    },
21
+                    to: 'users.user_id',
22
+                },
23
+            },
24
+        }
25
+    }
26
+    static get joiSchema() {
27
+        return queueSchema.single
28
+    }
29
+}

+ 12
- 0
backend/lib/models/membership.js 파일 보기

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const membershipSchema = require('../schemas/memberships')
4
+
5
+module.exports = class Membership extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'memberships'
8
+    }
9
+    static get joiSchema() {
10
+        return membershipSchema.single
11
+    }
12
+}

+ 43
- 0
backend/lib/models/profile.js 파일 보기

@@ -0,0 +1,43 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const profileSchema = require('../schemas/profile')
4
+const TagAssociationModel = require('./tag-association')
5
+const ResponseModel = require('./response')
6
+const UserModel = require('./user')
7
+
8
+module.exports = class Profile extends Schwifty.Model {
9
+    static get tableName() {
10
+        return 'profiles'
11
+    }
12
+    static get relationMappings() {
13
+        return {
14
+            tags: {
15
+                relation: Schwifty.Model.HasManyRelation,
16
+                modelClass: TagAssociationModel,
17
+                join: {
18
+                    from: 'tag_associations.profile_id',
19
+                    to: 'profiles.profile_id',
20
+                },
21
+            },
22
+            responses: {
23
+                relation: Schwifty.Model.HasManyRelation,
24
+                modelClass: ResponseModel,
25
+                join: {
26
+                    from: 'responses.profile_id',
27
+                    to: 'profiles.profile_id',
28
+                },
29
+            },
30
+            user: {
31
+                relation: Schwifty.Model.BelongsToOneRelation,
32
+                modelClass: UserModel,
33
+                join: {
34
+                    from: 'users.user_id',
35
+                    to: 'profiles.user_id',
36
+                },
37
+            },
38
+        }
39
+    }
40
+    static get joiSchema() {
41
+        return profileSchema.single
42
+    }
43
+}

+ 12
- 0
backend/lib/models/question.js 파일 보기

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const questionSchema = require('../schemas/questions')
4
+
5
+module.exports = class Question extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'questions'
8
+    }
9
+    static get joiSchema() {
10
+        return questionSchema.single
11
+    }
12
+}

+ 12
- 0
backend/lib/models/response.js 파일 보기

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const responseSchema = require('../schemas/response')
4
+
5
+module.exports = class Response extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'responses'
8
+    }
9
+    static get joiSchema() {
10
+        return responseSchema.single
11
+    }
12
+}

+ 25
- 0
backend/lib/models/tag-association.js 파일 보기

@@ -0,0 +1,25 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const associationSchema = require('../schemas/tag-associations')
4
+const Tag = require('./tag')
5
+
6
+module.exports = class TagAssociation extends Schwifty.Model {
7
+    static get tableName() {
8
+        return 'tag_associations'
9
+    }
10
+    static get relationMappings() {
11
+        return {
12
+            description: {
13
+                relation: Schwifty.Model.BelongsToOneRelation,
14
+                modelClass: Tag,
15
+                join: {
16
+                    from: 'tag_associations.tag_id',
17
+                    to: 'tags.tag_id',
18
+                },
19
+            },
20
+        }
21
+    }
22
+    static get joiSchema() {
23
+        return associationSchema.single
24
+    }
25
+}

+ 12
- 0
backend/lib/models/tags.js 파일 보기

@@ -0,0 +1,12 @@
1
+const Schwifty = require('@hapipal/schwifty')
2
+
3
+const tagSchema = require('../schemas/tags')
4
+
5
+module.exports = class Tag extends Schwifty.Model {
6
+    static get tableName() {
7
+        return 'tags'
8
+    }
9
+    static get joiSchema() {
10
+        return tagSchema.single
11
+    }
12
+}

+ 16
- 2
backend/lib/models/user.js 파일 보기

@@ -1,6 +1,8 @@
1
-const { single } = require('../schemas/user')
2 1
 const Schwifty = require('@hapipal/schwifty')
3 2
 
3
+const ProfileModel = require('../profiles')
4
+const userSchema = require('../schemas/users')
5
+
4 6
 /**
5 7
  * @typedef User
6 8
  */
@@ -8,7 +10,19 @@ module.exports = class User extends Schwifty.Model {
8 10
     static get tableName() {
9 11
         return 'users'
10 12
     }
13
+    static get relationMappings() {
14
+        return {
15
+            profiles: {
16
+                relation: Schwifty.Model.HasManyRelation,
17
+                modelClass: ProfileModel,
18
+                join: {
19
+                    from: 'user.profile_id',
20
+                    to: 'profiles.profile_id',
21
+                },
22
+            },
23
+        }
24
+    }
11 25
     static get joiSchema() {
12
-        return single
26
+        return userSchema.single
13 27
     }
14 28
 }

+ 34
- 0
backend/lib/schemas/groupings.js 파일 보기

@@ -0,0 +1,34 @@
1
+const Joi = require('joi')
2
+
3
+const profileSchema = require('./profiles')
4
+
5
+/**
6
+ * Groupings
7
+ * A represents a match, an organization, or anything else
8
+ * that relates multiple profiles to each other.
9
+ */
10
+
11
+// validator is used to validate route input/output
12
+const validator = Joi.object({
13
+    grouping_id: Joi.number(),
14
+    grouping_name: Joi.string(),
15
+    grouping_type: Joi.string(),
16
+    is_paired: Joi.boolean(),
17
+    profile: profileSchema.validator,
18
+}).label('grouping__single_validator')
19
+
20
+const list = Joi.array().items(validator).label('grouping__list_validator')
21
+
22
+// single is used to define database models
23
+const single = Joi.object({
24
+    grouping_id: Joi.number(),
25
+    grouping_name: Joi.string(),
26
+    grouping_type: Joi.string(),
27
+    is_paired: Joi.boolean(),
28
+}).label('grouping__single')
29
+
30
+module.exports = {
31
+    single,
32
+    validator,
33
+    list,
34
+}

+ 38
- 0
backend/lib/schemas/match-queues.js 파일 보기

@@ -0,0 +1,38 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Match Queue
5
+ * A match queue record stores prematched target-profiles
6
+ * to display *in order* for the logged-in profile.
7
+ *
8
+ * example:
9
+ * { profile_id: 2, target_id: 54 }
10
+ * { profile_id: 2, target_id: 27 }
11
+ * { profile_id: 2, target_id: 83 }
12
+ *
13
+ * This example will display profiles 54, 27, 83 to
14
+ * profile 2 when they login.
15
+ */
16
+
17
+// validator is used to validate route input/output
18
+const validator = Joi.object({
19
+    match_queue_id: Joi.number(),
20
+    profile_id: Joi.number().required(),
21
+    target_id: Joi.number().required(),
22
+}).label('queue__single_validator')
23
+
24
+const list = Joi.array().items(validator).label('queue__list_validator')
25
+
26
+// single is used to define database models
27
+const single = Joi.object({
28
+    match_queue_id: Joi.number(),
29
+    profile_id: Joi.number().required(),
30
+    target_id: Joi.number().required(),
31
+    _is_deleted: Joi.boolean().required(),
32
+}).label('queue__single')
33
+
34
+module.exports = {
35
+    single,
36
+    validator,
37
+    list,
38
+}

+ 19
- 0
backend/lib/schemas/media.js 파일 보기

@@ -0,0 +1,19 @@
1
+const Joi = require('joi')
2
+
3
+const validator = Joi.object({
4
+    profile_id: Joi.number(),
5
+    media_url: Joi.string().required(),
6
+    media_type_url: Joi.string().required(),
7
+}).label('media__single_validator')
8
+
9
+const single = Joi.object({
10
+    profile_id: Joi.number(),
11
+    media_url: Joi.string().required(),
12
+    media_type: Joi.string().required(),
13
+    _is_deleted: Joi.number().required(),
14
+}).label('media__single')
15
+
16
+module.exports = {
17
+    single,
18
+    validator,
19
+}

+ 29
- 0
backend/lib/schemas/memberships.js 파일 보기

@@ -0,0 +1,29 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Memberships
5
+ * A membership relates a profile to a grouping.
6
+ */
7
+
8
+// validator is used to validate route input/output
9
+const validator = Joi.object({
10
+    membership_id: Joi.number(),
11
+    profile_id: Joi.number(),
12
+    grouping_id: Joi.number(),
13
+    membership_type: Joi.string().required(),
14
+}).label('membership__single_validator')
15
+
16
+// single is used to define database models
17
+const single = Joi.object({
18
+    membership_id: Joi.number(),
19
+    profile_id: Joi.number(),
20
+    grouping_id: Joi.number(),
21
+    membership_type: Joi.string().required(),
22
+    _can_edit: Joi.number().required(),
23
+    _is_active: Joi.number().required(),
24
+}).label('membership__single')
25
+
26
+module.exports = {
27
+    single,
28
+    validator,
29
+}

+ 35
- 0
backend/lib/schemas/profile.js 파일 보기

@@ -0,0 +1,35 @@
1
+const Joi = require('joi')
2
+const responseSchema = require('./responses')
3
+const userSchema = require('./users')
4
+const associationSchema = require('./tag-associations')
5
+
6
+/**
7
+ * Profiles
8
+ * A profile links a human user to multiple
9
+ * job seeking or job posting profiles.
10
+ */
11
+
12
+// validator is used to validate route input/output
13
+const validator = Joi.object({
14
+    profile_id: Joi.number(),
15
+    user: userSchema.single,
16
+    responses: responseSchema.list,
17
+    reveal: Joi.array().items(),
18
+    tags: associationSchema.list,
19
+    profile_description: Joi.string().allow(null, ''),
20
+}).label('profile__single_validator')
21
+
22
+const list = Joi.array().items(validator).label('profile__list_validator')
23
+
24
+// single is used to define database models
25
+const single = Joi.object({
26
+    profile_id: Joi.number(),
27
+    user_id: Joi.number(),
28
+    _is_deleted: Joi.number(),
29
+}).label('profile__single')
30
+
31
+module.exports = {
32
+    single,
33
+    validator,
34
+    list,
35
+}

+ 33
- 0
backend/lib/schemas/questions.js 파일 보기

@@ -0,0 +1,33 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Response Keys
5
+ * A response key is a question in the onboarding survey.
6
+ * We track the questions we ask to aggregate analytics 
7
+ * about survey effectiveness.
8
+ */
9
+
10
+// validator is used to validate route input/output
11
+const validator = Joi.object({
12
+    question_id: Joi.number().required(),
13
+    question_category: Joi.string().required(),
14
+    question_prompt: Joi.string().required(),
15
+    question_description: Joi.any()
16
+}).label('question__single_validator')
17
+
18
+const list = Joi.array().items(validator).label('question__list_validator')
19
+
20
+// single is used to define database models
21
+const single = Joi.object({
22
+    question_id: Joi.number().required(),
23
+    question_category: Joi.string().required(),
24
+    question_prompt: Joi.string().required(),
25
+    question_description: Joi.any()
26
+}).label('question__single')
27
+
28
+
29
+module.exports = {
30
+    single,
31
+    validator,
32
+    list
33
+}

+ 31
- 0
backend/lib/schemas/responses.js 파일 보기

@@ -0,0 +1,31 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Responses
5
+ * A response records how a profile answers
6
+ * a specific question (response-key).
7
+ */
8
+
9
+// validator is used to validate route input/output
10
+const validator = Joi.object({
11
+    response_key_id: Joi.number(),
12
+    response_id: Joi.number(),
13
+    profile_id: Joi.number(),
14
+    val: Joi.string().allow(null, ''),
15
+}).label('response__single_validator')
16
+
17
+const list = Joi.array().items(validator).label('response__list_validator')
18
+
19
+// single is used to define database models
20
+const single = Joi.object({
21
+    response_key_id: Joi.number(),
22
+    response_id: Joi.number(),
23
+    profile_id: Joi.number(),
24
+    val: Joi.string().allow(null, ''),
25
+}).label('response__single')
26
+
27
+module.exports = {
28
+    single,
29
+    validator,
30
+    list,
31
+}

+ 32
- 0
backend/lib/schemas/tag-associations.js 파일 보기

@@ -0,0 +1,32 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Tag Associations
5
+ * An association is a record linking a
6
+ * profile or grouping to a tag.
7
+ */
8
+
9
+// validator is used to validate route input/output
10
+const validator = Joi.object({
11
+    tag_association_id: Joi.number(),
12
+    profile_id: Joi.number().required(),
13
+    grouping_id: Joi.number(),
14
+    tag_id: Joi.number().required(),
15
+}).label('association__single_validator')
16
+
17
+const list = Joi.array().items(single).label('association__list_validator')
18
+
19
+// single is used to define database models
20
+const single = Joi.object({
21
+    tag_association_id: Joi.number(),
22
+    profile_id: Joi.number().required(),
23
+    grouping_id: Joi.number(),
24
+    tag_id: Joi.number().required(),
25
+    _is_deleted: Joi.boolean().required(),
26
+}).label('association__single')
27
+
28
+module.exports = {
29
+    single,
30
+    validator,
31
+    list,
32
+}

+ 30
- 0
backend/lib/schemas/tags.js 파일 보기

@@ -0,0 +1,30 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Tags
5
+ * A tag describes some attribute to be
6
+ * associated with a profile or grouping.
7
+ */
8
+
9
+// validator is used to validate route input/output
10
+const validator = Joi.object({
11
+    tag_id: Joi.number(),
12
+    tag_category: Joi.string(),
13
+    tag_description: Joi.string(),
14
+}).label('tag__single_validator')
15
+
16
+const list = Joi.array().items(validator).label('tag__list_validator')
17
+
18
+// single is used to define database models
19
+const single = Joi.object({
20
+    tag_id: Joi.number(),
21
+    tag_category: Joi.string(),
22
+    tag_description: Joi.string(),
23
+    _is_active: Joi.number().required(),
24
+}).label('tag__single')
25
+
26
+module.exports = {
27
+    single,
28
+    validator,
29
+    list,
30
+}

+ 0
- 12
backend/lib/schemas/user.js 파일 보기

@@ -1,12 +0,0 @@
1
-const Joi = require('joi')
2
-
3
-module.exports = {
4
-    single: Joi.object({
5
-        user_id: Joi.number(),
6
-        user_name: Joi.string(),
7
-        user_email: Joi.string().required(),
8
-        is_poster: Joi.number().required(),
9
-        is_admin: Joi.number().required(),
10
-        is_verified: Joi.number().required(),
11
-    }).label('user_single'),
12
-}

+ 25
- 0
backend/lib/schemas/users.js 파일 보기

@@ -0,0 +1,25 @@
1
+const Joi = require('joi')
2
+
3
+/**
4
+ * Users
5
+ * A user record is tied to a single person.
6
+ */
7
+
8
+// validator is used to validate route input/output
9
+const validator = Joi.object({
10
+    user_id: Joi.number(),
11
+    user_email: Joi.string().required(),
12
+}).label('user__single_validator')
13
+
14
+// single is used to define database models
15
+const single = Joi.object({
16
+    user_id: Joi.number(),
17
+    user_email: Joi.string().required(),
18
+    is_poster: Joi.number().required(),
19
+    is_verified: Joi.number().required(),
20
+}).label('user__single')
21
+
22
+module.exports = {
23
+    single,
24
+    validator,
25
+}

Loading…
취소
저장