(req)
| 53 | |
| 54 | // Returns a promise for a {response} object. |
| 55 | handleGet(req) { |
| 56 | const body = Object.assign(req.body || {}, ClassesRouter.JSONFromQuery(req.query)); |
| 57 | const options = {}; |
| 58 | |
| 59 | for (const key of Object.keys(body)) { |
| 60 | if (ALLOWED_GET_QUERY_KEYS.indexOf(key) === -1) { |
| 61 | throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Improper encode of parameter'); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (body.keys != null) { |
| 66 | options.keys = String(body.keys); |
| 67 | } |
| 68 | if (body.include != null) { |
| 69 | options.include = String(body.include); |
| 70 | } |
| 71 | if (body.excludeKeys != null) { |
| 72 | options.excludeKeys = String(body.excludeKeys); |
| 73 | } |
| 74 | if (typeof body.readPreference === 'string') { |
| 75 | options.readPreference = body.readPreference; |
| 76 | } |
| 77 | if (typeof body.includeReadPreference === 'string') { |
| 78 | options.includeReadPreference = body.includeReadPreference; |
| 79 | } |
| 80 | if (typeof body.subqueryReadPreference === 'string') { |
| 81 | options.subqueryReadPreference = body.subqueryReadPreference; |
| 82 | } |
| 83 | |
| 84 | return rest |
| 85 | .get( |
| 86 | req.config, |
| 87 | req.auth, |
| 88 | this.className(req), |
| 89 | req.params.objectId, |
| 90 | options, |
| 91 | req.info.clientSDK, |
| 92 | req.info.context |
| 93 | ) |
| 94 | .then(response => { |
| 95 | if (!response.results || response.results.length == 0) { |
| 96 | throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.'); |
| 97 | } |
| 98 | |
| 99 | if (this.className(req) === '_User') { |
| 100 | delete response.results[0].sessionToken; |
| 101 | |
| 102 | const user = response.results[0]; |
| 103 | |
| 104 | if (req.auth.user && user.objectId == req.auth.user.id) { |
| 105 | // Force the session token |
| 106 | response.results[0].sessionToken = req.info.sessionToken; |
| 107 | } |
| 108 | } |
| 109 | return { response: response.results[0] }; |
| 110 | }); |
| 111 | } |
| 112 |
no test coverage detected