From d19761913001817679ef8f9fe1203aae27cab2b6 Mon Sep 17 00:00:00 2001 From: Deepak Date: Mon, 20 Mar 2017 12:42:51 +0530 Subject: [PATCH] added parent schema --- .../views/org/admin/students/addStudentForm.js | 313 ++++++++++++++++++++- imports/collections/parents/index.js | 119 ++++++++ imports/collections/parents/methods.js | 99 +++++++ imports/collections/students/methods.js | 68 ++++- 4 files changed, 581 insertions(+), 18 deletions(-) create mode 100644 imports/collections/parents/index.js create mode 100644 imports/collections/parents/methods.js diff --git a/imports/client/views/org/admin/students/addStudentForm.js b/imports/client/views/org/admin/students/addStudentForm.js index dcce5cc..68e9291 100644 --- a/imports/client/views/org/admin/students/addStudentForm.js +++ b/imports/client/views/org/admin/students/addStudentForm.js @@ -26,6 +26,7 @@ export class AddStudentForm extends Component { rollNo: "", class: "", section: "", + community: "", bloodGroup: "", phone: "", address: "", @@ -59,18 +60,112 @@ export class AddStudentForm extends Component { addStudent(e){ e.preventDefault(); e.persist(); - const firstName = this.state.firstName; - const middleName = this.state.middleName; + const firstName = this.state.firstName; + const middleName = this.state.middleName; const lastName = this.state.lastName; - if(firstName==""){ + const admissionId = this.state.admissionId; + const email = this.state.email; + const dob = this.state.dob; + const formattedDob = this.state.formattedDob; + const gender = this.state.gender; + const rollNo = this.state.rollNo; + const studentclass = this.state.class; + const section = this.state.section; + const community = this.state.community; + const bloodGroup = this.state.bloodGroup; + const phone = this.state.phone; + const address = this.state.address; + const city = this.state.city; + const state = this.state.state; + const parentName = this.state.parentName; + const parentEmail = this.state.parentEmail; + const relation = this.state.relation; + const profession = this.state.profession; + const parentGender = this.state.parentGender; + const parentPhone = this.state.parentPhone; + const parentAddress = this.state.parentAddress; + const parentCity = this.state.parentCity; + const parentState = this.state.parentState; + const parentZipcode = this.state.parentZipcode; + if(admissionId==""){ + Bert.alert('Enter Admission Id!', 'danger'); + }else if(firstName==""){ Bert.alert('Enter Fist Name', 'danger'); } else if(middleName==""){ Bert.alert('Enter Middle name!', 'danger'); - } else{ + }else if(lastName==""){ + Bert.alert('Enter Last name!', 'danger'); + }else if(email==""){ + Bert.alert('Enter email!', 'danger'); + }else if(dob==""){ + Bert.alert('Enter DOB!', 'danger'); + }else if(gender==""){ + Bert.alert('Enter Student Gender!', 'danger'); + }else if(studentclass==""){ + Bert.alert('Enter Class!', 'danger'); + }else if(section==""){ + Bert.alert('Enter Section!', 'danger'); + }else if(community==""){ + Bert.alert('Enter Section!', 'danger'); + }else if(bloodGroup==""){ + Bert.alert('Enter Blood Group!', 'danger'); + }else if(phone==""){ + Bert.alert('Enter phone!', 'danger'); + }else if(address==""){ + Bert.alert('Enter address!', 'danger'); + }else if(city==""){ + Bert.alert('Enter city!', 'danger'); + }else if(state==""){ + Bert.alert('Enter state!', 'danger'); + }else if(parentName==""){ + Bert.alert('Enter Parent name!', 'danger'); + }else if(parentEmail==""){ + Bert.alert('Enter Parent Email!', 'danger'); + }else if(relation==""){ + Bert.alert('Enter relation!', 'danger'); + }else if(profession==""){ + Bert.alert('Enter parent profession!', 'danger'); + }else if(parentGender==""){ + Bert.alert("Enter Parent's Gender!", 'danger'); + }else if(parentPhone==""){ + Bert.alert("Enter Parent's Phone!", 'danger'); + }else if(parentAddress==""){ + Bert.alert("Enter Parent's Address!", 'danger'); + }else if(parentCity==""){ + Bert.alert("Enter Parent's City!", 'danger'); + }else if(parentState==""){ + Bert.alert("Enter Parent's State!", 'danger'); + }else if(parentZipcode==""){ + Bert.alert("Enter Parent's zipcode!", 'danger'); + }else{ addStudentManually.call({ - firstName: firstName, - middleName: middleName, - lastName: lastName + admissionId, + firstName, + middleName, + lastName, + email, + dob, + formattedDob, + gender, + rollNo, + studentclass, + section, + community, + bloodGroup, + phone, + address, + city, + state, + parentName, + parentEmail, + relation, + profession, + parentGender, + parentPhone, + parentAddress, + parentCity, + parentState, + parentZipcode }, function (error, result) { console.log(error); console.log(result); @@ -108,6 +203,7 @@ export class AddStudentForm extends Component { onChange={e=>this.onUpdate('middleName',e.target.value)} /> + Last Name this.onUpdate('lastName',e.target.value)} /> + Email @@ -133,6 +230,208 @@ export class AddStudentForm extends Component { onChange={this.handleDob} /> + + + Gender + this.onUpdate('gender',e.target.value)} + > + + + + + + + Roll No + this.onUpdate('rollNo',e.target.value)} + /> + + + Class + this.onUpdate('class',e.target.value)} + /> + + + Section + this.onUpdate('section',e.target.value)} + /> + + + + Community + this.onUpdate('community',e.target.value)} + /> + + + + bloodGroup + this.onUpdate('bloodGroup',e.target.value)} + /> + + + + Phone + this.onUpdate('phone',e.target.value)} + /> + + + + Address + this.onUpdate('address',e.target.value)} + /> + + + + City + this.onUpdate('city',e.target.value)} + /> + + + + State + this.onUpdate('state',e.target.value)} + /> + + + + Parent Name + this.onUpdate('parentName',e.target.value)} + /> + + + + Parent Email + this.onUpdate('parentEmail',e.target.value)} + /> + + + + Relation + this.onUpdate('relation',e.target.value)} + /> + + + + Profession + this.onUpdate('profession',e.target.value)} + /> + + + + Parent Gender + this.onUpdate('parentGender',e.target.value)} + > + + + + + + + Parent Phone + this.onUpdate('parentPhone',e.target.value)} + /> + + + + Parent Address + this.onUpdate('parentAddress',e.target.value)} + /> + + + + Parent City + this.onUpdate('parentCity',e.target.value)} + /> + + + + Parent State + this.onUpdate('parentState',e.target.value)} + /> + + + + Parent Zipcode + this.onUpdate('parentZipcode',e.target.value)} + /> + ); diff --git a/imports/collections/parents/index.js b/imports/collections/parents/index.js new file mode 100644 index 0000000..176d99f --- /dev/null +++ b/imports/collections/parents/index.js @@ -0,0 +1,119 @@ +// 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 }, + relationship: { type: String, optional: true }, + gender: { type: String, optional: true }, + profession: { 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 }, + }), + 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, +}; diff --git a/imports/collections/parents/methods.js b/imports/collections/parents/methods.js new file mode 100644 index 0000000..9f0728c --- /dev/null +++ b/imports/collections/parents/methods.js @@ -0,0 +1,99 @@ +// import {Parents } from '/imports/collections/parents/methods' +import _ from 'lodash'; +import { Meteor } from 'meteor/meteor'; +import { ValidatedMethod } from 'meteor/mdg:validated-method'; +import { SimpleSchema } from 'meteor/aldeed:simple-schema'; +import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { Bert } from 'meteor/themeteorchef:bert'; +import { Users } from '/imports/collections/users/index'; +import { Students } from '/imports/collections/students/index'; +import { Orgs } from '/imports/collections/orgs/index'; +export const studentMethods = new ValidatedMethod({ + name: 'student.method', + + validate: new SimpleSchema({ + itemId: { type: String }, + }).validator(), + + run({itemId}) { + return {}; + }, + +}); + +export const addStudentManually = new ValidatedMethod({ + name: 'student.addManually', + + validate: new SimpleSchema({ + admissionId: { type: String }, + firstName: { type: String }, + middleName: { type: String }, + lastName: { type: String }, + email: { type: String }, + dob: { type: String }, + formattedDob: { type: String }, + gender: { type: String }, + rollNo: { type: String }, + studentclass: { type: String }, + section: { type: String }, + community: { type: String }, + bloodGroup: { type: String }, + phone: { type: String }, + address: { type: String }, + city: { type: String }, + state: { type: String }, + parentName: { type: String }, + parentEmail: { type: String }, + relation: { type: String }, + profession: { type: String }, + parentGender: { type: String }, + parentPhone: { type: String }, + parentAddress: { type: String }, + parentCity: { type: String }, + parentState: { type: String }, + parentZipcode: { type: String }, + }).validator(), + + run(data) { + console.log("data"); + console.log(data); + const user = Users.findOne({_id: this.userId}); + orgId = user.orgId; + newStudentId = Users.insert({ + emails: [data.email], + username: firstName, + firstName: firstName, + middleName: middleName, + lastName: lastName, + orgId: orgId, + role: 'STUDENT' + }); + newParentId = Users.insert({ + emails: [data.parentEmail], + username: parentName, + firstName: parentName, + orgId: orgId, + role: 'PARENT' + }); + console.log("newUserId"); + console.log(newUserId); + if(newUserId){ + Students.insert({ + userId: newUserId, + orgId: orgId, + admissionId: data.admissionId, + address: data.address, + gender: data.gender, + dob: data.dob, + rollNo: data.rollNo, + class: data.studentclass, + section: data.section, + bloodGroup: data.bloodGroup, + community: data.community, + + }); + } + return {newUserId}; + }, + +}); diff --git a/imports/collections/students/methods.js b/imports/collections/students/methods.js index a8a2011..97b7928 100644 --- a/imports/collections/students/methods.js +++ b/imports/collections/students/methods.js @@ -25,26 +25,72 @@ export const addStudentManually = new ValidatedMethod({ name: 'student.addManually', validate: new SimpleSchema({ - firstName: { type: String }, - middleName: { type: String }, - lastName: { type: String }, + admissionId: { type: String }, + firstName: { type: String }, + middleName: { type: String }, + lastName: { type: String }, + email: { type: String }, + dob: { type: String }, + formattedDob: { type: String }, + gender: { type: String }, + rollNo: { type: String }, + studentclass: { type: String }, + section: { type: String }, + community: { type: String }, + bloodGroup: { type: String }, + phone: { type: String }, + address: { type: String }, + city: { type: String }, + state: { type: String }, + parentName: { type: String }, + parentEmail: { type: String }, + relation: { type: String }, + profession: { type: String }, + parentGender: { type: String }, + parentPhone: { type: String }, + parentAddress: { type: String }, + parentCity: { type: String }, + parentState: { type: String }, + parentZipcode: { type: String }, }).validator(), - run({firstName,middleName,lastName}) { + run(data) { + console.log("data"); + console.log(data); const user = Users.findOne({_id: this.userId}); orgId = user.orgId; - newUserId = Users.insert({ - username: firstName, - firstName: firstName, - middleName: middleName, - lastName: lastName, - orgId: orgId, - role: 'STUDENT' + newStudentId = Users.insert({ + emails: [data.email], + username: firstName, + firstName: firstName, + middleName: middleName, + lastName: lastName, + orgId: orgId, + role: 'STUDENT' + }); + newParentId = Users.insert({ + emails: [data.parentEmail], + username: parentName, + firstName: parentName, + orgId: orgId, + role: 'PARENT' }); + console.log("newUserId"); + console.log(newUserId); if(newUserId){ Students.insert({ userId: newUserId, orgId: orgId, + admissionId: data.admissionId, + address: data.address, + gender: data.gender, + dob: data.dob, + rollNo: data.rollNo, + class: data.studentclass, + section: data.section, + bloodGroup: data.bloodGroup, + community: data.community, + }); } return {newUserId}; -- 2.0.0