Blame view

imports/collections/parents/index.js 3.17 KB
d19761913   Deepak   added parent schema
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  // import {Parents } from '/imports/collections/parents/index'
  
  import _                                  from 'lodash';
  import { Meteor }                         from 'meteor/meteor';
  import { Mongo }                          from 'meteor/mongo';
  import { SimpleSchema }                   from 'meteor/aldeed:simple-schema';
  
  import { Orgs }                           from '/imports/collections/orgs/index';
  import { Users }                          from '/imports/collections/users/index';
  
  class Parent {
    constructor(doc) {
      _.assign(this, doc);
    };
  
    getUserIds() {
      return _.filter(_.map(this.users, 'userId'));
    };
  };
  export { Parent };
  
  class ParentsCollection extends Mongo.Collection {
    insert(item, callback) {
      _.assign(item, {
        createdAt:        new Date().getTime(),
      });
      return super.insert(item, callback);
    };
  };
  
  export const Parents = new ParentsCollection('Parents', {
    transform: (item) => {
      return new Parent(item);
    },
  });
  
  _.assign(Parents, {
    allStudents: () => {
      const user = Users.current();
      if(!user) return null;
      return Orgs.find({'users.userId': user._id});
    },
    current: () => {
      const user = Users.current();
      if(!user) return null;
      return Orgs.findOne({_id: user.orgId});
    },
    currentOrgUsers: () => {
      const OrgsArr = Orgs.current();
      if(!OrgsArr) return null;
      return OrgsArr.users;
    },
  
  });
  
  Parents.deny({
    insert() { return true; },
    update() { return true; },
    remove() { return true; },
  });
  
  
  Parents.schema = new SimpleSchema({
    userId:               { type: String },
    orgId:                { type: String },
167dd6325   satheesh   [#004]-Revised Sc...
66
    relationship:         { type: String, optional: true },
d19761913   Deepak   added parent schema
67
    gender:               { type: String, optional: true },
167dd6325   satheesh   [#004]-Revised Sc...
68
    profession:           { type: String, optional: true },
df05c55ea   Deepak   fixed views for d...
69
    relationship:         { type: String, optional: true },
d19761913   Deepak   added parent schema
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    permanentAddress: {
      type: new SimpleSchema({
        home:             { type: String, optional: true },
        street:           { type: String, optional: true },
        town:             { type: String, optional: true },
        city:             { type: String, optional: true },
        state:            { type: String, optional: true },
        zip:              { type: String, optional: true },
      }),
      optional: true
    },
    currentAddress: {
      type: new SimpleSchema({
        home:             { type: String, optional: true },
        street:           { type: String, optional: true },
        town:             { type: String, optional: true },
        city:             { type: String, optional: true },
        state:            { type: String, optional: true },
        zip:              { type: String, optional: true },
      }),
      optional: true
    },
    services: {
      type: Object,
      optional: true,
      blackbox: true,
    },
  
    isMetaUser:           { type: Boolean, optional: true },
  
    createdAt:            { type: Date, autoValue: function(){return new Date();}}
  
  });
  
  Parents.attachSchema(Parents.schema);
  
  Parents.privateFields = {
    orgId:              1,
    address:            1,
  
    isMetaUser:         1,
    createdAt:          1,
  };
  
  Parents.publicFields = {
    firstName:          1,
    lastName:           1,
    emails:             1,
  
    createdAt:          1,
  };