12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- Websites.allow({
- insert: function (userId, doc) {
-
- check(doc, {
- url: String,
- title: String,
- description: String
- });
-
- if (!userId) {
- throw new Meteor.Error("logged-out", "User must be logged in to post a site.");
-
- }
-
- const url = doc.url;
- if (Websites.findOne({ url })) {
- throw new Meteor.Error("duplicate", "User may only post new sites.");
-
- }
-
-
-
-
- const URL_BOGO_REGEX = /^https?:\/\/.+$/;
- if (!URL_BOGO_REGEX.test(doc.url)) {
- throw new Meteor.Error("bad-url", "Users may only post http(s) URLs.");
-
- }
-
- if (doc.title === "") {
- throw new Meteor.Error("empty-title", "Title may not be empty");
-
- }
- if (doc.description === "") {
- throw new Meteor.Error("empty-description", "Description may not be empty");
-
- }
- return true;
- },
-
- update: function (userId, doc, fields, modifier) {
- if (!userId) {
- throw new Meteor.Error("logged-out", "User must be logged to vote on a site.");
- }
- const orderedFields = fields.sort();
- if (!_.isEqual(orderedFields, ["minus", "minusScore"]) &&
- !_.isEqual(orderedFields, ["plus", "plusScore"]) &&
- !_.isEqual(orderedFields, ["minus", "minusScore", "plus", "plusScore"])) {
- throw new Meteor.Error("invalid-field", "May only update minus[Score] and plus[Score].");
- }
-
- return true;
- }
- });
|