Blame view
imports/collections/students/index.js
4.07 KB
d0099dd88
|
1 |
// import {Students } from '/imports/collections/students/methods' |
39d8f536d
|
2 3 4 5 6 7 8 |
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'; |
d0099dd88
|
9 |
import { Users } from '/imports/collections/users/index'; |
39d8f536d
|
10 |
|
d0099dd88
|
11 |
class Student { |
39d8f536d
|
12 13 14 |
constructor(doc) { _.assign(this, doc); }; |
d0099dd88
|
15 16 |
getUserIds() { return _.filter(_.map(this.users, 'userId')); |
39d8f536d
|
17 18 |
}; }; |
d0099dd88
|
19 20 21 22 23 24 25 26 27 |
export { Student }; class StudentsCollection extends Mongo.Collection { insert(item, callback) { _.assign(item, { createdAt: new Date().getTime(), }); return super.insert(item, callback); }; |
39d8f536d
|
28 |
}; |
d0099dd88
|
29 30 31 |
export const Students = new StudentsCollection('Students', { transform: (item) => { return new Student(item); |
39d8f536d
|
32 |
}, |
d0099dd88
|
33 |
}); |
39d8f536d
|
34 |
|
d0099dd88
|
35 36 37 38 39 |
_.assign(Students, { allStudents: () => { const user = Users.current(); if(!user) return null; return Orgs.find({'users.userId': user._id}); |
39d8f536d
|
40 |
}, |
d0099dd88
|
41 42 43 44 45 46 47 48 49 |
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; |
39d8f536d
|
50 |
}, |
d0099dd88
|
51 |
}); |
39d8f536d
|
52 |
|
d0099dd88
|
53 |
Students.deny({ |
39d8f536d
|
54 55 56 57 |
insert() { return true; }, update() { return true; }, remove() { return true; }, }); |
39d8f536d
|
58 |
|
d0099dd88
|
59 60 |
Students.schema = new SimpleSchema({ userId: { type: String }, |
39d8f536d
|
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 |
orgId: { type: String }, admissionId: { type: String, optional: true }, enrollmentDate: { type: String, optional: true }, address: { type: String, optional: true }, prefix: { type: String, optional: true }, firstName: { type: String, optional: true }, middlename: { type: String, optional: true }, lastName: { type: String, optional: true }, gender: { type: String, optional: true }, dob: { type: String, optional: true }, rollNo: { type: String, optional: true }, class: { type: String, optional: true }, section: { type: String, optional: true }, bloodGroup: { type: String, optional: true }, community: { type: String, optional: true }, nationality: { type: String, optional: true }, motherTongue: { type: String, optional: true }, motherTongue: { type: String, optional: true }, religion: { type: String, optional: true }, 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 }, }), |
d0099dd88
|
89 |
optional: true |
39d8f536d
|
90 91 92 93 94 95 |
}, parent: { type: [new SimpleSchema({ id: { type: String, }, relatinship: { type: Boolean, }, })], |
d0099dd88
|
96 |
optional: true |
39d8f536d
|
97 98 99 100 101 102 103 104 105 106 |
}, prevInstitute: { type: [new SimpleSchema({ name: { type: String, }, fromYear: { type: Boolean, }, toYear: { type: Boolean, }, ydId: { type: Boolean, }, })], optional: true }, |
39d8f536d
|
107 108 109 110 111 112 113 114 115 116 117 |
services: { type: Object, optional: true, blackbox: true, }, isMetaUser: { type: Boolean, optional: true }, createdAt: { type: Date, autoValue: function(){return new Date();}} }); |
d0099dd88
|
118 |
Students.attachSchema(Students.schema); |
39d8f536d
|
119 |
|
d0099dd88
|
120 |
Students.privateFields = { |
39d8f536d
|
121 122 123 124 125 126 127 128 129 130 131 |
orgId: 1, address: 1, firstName: 1, lastName: 1, emails: 1, phones: 1, isMetaUser: 1, createdAt: 1, }; |
d0099dd88
|
132 |
Students.publicFields = { |
39d8f536d
|
133 134 135 136 137 138 |
firstName: 1, lastName: 1, emails: 1, createdAt: 1, }; |