Commit d19761913001817679ef8f9fe1203aae27cab2b6

Authored by Deepak
1 parent 15998a6afd
Exists in master

added parent schema

imports/client/views/org/admin/students/addStudentForm.js
... ... @@ -26,6 +26,7 @@ export class AddStudentForm extends Component {
26 26 rollNo: "",
27 27 class: "",
28 28 section: "",
  29 + community: "",
29 30 bloodGroup: "",
30 31 phone: "",
31 32 address: "",
... ... @@ -59,18 +60,112 @@ export class AddStudentForm extends Component {
59 60 addStudent(e){
60 61 e.preventDefault();
61 62 e.persist();
62   - const firstName = this.state.firstName;
63   - const middleName = this.state.middleName;
  63 + const firstName = this.state.firstName;
  64 + const middleName = this.state.middleName;
64 65 const lastName = this.state.lastName;
65   - if(firstName==""){
  66 + const admissionId = this.state.admissionId;
  67 + const email = this.state.email;
  68 + const dob = this.state.dob;
  69 + const formattedDob = this.state.formattedDob;
  70 + const gender = this.state.gender;
  71 + const rollNo = this.state.rollNo;
  72 + const studentclass = this.state.class;
  73 + const section = this.state.section;
  74 + const community = this.state.community;
  75 + const bloodGroup = this.state.bloodGroup;
  76 + const phone = this.state.phone;
  77 + const address = this.state.address;
  78 + const city = this.state.city;
  79 + const state = this.state.state;
  80 + const parentName = this.state.parentName;
  81 + const parentEmail = this.state.parentEmail;
  82 + const relation = this.state.relation;
  83 + const profession = this.state.profession;
  84 + const parentGender = this.state.parentGender;
  85 + const parentPhone = this.state.parentPhone;
  86 + const parentAddress = this.state.parentAddress;
  87 + const parentCity = this.state.parentCity;
  88 + const parentState = this.state.parentState;
  89 + const parentZipcode = this.state.parentZipcode;
  90 + if(admissionId==""){
  91 + Bert.alert('Enter Admission Id!', 'danger');
  92 + }else if(firstName==""){
66 93 Bert.alert('Enter Fist Name', 'danger');
67 94 } else if(middleName==""){
68 95 Bert.alert('Enter Middle name!', 'danger');
69   - } else{
  96 + }else if(lastName==""){
  97 + Bert.alert('Enter Last name!', 'danger');
  98 + }else if(email==""){
  99 + Bert.alert('Enter email!', 'danger');
  100 + }else if(dob==""){
  101 + Bert.alert('Enter DOB!', 'danger');
  102 + }else if(gender==""){
  103 + Bert.alert('Enter Student Gender!', 'danger');
  104 + }else if(studentclass==""){
  105 + Bert.alert('Enter Class!', 'danger');
  106 + }else if(section==""){
  107 + Bert.alert('Enter Section!', 'danger');
  108 + }else if(community==""){
  109 + Bert.alert('Enter Section!', 'danger');
  110 + }else if(bloodGroup==""){
  111 + Bert.alert('Enter Blood Group!', 'danger');
  112 + }else if(phone==""){
  113 + Bert.alert('Enter phone!', 'danger');
  114 + }else if(address==""){
  115 + Bert.alert('Enter address!', 'danger');
  116 + }else if(city==""){
  117 + Bert.alert('Enter city!', 'danger');
  118 + }else if(state==""){
  119 + Bert.alert('Enter state!', 'danger');
  120 + }else if(parentName==""){
  121 + Bert.alert('Enter Parent name!', 'danger');
  122 + }else if(parentEmail==""){
  123 + Bert.alert('Enter Parent Email!', 'danger');
  124 + }else if(relation==""){
  125 + Bert.alert('Enter relation!', 'danger');
  126 + }else if(profession==""){
  127 + Bert.alert('Enter parent profession!', 'danger');
  128 + }else if(parentGender==""){
  129 + Bert.alert("Enter Parent's Gender!", 'danger');
  130 + }else if(parentPhone==""){
  131 + Bert.alert("Enter Parent's Phone!", 'danger');
  132 + }else if(parentAddress==""){
  133 + Bert.alert("Enter Parent's Address!", 'danger');
  134 + }else if(parentCity==""){
  135 + Bert.alert("Enter Parent's City!", 'danger');
  136 + }else if(parentState==""){
  137 + Bert.alert("Enter Parent's State!", 'danger');
  138 + }else if(parentZipcode==""){
  139 + Bert.alert("Enter Parent's zipcode!", 'danger');
  140 + }else{
70 141 addStudentManually.call({
71   - firstName: firstName,
72   - middleName: middleName,
73   - lastName: lastName
  142 + admissionId,
  143 + firstName,
  144 + middleName,
  145 + lastName,
  146 + email,
  147 + dob,
  148 + formattedDob,
  149 + gender,
  150 + rollNo,
  151 + studentclass,
  152 + section,
  153 + community,
  154 + bloodGroup,
  155 + phone,
  156 + address,
  157 + city,
  158 + state,
  159 + parentName,
  160 + parentEmail,
  161 + relation,
  162 + profession,
  163 + parentGender,
  164 + parentPhone,
  165 + parentAddress,
  166 + parentCity,
  167 + parentState,
  168 + parentZipcode
74 169 }, function (error, result) {
75 170 console.log(error);
76 171 console.log(result);
... ... @@ -108,6 +203,7 @@ export class AddStudentForm extends Component {
108 203 onChange={e=>this.onUpdate('middleName',e.target.value)}
109 204 />
110 205 </FormGroup>
  206 +
111 207 <FormGroup controlId="lastName">
112 208 <ControlLabel>Last Name</ControlLabel>
113 209 <FormControl
... ... @@ -116,6 +212,7 @@ export class AddStudentForm extends Component {
116 212 placeholder="Last Name"
117 213 onChange={e=>this.onUpdate('lastName',e.target.value)}
118 214 />
  215 +
119 216 </FormGroup>
120 217 <FormGroup controlId="email">
121 218 <ControlLabel>Email</ControlLabel>
... ... @@ -133,6 +230,208 @@ export class AddStudentForm extends Component {
133 230 onChange={this.handleDob}
134 231 />
135 232 </FormGroup>
  233 +
  234 + <FormGroup controlId="formControlsSelect">
  235 + <ControlLabel>Gender</ControlLabel>
  236 + <FormControl componentClass="select"
  237 + placeholder="select"
  238 + value={this.state.gender}
  239 + onChange={e=>this.onUpdate('gender',e.target.value)}
  240 + >
  241 + <option value="male">Male</option>
  242 + <option value="female">Female</option>
  243 + </FormControl>
  244 + </FormGroup>
  245 +
  246 + <FormGroup controlId="rollNo">
  247 + <ControlLabel>Roll No</ControlLabel>
  248 + <FormControl
  249 + type="text"
  250 + value={this.state.rollNo}
  251 + placeholder="Roll No"
  252 + onChange={e=>this.onUpdate('rollNo',e.target.value)}
  253 + />
  254 + </FormGroup>
  255 + <FormGroup controlId="class">
  256 + <ControlLabel>Class</ControlLabel>
  257 + <FormControl
  258 + type="text"
  259 + value={this.state.class}
  260 + placeholder="7"
  261 + onChange={e=>this.onUpdate('class',e.target.value)}
  262 + />
  263 + </FormGroup>
  264 + <FormGroup controlId="section">
  265 + <ControlLabel>Section</ControlLabel>
  266 + <FormControl
  267 + type="text"
  268 + value={this.state.section}
  269 + placeholder="B"
  270 + onChange={e=>this.onUpdate('section',e.target.value)}
  271 + />
  272 + </FormGroup>
  273 +
  274 + <FormGroup controlId="community">
  275 + <ControlLabel>Community</ControlLabel>
  276 + <FormControl
  277 + type="text"
  278 + value={this.state.community}
  279 + placeholder="General"
  280 + onChange={e=>this.onUpdate('community',e.target.value)}
  281 + />
  282 + </FormGroup>
  283 +
  284 + <FormGroup controlId="bloodGroup">
  285 + <ControlLabel>bloodGroup</ControlLabel>
  286 + <FormControl
  287 + type="text"
  288 + value={this.state.bloodGroup}
  289 + placeholder="B+"
  290 + onChange={e=>this.onUpdate('bloodGroup',e.target.value)}
  291 + />
  292 + </FormGroup>
  293 +
  294 + <FormGroup controlId="phone">
  295 + <ControlLabel>Phone</ControlLabel>
  296 + <FormControl
  297 + type="text"
  298 + value={this.state.phone}
  299 + placeholder="9999999999"
  300 + onChange={e=>this.onUpdate('phone',e.target.value)}
  301 + />
  302 + </FormGroup>
  303 +
  304 + <FormGroup controlId="address">
  305 + <ControlLabel>Address</ControlLabel>
  306 + <FormControl
  307 + type="text"
  308 + value={this.state.address}
  309 + placeholder="#876, Street, town"
  310 + onChange={e=>this.onUpdate('address',e.target.value)}
  311 + />
  312 + </FormGroup>
  313 +
  314 + <FormGroup controlId="city">
  315 + <ControlLabel>City</ControlLabel>
  316 + <FormControl
  317 + type="text"
  318 + value={this.state.city}
  319 + placeholder="Chennai"
  320 + onChange={e=>this.onUpdate('city',e.target.value)}
  321 + />
  322 + </FormGroup>
  323 +
  324 + <FormGroup controlId="state">
  325 + <ControlLabel>State</ControlLabel>
  326 + <FormControl
  327 + type="text"
  328 + value={this.state.state}
  329 + placeholder="Tamilnadu"
  330 + onChange={e=>this.onUpdate('state',e.target.value)}
  331 + />
  332 + </FormGroup>
  333 +
  334 + <FormGroup controlId="parentName">
  335 + <ControlLabel>Parent Name</ControlLabel>
  336 + <FormControl
  337 + type="text"
  338 + value={this.state.parentName}
  339 + placeholder="John"
  340 + onChange={e=>this.onUpdate('parentName',e.target.value)}
  341 + />
  342 + </FormGroup>
  343 +
  344 + <FormGroup controlId="parentEmail">
  345 + <ControlLabel>Parent Email</ControlLabel>
  346 + <FormControl
  347 + type="text"
  348 + value={this.state.parentEmail}
  349 + placeholder="john@email.com"
  350 + onChange={e=>this.onUpdate('parentEmail',e.target.value)}
  351 + />
  352 + </FormGroup>
  353 +
  354 + <FormGroup controlId="relation">
  355 + <ControlLabel>Relation</ControlLabel>
  356 + <FormControl
  357 + type="text"
  358 + value={this.state.relation}
  359 + placeholder="Father"
  360 + onChange={e=>this.onUpdate('relation',e.target.value)}
  361 + />
  362 + </FormGroup>
  363 +
  364 + <FormGroup controlId="profession">
  365 + <ControlLabel>Profession</ControlLabel>
  366 + <FormControl
  367 + type="text"
  368 + value={this.state.profession}
  369 + placeholder="Farmer"
  370 + onChange={e=>this.onUpdate('profession',e.target.value)}
  371 + />
  372 + </FormGroup>
  373 +
  374 + <FormGroup controlId="parentGender">
  375 + <ControlLabel>Parent Gender</ControlLabel>
  376 + <FormControl componentClass="select"
  377 + placeholder="select"
  378 + value={this.state.parentGender}
  379 + onChange={e=>this.onUpdate('parentGender',e.target.value)}
  380 + >
  381 + <option value="male">Male</option>
  382 + <option value="female">Female</option>
  383 + </FormControl>
  384 + </FormGroup>
  385 +
  386 + <FormGroup controlId="parentPhone">
  387 + <ControlLabel>Parent Phone</ControlLabel>
  388 + <FormControl
  389 + type="text"
  390 + value={this.state.parentPhone}
  391 + placeholder="9876543210"
  392 + onChange={e=>this.onUpdate('parentPhone',e.target.value)}
  393 + />
  394 + </FormGroup>
  395 +
  396 + <FormGroup controlId="parentAddress">
  397 + <ControlLabel>Parent Address</ControlLabel>
  398 + <FormControl
  399 + type="text"
  400 + value={this.state.parentAddress}
  401 + placeholder="#12, street, town"
  402 + onChange={e=>this.onUpdate('parentAddress',e.target.value)}
  403 + />
  404 + </FormGroup>
  405 +
  406 + <FormGroup controlId="parentCity">
  407 + <ControlLabel>Parent City</ControlLabel>
  408 + <FormControl
  409 + type="text"
  410 + value={this.state.parentCity}
  411 + placeholder="Chennai"
  412 + onChange={e=>this.onUpdate('parentCity',e.target.value)}
  413 + />
  414 + </FormGroup>
  415 +
  416 + <FormGroup controlId="parentState">
  417 + <ControlLabel>Parent State</ControlLabel>
  418 + <FormControl
  419 + type="text"
  420 + value={this.state.parentState}
  421 + placeholder="Tamilnadu"
  422 + onChange={e=>this.onUpdate('parentState',e.target.value)}
  423 + />
  424 + </FormGroup>
  425 +
  426 + <FormGroup controlId="parentZipcode">
  427 + <ControlLabel>Parent Zipcode</ControlLabel>
  428 + <FormControl
  429 + type="text"
  430 + value={this.state.parentZipcode}
  431 + placeholder="600031"
  432 + onChange={e=>this.onUpdate('parentZipcode',e.target.value)}
  433 + />
  434 + </FormGroup>
136 435 <Button type="submit" bsStyle="default">Add Student</Button>
137 436 </Form>
138 437 );
... ...
imports/collections/parents/index.js
... ... @@ -0,0 +1,119 @@
  1 +// import {Parents } from '/imports/collections/parents/index'
  2 +
  3 +import _ from 'lodash';
  4 +import { Meteor } from 'meteor/meteor';
  5 +import { Mongo } from 'meteor/mongo';
  6 +import { SimpleSchema } from 'meteor/aldeed:simple-schema';
  7 +
  8 +import { Orgs } from '/imports/collections/orgs/index';
  9 +import { Users } from '/imports/collections/users/index';
  10 +
  11 +class Parent {
  12 + constructor(doc) {
  13 + _.assign(this, doc);
  14 + };
  15 +
  16 + getUserIds() {
  17 + return _.filter(_.map(this.users, 'userId'));
  18 + };
  19 +};
  20 +export { Parent };
  21 +
  22 +class ParentsCollection extends Mongo.Collection {
  23 + insert(item, callback) {
  24 + _.assign(item, {
  25 + createdAt: new Date().getTime(),
  26 + });
  27 + return super.insert(item, callback);
  28 + };
  29 +};
  30 +
  31 +export const Parents = new ParentsCollection('Parents', {
  32 + transform: (item) => {
  33 + return new Parent(item);
  34 + },
  35 +});
  36 +
  37 +_.assign(Parents, {
  38 + allStudents: () => {
  39 + const user = Users.current();
  40 + if(!user) return null;
  41 + return Orgs.find({'users.userId': user._id});
  42 + },
  43 + current: () => {
  44 + const user = Users.current();
  45 + if(!user) return null;
  46 + return Orgs.findOne({_id: user.orgId});
  47 + },
  48 + currentOrgUsers: () => {
  49 + const OrgsArr = Orgs.current();
  50 + if(!OrgsArr) return null;
  51 + return OrgsArr.users;
  52 + },
  53 +
  54 +});
  55 +
  56 +Parents.deny({
  57 + insert() { return true; },
  58 + update() { return true; },
  59 + remove() { return true; },
  60 +});
  61 +
  62 +
  63 +Parents.schema = new SimpleSchema({
  64 + userId: { type: String },
  65 + orgId: { type: String },
  66 + relationship: { type: String, optional: true },
  67 + gender: { type: String, optional: true },
  68 + profession: { type: String, optional: true },
  69 + permanentAddress: {
  70 + type: new SimpleSchema({
  71 + home: { type: String, optional: true },
  72 + street: { type: String, optional: true },
  73 + town: { type: String, optional: true },
  74 + city: { type: String, optional: true },
  75 + state: { type: String, optional: true },
  76 + zip: { type: String, optional: true },
  77 + }),
  78 + optional: true
  79 + },
  80 + currentAddress: {
  81 + type: new SimpleSchema({
  82 + home: { type: String, optional: true },
  83 + street: { type: String, optional: true },
  84 + town: { type: String, optional: true },
  85 + city: { type: String, optional: true },
  86 + state: { type: String, optional: true },
  87 + zip: { type: String, optional: true },
  88 + }),
  89 + optional: true
  90 + },
  91 + services: {
  92 + type: Object,
  93 + optional: true,
  94 + blackbox: true,
  95 + },
  96 +
  97 + isMetaUser: { type: Boolean, optional: true },
  98 +
  99 + createdAt: { type: Date, autoValue: function(){return new Date();}}
  100 +
  101 +});
  102 +
  103 +Parents.attachSchema(Parents.schema);
  104 +
  105 +Parents.privateFields = {
  106 + orgId: 1,
  107 + address: 1,
  108 +
  109 + isMetaUser: 1,
  110 + createdAt: 1,
  111 +};
  112 +
  113 +Parents.publicFields = {
  114 + firstName: 1,
  115 + lastName: 1,
  116 + emails: 1,
  117 +
  118 + createdAt: 1,
  119 +};
... ...
imports/collections/parents/methods.js
... ... @@ -0,0 +1,99 @@
  1 +// import {Parents } from '/imports/collections/parents/methods'
  2 +import _ from 'lodash';
  3 +import { Meteor } from 'meteor/meteor';
  4 +import { ValidatedMethod } from 'meteor/mdg:validated-method';
  5 +import { SimpleSchema } from 'meteor/aldeed:simple-schema';
  6 +import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
  7 +import { Bert } from 'meteor/themeteorchef:bert';
  8 +import { Users } from '/imports/collections/users/index';
  9 +import { Students } from '/imports/collections/students/index';
  10 +import { Orgs } from '/imports/collections/orgs/index';
  11 +export const studentMethods = new ValidatedMethod({
  12 + name: 'student.method',
  13 +
  14 + validate: new SimpleSchema({
  15 + itemId: { type: String },
  16 + }).validator(),
  17 +
  18 + run({itemId}) {
  19 + return {};
  20 + },
  21 +
  22 +});
  23 +
  24 +export const addStudentManually = new ValidatedMethod({
  25 + name: 'student.addManually',
  26 +
  27 + validate: new SimpleSchema({
  28 + admissionId: { type: String },
  29 + firstName: { type: String },
  30 + middleName: { type: String },
  31 + lastName: { type: String },
  32 + email: { type: String },
  33 + dob: { type: String },
  34 + formattedDob: { type: String },
  35 + gender: { type: String },
  36 + rollNo: { type: String },
  37 + studentclass: { type: String },
  38 + section: { type: String },
  39 + community: { type: String },
  40 + bloodGroup: { type: String },
  41 + phone: { type: String },
  42 + address: { type: String },
  43 + city: { type: String },
  44 + state: { type: String },
  45 + parentName: { type: String },
  46 + parentEmail: { type: String },
  47 + relation: { type: String },
  48 + profession: { type: String },
  49 + parentGender: { type: String },
  50 + parentPhone: { type: String },
  51 + parentAddress: { type: String },
  52 + parentCity: { type: String },
  53 + parentState: { type: String },
  54 + parentZipcode: { type: String },
  55 + }).validator(),
  56 +
  57 + run(data) {
  58 + console.log("data");
  59 + console.log(data);
  60 + const user = Users.findOne({_id: this.userId});
  61 + orgId = user.orgId;
  62 + newStudentId = Users.insert({
  63 + emails: [data.email],
  64 + username: firstName,
  65 + firstName: firstName,
  66 + middleName: middleName,
  67 + lastName: lastName,
  68 + orgId: orgId,
  69 + role: 'STUDENT'
  70 + });
  71 + newParentId = Users.insert({
  72 + emails: [data.parentEmail],
  73 + username: parentName,
  74 + firstName: parentName,
  75 + orgId: orgId,
  76 + role: 'PARENT'
  77 + });
  78 + console.log("newUserId");
  79 + console.log(newUserId);
  80 + if(newUserId){
  81 + Students.insert({
  82 + userId: newUserId,
  83 + orgId: orgId,
  84 + admissionId: data.admissionId,
  85 + address: data.address,
  86 + gender: data.gender,
  87 + dob: data.dob,
  88 + rollNo: data.rollNo,
  89 + class: data.studentclass,
  90 + section: data.section,
  91 + bloodGroup: data.bloodGroup,
  92 + community: data.community,
  93 +
  94 + });
  95 + }
  96 + return {newUserId};
  97 + },
  98 +
  99 +});
... ...
imports/collections/students/methods.js
... ... @@ -25,26 +25,72 @@ export const addStudentManually = new ValidatedMethod({
25 25 name: 'student.addManually',
26 26  
27 27 validate: new SimpleSchema({
28   - firstName: { type: String },
29   - middleName: { type: String },
30   - lastName: { type: String },
  28 + admissionId: { type: String },
  29 + firstName: { type: String },
  30 + middleName: { type: String },
  31 + lastName: { type: String },
  32 + email: { type: String },
  33 + dob: { type: String },
  34 + formattedDob: { type: String },
  35 + gender: { type: String },
  36 + rollNo: { type: String },
  37 + studentclass: { type: String },
  38 + section: { type: String },
  39 + community: { type: String },
  40 + bloodGroup: { type: String },
  41 + phone: { type: String },
  42 + address: { type: String },
  43 + city: { type: String },
  44 + state: { type: String },
  45 + parentName: { type: String },
  46 + parentEmail: { type: String },
  47 + relation: { type: String },
  48 + profession: { type: String },
  49 + parentGender: { type: String },
  50 + parentPhone: { type: String },
  51 + parentAddress: { type: String },
  52 + parentCity: { type: String },
  53 + parentState: { type: String },
  54 + parentZipcode: { type: String },
31 55 }).validator(),
32 56  
33   - run({firstName,middleName,lastName}) {
  57 + run(data) {
  58 + console.log("data");
  59 + console.log(data);
34 60 const user = Users.findOne({_id: this.userId});
35 61 orgId = user.orgId;
36   - newUserId = Users.insert({
37   - username: firstName,
38   - firstName: firstName,
39   - middleName: middleName,
40   - lastName: lastName,
41   - orgId: orgId,
42   - role: 'STUDENT'
  62 + newStudentId = Users.insert({
  63 + emails: [data.email],
  64 + username: firstName,
  65 + firstName: firstName,
  66 + middleName: middleName,
  67 + lastName: lastName,
  68 + orgId: orgId,
  69 + role: 'STUDENT'
  70 + });
  71 + newParentId = Users.insert({
  72 + emails: [data.parentEmail],
  73 + username: parentName,
  74 + firstName: parentName,
  75 + orgId: orgId,
  76 + role: 'PARENT'
43 77 });
  78 + console.log("newUserId");
  79 + console.log(newUserId);
44 80 if(newUserId){
45 81 Students.insert({
46 82 userId: newUserId,
47 83 orgId: orgId,
  84 + admissionId: data.admissionId,
  85 + address: data.address,
  86 + gender: data.gender,
  87 + dob: data.dob,
  88 + rollNo: data.rollNo,
  89 + class: data.studentclass,
  90 + section: data.section,
  91 + bloodGroup: data.bloodGroup,
  92 + community: data.community,
  93 +
48 94 });
49 95 }
50 96 return {newUserId};
... ...