jxp 2.11.1 → 2.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/libs/jxp.js +6 -13
  2. package/package.json +1 -1
package/libs/jxp.js CHANGED
@@ -83,13 +83,6 @@ const outputCSV = (req, res, next) => {
83
83
  const actionGet = async (req, res) => {
84
84
  const opname = `get ${req.modelname} ${ops++}`;
85
85
  console.time(opname);
86
- try {
87
- if (res.user) {
88
- req.Model.__user = res.user;
89
- }
90
- } catch(err) {
91
- console.error(err);
92
- }
93
86
  const parseSearch = function(search) {
94
87
  let result = {};
95
88
  for (let i in search) {
@@ -124,6 +117,9 @@ const actionGet = async (req, res) => {
124
117
  countquery = Object.assign({ $text: { $search: req.query.search }}, countquery);
125
118
  qcount = req.Model.find({ $text: { $search: req.query.search }});
126
119
  }
120
+ if (res.user) {
121
+ q.options({ user: res.user });
122
+ }
127
123
  try {
128
124
  let count = await req.Model.estimatedDocumentCount();
129
125
  if (count < 100000 && Object.keys(countquery).length !== 0) {
@@ -197,10 +193,7 @@ const actionGetOne = async (req, res) => {
197
193
  const opname = `getOne ${req.modelname}/${req.params.item_id} ${ops++}`;
198
194
  console.time(opname);
199
195
  try {
200
- if (res.user) {
201
- req.Model.__user = res.user;
202
- }
203
- const data = await getOne(req.Model, req.params.item_id, req.query);
196
+ const data = await getOne(req.Model, req.params.item_id, req.query, { user: res.user });
204
197
  res.send({ data });
205
198
  if (debug) console.timeEnd(opname);
206
199
  } catch(err) {
@@ -613,8 +606,8 @@ const actionBulkWrite = async (req, res) => {
613
606
 
614
607
  // Utitlities
615
608
 
616
- const getOne = async (Model, item_id, params) => {
617
- const query = Model.findById(item_id);
609
+ const getOne = async (Model, item_id, params, options) => {
610
+ const query = Model.findById(item_id, {}, options);
618
611
  if (params.populate) {
619
612
  if ((typeof params.populate === "object") && !Array.isArray(params.populate)) {
620
613
  for (let i in params.populate) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jxp",
3
3
  "description:": "An opinionated RESTful API library based on Mongoose and Restify. Make an API by just writing Mongoose models.",
4
- "version": "2.11.1",
4
+ "version": "2.11.2",
5
5
  "private": false,
6
6
  "main": "libs/jxp.js",
7
7
  "scripts": {