I have a confusion as I don't really understand in my case how i should structure my whole project folders and when to call a certain method for inserting a record in the collections (database).
Here is what I'm doing. Each time when an "employer" registers on my site I want to create a record for him in a Mongo Collection called Employer = new Meteor.Collection("employer");
This is how I imagined it:
FOLDER STRUCTURE:
client/client.js
collections/collections.js
server/server.js
server/methods.js
COLECTIONS.js
Employer = new Meteor.Collection("employer");
SERVER.JS
Meteor.startup(function(){
Accounts.onCreateUser(function (options, user) {
if (options.profile.type == 1) {
Roles.setRolesOnUserObj(user, ['employer']);
user.profile = options.profile
Meteor.publish("employer", function(){ //actually, here is where I want to write the newly created user into the Employer collections (as I have this selection through TYPE parameter)
return Employer.find();
});
}
else{
Roles.setRolesOnUserObj(user, ['employee']);
user.profile = options.profile
}
return user;
});
METHODS.js
Meteor.methods({
addEmployer: function () {
Employer.insert({
createdAt: new Date(),
owner: Meteor.userId(),
});
}
});
CLIENT.js
if (Meteor.isClient) {
// This code only runs on the client
// (client-side)
Template.Homepage.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
console.log('Sorry this verification link has expired.')
}
} else {
console.log('Thank you! Your email address has been confirmed.')
Meteor.call('addEmployer'); // when he actually verifies hes email, he is added to the Employer colelction, but this is a bit tricky as I don't know if the person verifying the email is EMPLOYEE OR EMPLOYER?
}
});
}
};
}
Now my questions are:
- "Do you think this is a good approach for implementing the logic of registering and adding an employer to a collection"?
- "Should the collections.js only have the collections defined with no extra programing logic?"
- "Finally, is this a good "design pattern" approach?"
EDIT: And when I think about it, there is actually no need for LATENCY COMPENSATION here so I would add my new Employer to the collection EMPLOYER only on the server, right after the user is registered and saved in the USERS collection?