Commit dd5d357afe653987bf49fba98e5b85925ea3a1b3

Authored by satheesh
1 parent 9db2d9cbe3
Exists in master

[#005]-CSV duplicate fix

imports/collections/staff/serverCsvUpload.js
... ... @@ -64,6 +64,8 @@ export const addStaffCSV= new ValidatedMethod({
64 64 //username: data["First Name*"],
65 65 firstName: data["First Name*"],
66 66 lastName: data['Last Name*'],
  67 + emails: [{ address: data['Staff Email*'],verified: false }],
  68 + phones: [{ number: data['Staff Phone*'],verified: false }],
67 69 orgId: orgId,
68 70 role: 'STAFF'
69 71 });
... ... @@ -141,9 +143,6 @@ export const staffUploadCsv = new ValidatedMethod({
141 143 run({data}) {
142 144 let validation = new Validation();
143 145 let constants = new Constants();
144   - //console.log("++++++++++++++++++++++++"+constants.csv_students_data());
145   - temp = constants.csv_students_data();
146   - console.log(temp);
147 146 var CSV_valid_buffer = [];
148 147 var CSV_invalid_buffer = [];
149 148 var filename = "Staff-" + new Date().getTime().toString();
... ... @@ -177,22 +176,33 @@ export const staffUploadCsv = new ValidatedMethod({
177 176 }
178 177  
179 178 var is_valid = formate_validation && is_not_null ;
  179 +
  180 +
  181 +
180 182 if (is_valid)
181 183 {
182   - CSV_valid_buffer.push(item);
183   - console.log("----------------------------------------1");
  184 + exists = Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"],'emails.$.address' : item['Staff Email*'],'phones.$.number' : item['Staff Phone*']}, {"_id": 1});
184 185  
185   - Meteor.call('staff.addCSV',item);
186   - console.log("----------------------------------------2");
187   -
  186 + if (!exists)
  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
190   - {
191   - var str = errors.toString();
192   - item.Errors = str;
193   - CSV_invalid_buffer.push(item);
194   - }
  202 +
195 203 }
  204 +
  205 +
196 206 console.log(csv_filepath+filename+"_CSV_invalid_data"+".csv");
197 207 Meteor.call('staff.saveCsvData',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_staff_data()});
198 208 Meteor.call('staff.saveCsvData',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_staff_data()});
... ...
imports/collections/students/serverCsvUpload.js
... ... @@ -58,9 +58,6 @@ export const addStudentCSV= new ValidatedMethod({
58 58  
59 59 run(item){
60 60 data = item ;
61   - console.log("data");
62   - console.log(data);
63   - // return true;
64 61 const user = Users.findOne({_id: this.userId});
65 62 orgId = user.orgId;
66 63 newStudentId = Users.insert({
... ... @@ -74,9 +71,12 @@ export const addStudentCSV= new ValidatedMethod({
74 71 newParentUserId = Users.insert({
75 72 //emails: [{address:data.parentEmail, verified: false}],
76 73 //3: data['Parent Name*'],
77   - firstName: data['Parent Name*'],
78 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 78 role: 'PARENT'
  79 +
80 80 });
81 81 if(newParentUserId){
82 82 newParentId = Parents.insert({
... ... @@ -135,10 +135,7 @@ export const studentUploadCsv = new ValidatedMethod({
135 135 run({data}) {
136 136 let validation = new Validation();
137 137 let constants = new Constants();
138   - //console.log("++++++++++++++++++++++++"+constants.csv_students_data());
139   - temp = constants.csv_students_data();
140   - //
141   - console.log(temp);
  138 +
142 139 // var data_1=csv1.csvtojson(("/Users/satheeshnagaraj/Downloads/11.csv")); //csvtojson is function that accepts csv filenames and returns JSON object
143 140 //console.log(data);''
144 141 // Stores = new Mongo.Collection('stores');
... ... @@ -147,7 +144,8 @@ export const studentUploadCsv = new ValidatedMethod({
147 144 var CSV_valid_buffer = [];
148 145 var CSV_invalid_buffer = [];
149 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  
... ... @@ -193,35 +191,40 @@ export const studentUploadCsv = new ValidatedMethod({
193 191 // console.log(formate_validation);
194 192 if (is_valid)
195 193 {
196   - CSV_valid_buffer.push(item);
197   - console.log("----------------------------------------1");
198   - console.log("----------------------------------------item");
199   - console.log(item);
200   - console.log (Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"]}));
201   -
202   - Meteor.call('student.addCSV',item);
203   - console.log("----------------------------------------2");
204   -
205   - // exists = Stores.findOne({
206   - // "Student 'Admission' ID*": item["Student Admission ID*"]
207   - // });
208   - // if (!exists)
209   - // {
210   - // Stores.insert(item);
211   - // }
212   - // else
213   - // {
214   - // console.warn('Rejected. This item already exists.');
215   - // }
216   - }
217   - else
218   - {
219   - var str = errors.toString();
220   - item.Errors = str;
221   - CSV_invalid_buffer.push(item);
222   - //console.log(str);
223   - // console.log(CSV_invalid_buffer);
224   - }
  194 +
  195 + exists = Users.findOne({"firstName": item["First Name*"],"lastName": item["Last Name*"]}, {"_id": 1});
  196 +
  197 + if (!exists)
  198 + {
  199 + CSV_valid_buffer.push(item);
  200 + Meteor.call('student.addCSV',item);
  201 + console.warn('done');
  202 + }
  203 + else
  204 + {
  205 + console.log(exists._id);
  206 + student_data = Students.findOne({"userId":exists._id});
  207 + console.log("--------------"+student_data);
  208 +
  209 + parent_data = Users.findOne({"_id":student_data.parent[0].id});
  210 +
  211 + console.log(parent_data.emails[0].address);
  212 + if ( parent_data.emails[0].address != item["Parent Email*"])
  213 + {
  214 + CSV_valid_buffer.push(item);
  215 + Meteor.call('student.addCSV',item);
  216 + console.warn('done');
  217 + }
  218 + else
  219 + {
  220 + console.warn('This data already exists.');
  221 + errors.push('This data already exists');
  222 + var str = errors.toString();
  223 + item.Errors = str;
  224 + CSV_invalid_buffer.push(item);
  225 + }
  226 + }
  227 + }
225 228 }
226 229 Meteor.call('save_csv_data',{ item : CSV_invalid_buffer, filename: csv_filepath+filename+"_CSV_invalid_data"+".csv",csv_fiels :constants.csv_students_data()});
227 230 Meteor.call('save_csv_data',{ item : CSV_valid_buffer,filename: csv_filepath+filename+"_CSV_valid_data"+".csv",csv_fiels :constants.csv_students_data()});
... ...