methods.js
3.3 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
97
98
// 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 {};
},
});