@@ -2281,22 +2281,20 @@ function sanitizeData(data, challenge) {
2281
2281
* @returns {Object } the deleted challenge
2282
2282
*/
2283
2283
async function deleteChallenge ( currentUser , challengeId ) {
2284
- const challenge = await challengeDomain . lookup ( getLookupCriteria ( "id" , challengeId ) ) ;
2284
+ const { items } = await challengeDomain . scan ( {
2285
+ criteria : getScanCriteria ( { id : challengeId , status : constants . challengeStatuses . New } ) ,
2286
+ } ) ;
2287
+ const challenge = _ . first ( items ) ;
2285
2288
if ( ! challenge ) {
2286
- throw new errors . NotFoundError ( `Challenge with id: ${ challengeId } doesn't exist` ) ;
2287
- }
2288
- if ( challenge . status !== constants . challengeStatuses . New ) {
2289
- throw new errors . BadRequestError (
2290
- `Challenge with status other than "${ constants . challengeStatuses . New } " cannot be removed`
2291
- ) ;
2289
+ throw new errors . NotFoundError ( `Challenge with id: ${ challengeId } doesn't exist or is not in New status` ) ;
2292
2290
}
2293
2291
// check groups authorization
2294
2292
await ensureAccessibleByGroupsAccess ( currentUser , challenge ) ;
2295
2293
// check if user are allowed to delete the challenge
2296
2294
await ensureAccessibleForChallenge ( currentUser , challenge ) ;
2297
2295
// delete DB record
2298
- const { items } = await challengeDomain . delete ( getLookupCriteria ( "id" , challengeId ) ) ;
2299
- if ( ! _ . find ( items , { id : challengeId } ) ) {
2296
+ const { items : deletedItems } = await challengeDomain . delete ( getLookupCriteria ( "id" , challengeId ) ) ;
2297
+ if ( ! _ . find ( deletedItems , { id : challengeId } ) ) {
2300
2298
throw new errors . Internal ( `There was an error deleting the challenge with id: ${ challengeId } from dynamo` ) ;
2301
2299
}
2302
2300
// delete ES document
0 commit comments