MCPcopy Index your code
hub / github.com/parse-community/parse-server / del

Function del

src/rest.js:168–264  ·  view source on GitHub ↗
(config, auth, className, objectId, context)

Source from the content-addressed store, hash-verified

166
167// Returns a promise that doesn't resolve to any useful value.
168function del(config, auth, className, objectId, context) {
169 if (typeof objectId !== 'string') {
170 throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad objectId');
171 }
172
173 if (className === '_User' && auth.isUnauthenticated()) {
174 throw new Parse.Error(Parse.Error.SESSION_MISSING, 'Insufficient auth to delete user');
175 }
176
177 enforceRoleSecurity('delete', className, auth, config);
178
179 let inflatedObject;
180 let schemaController;
181
182 return Promise.resolve()
183 .then(async () => {
184 const hasTriggers = checkTriggers(className, config, ['beforeDelete', 'afterDelete']);
185 const hasLiveQuery = checkLiveQuery(className, config);
186 if (hasTriggers || hasLiveQuery || className == '_Session') {
187 const query = await RestQuery({
188 method: RestQuery.Method.get,
189 config,
190 auth,
191 className,
192 restWhere: { objectId },
193 });
194 return query.execute({ op: 'delete' }).then(response => {
195 if (response && response.results && response.results.length) {
196 const firstResult = response.results[0];
197 firstResult.className = className;
198 if (className === '_Session' && !auth.isMaster && !auth.isMaintenance) {
199 if (!auth.user || firstResult.user.objectId !== auth.user.id) {
200 throw createSanitizedError(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token', config);
201 }
202 }
203 var cacheAdapter = config.cacheController;
204 cacheAdapter.user.del(firstResult.sessionToken);
205 inflatedObject = Parse.Object.fromJSON(firstResult);
206 return triggers.maybeRunTrigger(
207 triggers.Types.beforeDelete,
208 auth,
209 inflatedObject,
210 null,
211 config,
212 context
213 );
214 }
215 throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found for delete.');
216 });
217 }
218 return Promise.resolve({});
219 })
220 .then(() => {
221 if (!auth.isMaster && !auth.isMaintenance) {
222 return auth.getUserRoles();
223 } else {
224 return;
225 }

Callers

nothing calls this directly

Calls 12

enforceRoleSecurityFunction · 0.85
checkTriggersFunction · 0.85
checkLiveQueryFunction · 0.85
RestQueryFunction · 0.85
createSanitizedErrorFunction · 0.85
executeMethod · 0.80
loadSchemaMethod · 0.80
destroyMethod · 0.80
onAfterDeleteMethod · 0.80
delMethod · 0.45

Tested by

no test coverage detected