index.js
2.21 KB
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
66
67
68
69
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
// 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 Teacher {
constructor(doc) {
_.assign(this, doc);
};
getUserIds() {
return _.filter(_.map(this.users, 'userId'));
};
};
export { Teacher };
class TeachersCollection extends Mongo.Collection {
insert(item, callback) {
_.assign(item, {
createdAt: new Date().getTime(),
});
return super.insert(item, callback);
};
};
export const Teachers = new TeachersCollection('Teachers', {
transform: (item) => {
return new Teacher(item);
},
});
_.assign(Teachers, {
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;
},
});
Teachers.deny({
insert() { return true; },
update() { return true; },
remove() { return true; },
});
Teachers.schema = new SimpleSchema({
userId: { type: String },
orgId: { type: String },
type: { type: String },
gender: { type: String, optional: true },
services: {
type: Object,
optional: true,
blackbox: true,
},
isMetaUser: { type: Boolean, optional: true },
createdAt: { type: Date, autoValue: function(){return new Date();}}
});
Teachers.attachSchema(Teachers.schema);
Teachers.privateFields = {
orgId: 1,
address: 1,
isMetaUser: 1,
createdAt: 1,
};
Teachers.publicFields = {
firstName: 1,
lastName: 1,
emails: 1,
createdAt: 1,
};