UNPKG

meteor-interface

Version:

Simple Content Management System to generate your administration interface for Meteor and React.

101 lines (85 loc) 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _slugify = _interopRequireDefault(require("slugify")); var _configuration = _interopRequireDefault(require("../../lib/configuration")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var initPublications = function initPublications() { var config = _configuration.default.get(); // Extract datas from config var _config$collections = config.collections, collections = _config$collections === void 0 ? [] : _config$collections; Meteor.publish('interface.counters.all.collections', function () { var _this = this; collections.map(function (coll) { if (Roles.userIsInRole(Meteor.userId(), coll.visible)) { Counts.publish(_this, "count-all-".concat((0, _slugify.default)(coll.label, { lower: true })), coll.mongo.find()); } }); }); collections.map(function (coll) { Meteor.publish("interface.all.".concat((0, _slugify.default)(coll.label, { lower: true })), function (_ref) { var _ref$search = _ref.search, search = _ref$search === void 0 ? '' : _ref$search, page = _ref.page; var isAuthorized = Roles.userIsInRole(this.userId, coll.visible); if (!isAuthorized) { throw new Meteor.Error(403, "You aren't authorized to do that"); } var regex = { $regex: new RegExp(search, 'i') }; var research = { $or: coll.fields.map(function (field) { return _defineProperty({}, field.name, regex); }) }; Counts.publish(this, "count-all-".concat((0, _slugify.default)(coll.label, { lower: true })), coll.mongo.find(research)); return coll.mongo.find(research, { limit: 10, skip: (page - 1) * 10 }); }); Meteor.publish("interface.one.".concat((0, _slugify.default)(coll.label, { lower: true })), function (_ref3) { var itemId = _ref3.itemId; var isAuthorized = Roles.userIsInRole(this.userId, coll.visible); if (!isAuthorized) { throw new Meteor.Error(403, "You aren't authorized to do that"); } return coll.mongo.find({ _id: itemId }, { sort: { _id: 1 }, limit: 1 }); }); Meteor.publish("interface.single.".concat((0, _slugify.default)(coll.label, { lower: true })), function () { var isAuthorized = Roles.userIsInRole(this.userId, coll.visible); if (!isAuthorized) { throw new Meteor.Error(403, "You aren't authorized to do that"); } return coll.mongo.find({}, { sort: { _id: 1 }, limit: 1 }); }); }); }; var _default = initPublications; exports.default = _default;