Commit dd5d357afe653987bf49fba98e5b85925ea3a1b3
1 parent
9db2d9cbe3
Exists in
master
[#005]-CSV duplicate fix
Showing
2 changed files
with
65 additions
and
52 deletions
Show diff stats
imports/collections/staff/serverCsvUpload.js
1 | // import { } from '/imports/collections/staff/methods'; | 1 | // import { } from '/imports/collections/staff/methods'; |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
4 | import Papa from 'meteor/harrison:papa-parse' | 4 | import Papa from 'meteor/harrison:papa-parse' |
5 | import csv from 'csv2json-convertor' | 5 | import csv from 'csv2json-convertor' |
6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | 6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | 8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
9 | import { Bert } from 'meteor/themeteorchef:bert'; | 9 | import { Bert } from 'meteor/themeteorchef:bert'; |
10 | import { Users } from '/imports/collections/users/index'; | 10 | import { Users } from '/imports/collections/users/index'; |
11 | import { Orgs } from '/imports/collections/orgs/index'; | 11 | import { Orgs } from '/imports/collections/orgs/index'; |
12 | import { Students } from '/imports/collections/students/index' | 12 | import { Students } from '/imports/collections/students/index' |
13 | import { Parents } from '/imports/collections/parents/index'; | 13 | import { Parents } from '/imports/collections/parents/index'; |
14 | import { Staffs } from '/imports/collections/staff/index'; | 14 | import { Staffs } from '/imports/collections/staff/index'; |
15 | import csv1 from 'csv2json-convertor' | 15 | import csv1 from 'csv2json-convertor' |
16 | import json2csv from 'json2csv' | 16 | import json2csv from 'json2csv' |
17 | import fs from 'fs' | 17 | import fs from 'fs' |
18 | import Validation from '/imports/validation/validationMethods'; | 18 | import Validation from '/imports/validation/validationMethods'; |
19 | import Constants from '/imports/constants/constants' | 19 | import Constants from '/imports/constants/constants' |
20 | 20 | ||
21 | export const staffCsvtMethod = new ValidatedMethod({ | 21 | export const staffCsvtMethod = new ValidatedMethod({ |
22 | name: 'staff.csvMethod', | 22 | name: 'staff.csvMethod', |
23 | 23 | ||
24 | validate: new SimpleSchema({ | 24 | validate: new SimpleSchema({ |
25 | itemId: { type: String }, | 25 | itemId: { type: String }, |
26 | }).validator(), | 26 | }).validator(), |
27 | 27 | ||
28 | run({itemId}) { | 28 | run({itemId}) { |
29 | return {}; | 29 | return {}; |
30 | }, | 30 | }, |
31 | 31 | ||
32 | }); | 32 | }); |
33 | 33 | ||
34 | export const staffSaveCsvData = new ValidatedMethod({ | 34 | export const staffSaveCsvData = new ValidatedMethod({ |
35 | name: 'staff.saveCsvData', | 35 | name: 'staff.saveCsvData', |
36 | 36 | ||
37 | validate: null, | 37 | validate: null, |
38 | 38 | ||
39 | run({item,filename,csv_fiels}) { | 39 | run({item,filename,csv_fiels}) { |
40 | var csv = json2csv({ | 40 | var csv = json2csv({ |
41 | data: item, | 41 | data: item, |
42 | fields: csv_fiels | 42 | fields: csv_fiels |
43 | }); | 43 | }); |
44 | fs.writeFile(filename, csv,function(err) { | 44 | fs.writeFile(filename, csv,function(err) { |
45 | if (err) throw err; | 45 | if (err) throw err; |
46 | }); | 46 | }); |
47 | }, | 47 | }, |
48 | }); | 48 | }); |
49 | 49 | ||
50 | export const addStaffCSV= new ValidatedMethod({ | 50 | export const addStaffCSV= new ValidatedMethod({ |
51 | name: 'staff.addCSV', | 51 | name: 'staff.addCSV', |
52 | 52 | ||
53 | validate: null, | 53 | validate: null, |
54 | 54 | ||
55 | run(item){ | 55 | run(item){ |
56 | data = item ; | 56 | data = item ; |
57 | console.log("data"); | 57 | console.log("data"); |
58 | console.log(data); | 58 | console.log(data); |
59 | // return true; | 59 | // return true; |
60 | const user = Users.findOne({_id: this.userId}); | 60 | const user = Users.findOne({_id: this.userId}); |
61 | orgId = user.orgId; | 61 | orgId = user.orgId; |
62 | newStaffId = Users.insert({ | 62 | newStaffId = Users.insert({ |
63 | // emails: [{address:data.email, verified: false}], | 63 | // emails: [{address:data.email, verified: false}], |
64 | //username: data["First Name*"], | 64 | //username: data["First Name*"], |
65 | firstName: data["First Name*"], | 65 | firstName: data["First Name*"], |
66 | lastName: data['Last Name*'], | 66 | lastName: data['Last Name*'], |
67 | emails: [{ address: data['Staff Email*'],verified: false }], | ||
68 | phones: [{ number: data['Staff Phone*'],verified: false }], | ||
67 | orgId: orgId, | 69 | orgId: orgId, |
68 | role: 'STAFF' | 70 | role: 'STAFF' |
69 | }); | 71 | }); |
70 | console.log("newStaffId"); | 72 | console.log("newStaffId"); |
71 | console.log(newStaffId); | 73 | console.log(newStaffId); |
72 | 74 | ||
73 | 75 | ||
74 | 76 | ||
75 | 77 | ||
76 | 78 | ||
77 | if(newStaffId){ | 79 | if(newStaffId){ |
78 | newStaff = Staffs.insert({ | 80 | newStaff = Staffs.insert({ |
79 | userId: newStaffId, | 81 | userId: newStaffId, |
80 | orgId: orgId, | 82 | orgId: orgId, |
81 | 83 | ||
82 | employeeId: data['Employee ID*'], | 84 | employeeId: data['Employee ID*'], |
83 | martialStatus: data['Marital Status(married/unmarried)*'], | 85 | martialStatus: data['Marital Status(married/unmarried)*'], |
84 | dob: data['Staff Birthday(YYYY-MM-DD)*'], | 86 | dob: data['Staff Birthday(YYYY-MM-DD)*'], |
85 | gender: data['Gender(male/female)*'], | 87 | gender: data['Gender(male/female)*'], |
86 | teaching: data['Teaching Staff(yes/no)*'], | 88 | teaching: data['Teaching Staff(yes/no)*'], |
87 | type: data['Job Type(permanent/contract)*'], | 89 | type: data['Job Type(permanent/contract)*'], |
88 | doj: data['Date of joining(YYYY-MM-DD)*'], | 90 | doj: data['Date of joining(YYYY-MM-DD)*'], |
89 | 91 | ||
90 | bloodGroup: data['Blood group*'], | 92 | bloodGroup: data['Blood group*'], |
91 | nationality: data['Nationality*'], | 93 | nationality: data['Nationality*'], |
92 | motherTongue: data['Mother Tongue*'], | 94 | motherTongue: data['Mother Tongue*'], |
93 | religion: data['Religion*'], | 95 | religion: data['Religion*'], |
94 | 96 | ||
95 | PANNumber: data['PAN Number'], | 97 | PANNumber: data['PAN Number'], |
96 | ESINumber: data['ESI Number'], | 98 | ESINumber: data['ESI Number'], |
97 | aadharNumber: data['Aadhar Number'], | 99 | aadharNumber: data['Aadhar Number'], |
98 | PFNumber: data['PF Number'], | 100 | PFNumber: data['PF Number'], |
99 | 101 | ||
100 | permanentAddress: { street: data['Staff Line Address*'], | 102 | permanentAddress: { street: data['Staff Line Address*'], |
101 | city: data['City*'], | 103 | city: data['City*'], |
102 | state: data['State*'], | 104 | state: data['State*'], |
103 | zip: data['Zip*'] | 105 | zip: data['Zip*'] |
104 | }, | 106 | }, |
105 | 107 | ||
106 | 108 | ||
107 | bankdetails: { bankAccountNo: data['Bank Account No'], | 109 | bankdetails: { bankAccountNo: data['Bank Account No'], |
108 | bankIFSC: data['Bank IFSC'], | 110 | bankIFSC: data['Bank IFSC'], |
109 | bankBranchDetails: data['Bank Branch Details'] | 111 | bankBranchDetails: data['Bank Branch Details'] |
110 | }, | 112 | }, |
111 | 113 | ||
112 | workingExperience: [{ previousJobRole: data['Previous job Role'], | 114 | workingExperience: [{ previousJobRole: data['Previous job Role'], |
113 | previousJobType: data['Previous Job Type'], | 115 | previousJobType: data['Previous Job Type'], |
114 | previousOrganization: data['Previous Organization'], | 116 | previousOrganization: data['Previous Organization'], |
115 | from: data['From'], | 117 | from: data['From'], |
116 | to: data['To'] | 118 | to: data['To'] |
117 | }], | 119 | }], |
118 | 120 | ||
119 | educationDetails: [{ qualifaication: data['Qualification*'], | 121 | educationDetails: [{ qualifaication: data['Qualification*'], |
120 | specialization: data['Specialization*'], | 122 | specialization: data['Specialization*'], |
121 | university: data['University*'], | 123 | university: data['University*'], |
122 | from: data['From*'], | 124 | from: data['From*'], |
123 | to: data['To*'] | 125 | to: data['To*'] |
124 | }] | 126 | }] |
125 | 127 | ||
126 | 128 | ||
127 | }); | 129 | }); |
128 | console.log("newStaff"); | 130 | console.log("newStaff"); |
129 | console.log(newStaff); | 131 | console.log(newStaff); |
130 | } | 132 | } |
131 | return {newStaffId}; | 133 | return {newStaffId}; |
132 | }, | 134 | }, |
133 | 135 | ||
134 | }); | 136 | }); |
135 | 137 | ||
136 | export const staffUploadCsv = new ValidatedMethod({ | 138 | export const staffUploadCsv = new ValidatedMethod({ |
137 | name: 'staff.uploadCsv', | 139 | name: 'staff.uploadCsv', |
138 | 140 | ||
139 | validate: null, | 141 | validate: null, |
140 | 142 | ||
141 | run({data}) { | 143 | run({data}) { |
142 | let validation = new Validation(); | 144 | let validation = new Validation(); |
143 | let constants = new Constants(); | 145 | let constants = new Constants(); |
144 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); | ||
145 | temp = constants.csv_students_data(); | ||
146 | console.log(temp); | ||
147 | var CSV_valid_buffer = []; | 146 | var CSV_valid_buffer = []; |
148 | var CSV_invalid_buffer = []; | 147 | var CSV_invalid_buffer = []; |
149 | var filename = "Staff-" + new Date().getTime().toString(); | 148 | var filename = "Staff-" + new Date().getTime().toString(); |
150 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/Youngdesk/ydapp/CSV_Files/'; | 149 | var csv_filepath = '/Users/satheeshnagaraj/Documents/Workspace/Meteor/Youngdesk/ydapp/CSV_Files/'; |
151 | for (let i = 0; i < data.length; i++) | 150 | for (let i = 0; i < data.length; i++) |
152 | { | 151 | { |
153 | let item = data[i]; | 152 | let item = data[i]; |
154 | delete item['Errors']; | 153 | delete item['Errors']; |
155 | var formate_validation = 1; | 154 | var formate_validation = 1; |
156 | var is_not_null = 1; | 155 | var is_not_null = 1; |
157 | var errors = []; | 156 | var errors = []; |
158 | for (var key in item){ | 157 | for (var key in item){ |
159 | var value = item[key]; | 158 | var value = item[key]; |
160 | var n = key.indexOf("*"); | 159 | var n = key.indexOf("*"); |
161 | if(n!=-1) { | 160 | if(n!=-1) { |
162 | if(!(validation.notNull(value))) | 161 | if(!(validation.notNull(value))) |
163 | { | 162 | { |
164 | errors.push(key+"is Empty"); | 163 | errors.push(key+"is Empty"); |
165 | } | 164 | } |
166 | is_not_null = is_not_null && validation.notNull(value); | 165 | is_not_null = is_not_null && validation.notNull(value); |
167 | } | 166 | } |
168 | } | 167 | } |
169 | var formate_validation = validation.validateEmail(item["Staff Email*"]) && validation.mobileNumber(item["Staff Phone*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); | 168 | var formate_validation = validation.validateEmail(item["Staff Email*"]) && validation.mobileNumber(item["Staff Phone*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); |
170 | 169 | ||
171 | if (!(validation.validateEmail(item["Staff Email*"]))){ | 170 | if (!(validation.validateEmail(item["Staff Email*"]))){ |
172 | errors.push('Staff Email is invalid'); | 171 | errors.push('Staff Email is invalid'); |
173 | } | 172 | } |
174 | if (!(validation.mobileNumber(item["Staff Phone*"]))) | 173 | if (!(validation.mobileNumber(item["Staff Phone*"]))) |
175 | { | 174 | { |
176 | errors.push('Staffs Mobile is invalid'); | 175 | errors.push('Staffs Mobile is invalid'); |
177 | } | 176 | } |
178 | 177 | ||
179 | var is_valid = formate_validation && is_not_null ; | 178 | var is_valid = formate_validation && is_not_null ; |
179 | |||
180 | |||
181 | |||
180 | if (is_valid) | 182 | if (is_valid) |
181 | { | 183 | { |
182 | CSV_valid_buffer.push(item); | 184 | exists = Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"],'emails.$.address' : item['Staff Email*'],'phones.$.number' : item['Staff Phone*']}, {"_id": 1}); |
183 | console.log("----------------------------------------1"); | ||
184 | 185 | ||
185 | Meteor.call('staff.addCSV',item); | 186 | if (!exists) |
186 | console.log("----------------------------------------2"); | 187 | { |
187 | 188 | CSV_valid_buffer.push(item); | |
189 | Meteor.call('staff.addCSV',item); | ||
190 | console.warn('done'); | ||
191 | } | ||
192 | else | ||
193 | { | ||
194 | console.warn('This data already exists.'); | ||
195 | errors.push('This data already exists'); | ||
196 | var str = errors.toString(); | ||
197 | item.Errors = str; | ||
198 | CSV_invalid_buffer.push(item); | ||
199 | } | ||
200 | |||
188 | } | 201 | } |
189 | else | 202 | |
190 | { | ||
191 | var str = errors.toString(); | ||
192 | item.Errors = str; | ||
193 | CSV_invalid_buffer.push(item); | ||
194 | } | ||
195 | } | 203 | } |
204 |
imports/collections/students/serverCsvUpload.js
1 | // import { } from '/imports/collections/orgs/methods'; | 1 | // import { } from '/imports/collections/orgs/methods'; |
2 | import _ from 'lodash'; | 2 | import _ from 'lodash'; |
3 | import { Meteor } from 'meteor/meteor'; | 3 | import { Meteor } from 'meteor/meteor'; |
4 | import Papa from 'meteor/harrison:papa-parse' | 4 | import Papa from 'meteor/harrison:papa-parse' |
5 | import csv from 'csv2json-convertor' | 5 | import csv from 'csv2json-convertor' |
6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; | 6 | import { ValidatedMethod } from 'meteor/mdg:validated-method'; |
7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; | 7 | import { SimpleSchema } from 'meteor/aldeed:simple-schema'; |
8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; | 8 | import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
9 | import { Bert } from 'meteor/themeteorchef:bert'; | 9 | import { Bert } from 'meteor/themeteorchef:bert'; |
10 | import { Users } from '/imports/collections/users/index'; | 10 | import { Users } from '/imports/collections/users/index'; |
11 | import { Orgs } from '/imports/collections/orgs/index'; | 11 | import { Orgs } from '/imports/collections/orgs/index'; |
12 | import { Students } from '/imports/collections/students/index' | 12 | import { Students } from '/imports/collections/students/index' |
13 | import { Parents } from '/imports/collections/parents/index'; | 13 | import { Parents } from '/imports/collections/parents/index'; |
14 | import csv1 from 'csv2json-convertor' | 14 | import csv1 from 'csv2json-convertor' |
15 | import json2csv from 'json2csv' | 15 | import json2csv from 'json2csv' |
16 | import fs from 'fs' | 16 | import fs from 'fs' |
17 | import Validation from '/imports/validation/validationMethods'; | 17 | import Validation from '/imports/validation/validationMethods'; |
18 | import Constants from '/imports/constants/constants' | 18 | import Constants from '/imports/constants/constants' |
19 | 19 | ||
20 | export const studenCsvtMethod = new ValidatedMethod({ | 20 | export const studenCsvtMethod = new ValidatedMethod({ |
21 | name: 'student.csvMethod', | 21 | name: 'student.csvMethod', |
22 | 22 | ||
23 | validate: new SimpleSchema({ | 23 | validate: new SimpleSchema({ |
24 | itemId: { type: String }, | 24 | itemId: { type: String }, |
25 | }).validator(), | 25 | }).validator(), |
26 | 26 | ||
27 | run({itemId}) { | 27 | run({itemId}) { |
28 | return {}; | 28 | return {}; |
29 | }, | 29 | }, |
30 | 30 | ||
31 | }); | 31 | }); |
32 | 32 | ||
33 | export const save_csv_data = new ValidatedMethod({ | 33 | export const save_csv_data = new ValidatedMethod({ |
34 | name: 'save_csv_data', | 34 | name: 'save_csv_data', |
35 | 35 | ||
36 | validate: null, | 36 | validate: null, |
37 | 37 | ||
38 | run({item,filename,csv_fiels}) { | 38 | run({item,filename,csv_fiels}) { |
39 | 39 | ||
40 | if ((item.length)) | 40 | if ((item.length)) |
41 | { console.log("++++++++++++++++++"+item.length) | 41 | { console.log("++++++++++++++++++"+item.length) |
42 | var csv = json2csv({ | 42 | var csv = json2csv({ |
43 | data: item, | 43 | data: item, |
44 | fields: csv_fiels | 44 | fields: csv_fiels |
45 | }); | 45 | }); |
46 | fs.writeFile(filename, csv,function(err) { | 46 | fs.writeFile(filename, csv,function(err) { |
47 | if (err) throw err; | 47 | if (err) throw err; |
48 | }); | 48 | }); |
49 | 49 | ||
50 | } | 50 | } |
51 | }, | 51 | }, |
52 | }); | 52 | }); |
53 | 53 | ||
54 | export const addStudentCSV= new ValidatedMethod({ | 54 | export const addStudentCSV= new ValidatedMethod({ |
55 | name: 'student.addCSV', | 55 | name: 'student.addCSV', |
56 | 56 | ||
57 | validate: null, | 57 | validate: null, |
58 | 58 | ||
59 | run(item){ | 59 | run(item){ |
60 | data = item ; | 60 | data = item ; |
61 | console.log("data"); | ||
62 | console.log(data); | ||
63 | // return true; | ||
64 | const user = Users.findOne({_id: this.userId}); | 61 | const user = Users.findOne({_id: this.userId}); |
65 | orgId = user.orgId; | 62 | orgId = user.orgId; |
66 | newStudentId = Users.insert({ | 63 | newStudentId = Users.insert({ |
67 | // emails: [{address:data.email, verified: false}], | 64 | // emails: [{address:data.email, verified: false}], |
68 | //username: data["First Name*"], | 65 | //username: data["First Name*"], |
69 | firstName: data["First Name*"], | 66 | firstName: data["First Name*"], |
70 | lastName: data['Last Name*'], | 67 | lastName: data['Last Name*'], |
71 | orgId: orgId, | 68 | orgId: orgId, |
72 | role: 'STUDENT' | 69 | role: 'STUDENT' |
73 | }); | 70 | }); |
74 | newParentUserId = Users.insert({ | 71 | newParentUserId = Users.insert({ |
75 | //emails: [{address:data.parentEmail, verified: false}], | 72 | //emails: [{address:data.parentEmail, verified: false}], |
76 | //3: data['Parent Name*'], | 73 | //3: data['Parent Name*'], |
77 | firstName: data['Parent Name*'], | ||
78 | orgId: orgId, | 74 | orgId: orgId, |
75 | firstName: data['Parent Name*'], | ||
76 | emails: [{ address: data['Parent Email*'],verified: false }], | ||
77 | phones: [{ number: data['Parent Mobile*'],verified: false }], | ||
79 | role: 'PARENT' | 78 | role: 'PARENT' |
79 | |||
80 | }); | 80 | }); |
81 | if(newParentUserId){ | 81 | if(newParentUserId){ |
82 | newParentId = Parents.insert({ | 82 | newParentId = Parents.insert({ |
83 | userId: newParentUserId, | 83 | userId: newParentUserId, |
84 | orgId: orgId, | 84 | orgId: orgId, |
85 | profession: data['Parent Profession'] | 85 | profession: data['Parent Profession'] |
86 | 86 | ||
87 | }); | 87 | }); |
88 | console.log("newParentUserId"); | 88 | console.log("newParentUserId"); |
89 | console.log(newParentUserId); | 89 | console.log(newParentUserId); |
90 | } | 90 | } |
91 | console.log("newUserId"); | 91 | console.log("newUserId"); |
92 | console.log(newStudentId); | 92 | console.log(newStudentId); |
93 | if(newStudentId){ | 93 | if(newStudentId){ |
94 | Students.insert({ | 94 | Students.insert({ |
95 | userId: newStudentId, | 95 | userId: newStudentId, |
96 | orgId: orgId, | 96 | orgId: orgId, |
97 | admissionId: data['Student Admission ID*'], | 97 | admissionId: data['Student Admission ID*'], |
98 | enrollmentDate: data['Enrollment Date(YYYY-MM-DD)*'], | 98 | enrollmentDate: data['Enrollment Date(YYYY-MM-DD)*'], |
99 | gender: data['Gender(male/female)*'], | 99 | gender: data['Gender(male/female)*'], |
100 | dob: data['Birthday(YYYY-MM-DD)*'], | 100 | dob: data['Birthday(YYYY-MM-DD)*'], |
101 | bloodGroup: data['Blood Group*'], | 101 | bloodGroup: data['Blood Group*'], |
102 | nationality: data['Nationality*'], | 102 | nationality: data['Nationality*'], |
103 | motherTongue: data['Mother Tongue*'], | 103 | motherTongue: data['Mother Tongue*'], |
104 | religion: data['Religion*'], | 104 | religion: data['Religion*'], |
105 | community: data['Community'], | 105 | community: data['Community'], |
106 | 106 | ||
107 | rollNo: data['Student Roll*'], | 107 | rollNo: data['Student Roll*'], |
108 | class: data['Student Class Name*'], | 108 | class: data['Student Class Name*'], |
109 | section: data['Student Section Name*'], | 109 | section: data['Student Section Name*'], |
110 | 110 | ||
111 | prevInstitute: [{ name: data['Previous Institution Name'], | 111 | prevInstitute: [{ name: data['Previous Institution Name'], |
112 | fromYear: data['Class-From'], | 112 | fromYear: data['Class-From'], |
113 | toYear: data['Class-To'], | 113 | toYear: data['Class-To'], |
114 | fromClass: data['From-Year'], | 114 | fromClass: data['From-Year'], |
115 | toClass: data['To-Year'] | 115 | toClass: data['To-Year'] |
116 | }], | 116 | }], |
117 | permanentAddress: { street: data['Student Line Adress*'], | 117 | permanentAddress: { street: data['Student Line Adress*'], |
118 | city: data['Student City*'], | 118 | city: data['Student City*'], |
119 | state: data['Student State*'], | 119 | state: data['Student State*'], |
120 | zip: data['Student Zip Code*'] | 120 | zip: data['Student Zip Code*'] |
121 | }, | 121 | }, |
122 | parent: [{id: newParentUserId, relatinship: data['Parent Relation*']}] | 122 | parent: [{id: newParentUserId, relatinship: data['Parent Relation*']}] |
123 | }); | 123 | }); |
124 | } | 124 | } |
125 | return {newStudentId}; | 125 | return {newStudentId}; |
126 | }, | 126 | }, |
127 | 127 | ||
128 | }); | 128 | }); |
129 | 129 | ||
130 | export const studentUploadCsv = new ValidatedMethod({ | 130 | export const studentUploadCsv = new ValidatedMethod({ |
131 | name: 'student.uploadCsv', | 131 | name: 'student.uploadCsv', |
132 | 132 | ||
133 | validate: null, | 133 | validate: null, |
134 | 134 | ||
135 | run({data}) { | 135 | run({data}) { |
136 | let validation = new Validation(); | 136 | let validation = new Validation(); |
137 | let constants = new Constants(); | 137 | let constants = new Constants(); |
138 | //console.log("++++++++++++++++++++++++"+constants.csv_students_data()); | 138 | |
139 | temp = constants.csv_students_data(); | ||
140 | // | ||
141 | console.log(temp); | ||
142 | // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object | 139 | // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object |
143 | //console.log(data);'' | 140 | //console.log(data);'' |
144 | // Stores = new Mongo.Collection('stores'); | 141 | // Stores = new Mongo.Collection('stores'); |
145 | // data = data_1; | 142 | // data = data_1; |
146 | 143 | ||
147 | var CSV_valid_buffer = []; | 144 | var CSV_valid_buffer = []; |
148 | var CSV_invalid_buffer = []; | 145 | var CSV_invalid_buffer = []; |
149 | var filename = "Student" + new Date().getTime().toString(); | 146 | var filename = "Student" + new Date().getTime().toString(); |
150 | var csv_filepath = '/Users/deepak/dev/yd/csv'; | 147 | var csv_filepath ='/Users/satheeshnagaraj/Documents/Workspace/Meteor/production/ydapp/CSV_Files/'; |
148 | //var csv_filepath = '/Users/deepak/dev/yd/csv'; | ||
151 | 149 | ||
152 | 150 | ||
153 | 151 | ||
154 | for (let i = 0; i < data.length; i++) | 152 | for (let i = 0; i < data.length; i++) |
155 | { | 153 | { |
156 | 154 | ||
157 | //let item= {Errors:""}; | 155 | //let item= {Errors:""}; |
158 | let item = data[i]; | 156 | let item = data[i]; |
159 | delete item['Errors']; | 157 | delete item['Errors']; |
160 | var formate_validation = 1; | 158 | var formate_validation = 1; |
161 | var is_not_null = 1; | 159 | var is_not_null = 1; |
162 | var errors = []; | 160 | var errors = []; |
163 | for (var key in item) | 161 | for (var key in item) |
164 | { | 162 | { |
165 | var value = item[key]; | 163 | var value = item[key]; |
166 | var n = key.indexOf("*"); | 164 | var n = key.indexOf("*"); |
167 | if(n!=-1) { | 165 | if(n!=-1) { |
168 | if(!(validation.notNull(value))) | 166 | if(!(validation.notNull(value))) |
169 | { | 167 | { |
170 | errors.push(key+"is Empty"); | 168 | errors.push(key+"is Empty"); |
171 | } | 169 | } |
172 | is_not_null = is_not_null && validation.notNull(value); | 170 | is_not_null = is_not_null && validation.notNull(value); |
173 | } | 171 | } |
174 | } | 172 | } |
175 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); | 173 | //console.log(validation.mobileNumber(item["Parent Mobile*"])); |
176 | 174 | ||
177 | 175 | ||
178 | 176 | ||
179 | 177 | ||
180 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); | 178 | var formate_validation = validation.validateEmail(item["Parent Email*"]) && validation.mobileNumber(item["Parent Mobile*"]) ; //&& validation.validateEmail(item["Parent Mobile"]) ); |
181 | 179 | ||
182 | if (!(validation.validateEmail(item["Parent Email*"]))) | 180 | if (!(validation.validateEmail(item["Parent Email*"]))) |
183 | { | 181 | { |
184 | errors.push('Parent Email is invalid'); | 182 | errors.push('Parent Email is invalid'); |
185 | } | 183 | } |
186 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) | 184 | if (!(validation.mobileNumber(item["Parent Mobile*"]))) |
187 | { | 185 | { |
188 | errors.push('Parent Mobile is invalid'); | 186 | errors.push('Parent Mobile is invalid'); |
189 | } | 187 | } |
190 | 188 | ||
191 | var is_valid = formate_validation && is_not_null ; | 189 | var is_valid = formate_validation && is_not_null ; |
192 | 190 | ||
193 | // console.log(formate_validation); | 191 | // console.log(formate_validation); |
194 | if (is_valid) | 192 | if (is_valid) |
195 | { | 193 | { |
196 | CSV_valid_buffer.push(item); | 194 | |
197 | console.log("----------------------------------------1"); | 195 | exists = Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"]}, {"_id": 1}); |
198 | console.log("----------------------------------------item"); | 196 | |
199 | console.log(item); | 197 | if (!exists) |
200 | console.log (Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"]})); | 198 | { |
201 | 199 | CSV_valid_buffer.push(item); | |
202 | Meteor.call('student.addCSV',item); | 200 | Meteor.call('student.addCSV',item); |
203 | console.log("----------------------------------------2"); | 201 | console.warn('done'); |
204 | 202 | } | |
205 | // exists = Stores.findOne({ | 203 | else |
206 | // "Student 'Admission' ID*": item["Student Admission ID*"] | 204 | { |
207 | // }); | 205 | console.log(exists._id); |
208 | // if (!exists) | 206 | student_data = Students.findOne({"userId":exists._id}); |
209 | // { | 207 | console.log("--------------"+student_data); |
210 | // Stores.insert(item); | 208 | |
211 | // } | 209 | parent_data = Users.findOne({"_id":student_data.parent[0].id}); |
212 | // else | 210 | |
213 | // { | 211 | console.log(parent_data.emails[0].address); |
214 | // console.warn('Rejected. This item already exists.'); | 212 | if ( parent_data.emails[0].address != item["Parent Email*"]) |
215 | // } | 213 | { |
216 | } | 214 | CSV_valid_buffer.push(item); |
217 | else | 215 | Meteor.call('student.addCSV',item); |
218 | { | 216 | console.warn('done'); |
219 | var str = errors.toString(); | 217 | } |
220 | item.Errors = str; | 218 | else |
221 | CSV_invalid_buffer.push(item); | 219 | { |
222 | //console.log(str); | 220 | console.warn('This data already exists.'); |
223 | // console.log(CSV_invalid_buffer); | 221 | errors.push('This data already exists'); |
224 | } | 222 | var str = errors.toString(); |
223 | item.Errors = str; | ||
224 | CSV_invalid_buffer.push(item); | ||
225 | } | ||
226 | } | ||
227 | } | ||
225 | } | 228 | } |