(config, auth, className, restWhere, restObject, clientSDK, context)
| 274 | // REST API is supposed to return. |
| 275 | // Usually, this is just updatedAt. |
| 276 | function update(config, auth, className, restWhere, restObject, clientSDK, context) { |
| 277 | enforceRoleSecurity('update', className, auth, config); |
| 278 | |
| 279 | return Promise.resolve() |
| 280 | .then(async () => { |
| 281 | const hasTriggers = checkTriggers(className, config, ['beforeSave', 'afterSave']); |
| 282 | const hasLiveQuery = checkLiveQuery(className, config); |
| 283 | if (hasTriggers || hasLiveQuery) { |
| 284 | // Do not use find, as it runs the before finds |
| 285 | // Use master auth when protectedFieldsTriggerExempt is true to bypass |
| 286 | // protectedFields filtering, so triggers see the full original object |
| 287 | const queryAuth = config.protectedFieldsTriggerExempt ? Auth.master(config) : auth; |
| 288 | const query = await RestQuery({ |
| 289 | method: RestQuery.Method.get, |
| 290 | config, |
| 291 | auth: queryAuth, |
| 292 | className, |
| 293 | restWhere, |
| 294 | runAfterFind: false, |
| 295 | runBeforeFind: false, |
| 296 | context, |
| 297 | }); |
| 298 | return query.execute({ |
| 299 | op: 'update', |
| 300 | }); |
| 301 | } |
| 302 | return Promise.resolve({}); |
| 303 | }) |
| 304 | .then(({ results }) => { |
| 305 | var originalRestObject; |
| 306 | if (results && results.length) { |
| 307 | originalRestObject = results[0]; |
| 308 | } |
| 309 | return new RestWrite( |
| 310 | config, |
| 311 | auth, |
| 312 | className, |
| 313 | restWhere, |
| 314 | restObject, |
| 315 | originalRestObject, |
| 316 | clientSDK, |
| 317 | context, |
| 318 | 'update' |
| 319 | ).execute(); |
| 320 | }) |
| 321 | .catch(error => { |
| 322 | handleSessionMissingError(error, className, auth, config); |
| 323 | }); |
| 324 | } |
| 325 | |
| 326 | function handleSessionMissingError(error, className, auth, config) { |
| 327 | // If we're trying to update a user without / with bad session token |
nothing calls this directly
no test coverage detected