methods.js 3.3 KB
// 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 { Staffs }                         from '/imports/collections/staff/index';
import { Orgs }                           from '/imports/collections/orgs/index';
export const staffMethods = new ValidatedMethod({
  name: 'staff.method',

  validate: new SimpleSchema({
    itemId: { type: String },
  }).validator(),

  run({itemId}) {
    return {};
  },

});

export const staffAddNew = new ValidatedMethod({
  name: 'staff.addNew',

  validate: new SimpleSchema({
    employeeId:     { type: String },
    firstName:      { type: String },
    lastName:       { type: String },
    martialStatus:  { type: String },
    gender:         { type: String },
    dob:            { type: String },
    desgnation:     { type: String },
    type:           { type: String },
    doj:            { type: String },
    teaching:       { type: String },
    qualifaication: { type: String },
    specialization: { type: String },
    university:     { type: String },
    degreeFrom:     { type: String },
    degreeEnded:    { type: String },
    email:          { type: String },
    phone:          { type: String },
    address:        { type: String },
    city:           { type: String },
    state:          { type: String },
  }).validator(),

  run(data) {
    const user = Users.findOne({_id: Meteor.userId()});
    if(!user) return false;
    const org = Orgs.findOne({_id: user.orgId});
    if(!org) return false;
    // console.log(data);return true;
    orgId = user.orgId;
    newUserId = Users.insert({
      emails:     [{address:data.email, verified: false}],
      phones:     [{number:data.phone, verified: false}],
      firstName:  data.firstName,
      lastName:   data.lastName,
      address:    data.address,
      orgId:      orgId,
      role:       'STAFF'
    });
    console.log("newUserId");
    console.log(newUserId);
    if(newUserId){
      newStaffId = Staffs.insert({
        userId:             newUserId,
        orgId:              orgId,
        employeeId:         data.employeeId,
        martialStatus:      data.martialStatus,
        gender:             data.gender,
        dob:                data.dob,
        teaching:           data.teaching,
        type:               data.type,
        'educationDetails':[{
          qualifaication:   data.qualifaication,
          specialization:   data.specialization,
          university:       data.university,
          from:             data.degreeFrom,
          to:               data.degreeEnded,
        }],
        permanentAddress:{
          address:          data.data,
          city:             data.city,
          state:            data.state,
        },
        doj:                data.doj
      });
    }
    console.log("newStaffId");
    console.log(newStaffId);
    return {};
  },

});