I'm trying to update my application to utilise Meteors suggested file structure and I'm having trouble separating the publish function from the schema file. the file structure I'm trying to use is
imports/
api/
profile/
server/
publications.js
Profile.js
When I combine the publish function into the Profile.js schema file the publish function works and the data flows through to the client however when I separate them I'm unable to get it to publish. Can someone please show me how to separate the publish function and schema correctly.
Path: imports/api/profile/Profile.js
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { AddressSchema } from '../../api/profile/AddressSchema.js';
import { ContactNumberSchema } from '../../api/profile/ContactNumberSchema.js';
export const Profile = new Mongo.Collection("profile");
Profile.allow({
insert: function(userId, doc) {
return !!userId;
},
update: function(userId, doc) {
return !!userId;
},
remove: function(userId, doc) {
return !!userId;
}
});
var Schemas = {};
Schemas.Profile = new SimpleSchema({
userId: {
type: String,
optional: true
},
firstName: {
type: String,
optional: false,
},
familyName: {
type: String,
optional: false
}
});
Profile.attachSchema(Schemas.Profile);
if (Meteor.isServer) {
Meteor.publish('private.profile', function() {
return Profile.find({});
});
}
Path: client/main.js
Template.main.onCreated(function() {
this.autorun(() => {
this.subscribe('private.profile');
});
});