diff --git a/example/src/controllers/user.ts b/example/src/controllers/user.ts index e4262bd..5f53638 100644 --- a/example/src/controllers/user.ts +++ b/example/src/controllers/user.ts @@ -63,7 +63,10 @@ class User { try { const usersDeleted = await UserModel.deleteMany({}) - if (usersDeleted.acknowledged) return MFU.ALL_USERS_DELETED + if (usersDeleted.deletedCount >= 1) return MFU.ALL_USERS_DELETED + + if (usersDeleted.deletedCount === 0) + throw new httpErrors.BadRequest(EFU.NOTHING_TO_DELETE) throw new httpErrors.InternalServerError(GE.INTERNAL_SERVER_ERROR) } catch (e) { diff --git a/example/src/controllers/utils/messages/user.ts b/example/src/controllers/utils/messages/user.ts index 2afc499..cffd104 100644 --- a/example/src/controllers/utils/messages/user.ts +++ b/example/src/controllers/utils/messages/user.ts @@ -1,5 +1,6 @@ enum ErrorForUser { - NOT_FOUND = 'The requested user does not exists' + NOT_FOUND = 'The requested user does not exists', + NOTHING_TO_DELETE = 'There is no user to be deleted' } enum MessageForUser { diff --git a/lib/src/functions/express.js b/lib/src/functions/express.js index a1a3834..70d9774 100644 --- a/lib/src/functions/express.js +++ b/lib/src/functions/express.js @@ -162,7 +162,10 @@ class User { try { const usersDeleted = await UserModel.deleteMany({}) - if (usersDeleted.acknowledged) return MFU.ALL_USERS_DELETED + if (usersDeleted.deletedCount >= 1) return MFU.ALL_USERS_DELETED + + if (usersDeleted.deletedCount === 0) + throw new httpErrors.BadRequest(EFU.NOTHING_TO_DELETE) throw new httpErrors.InternalServerError(GE.INTERNAL_SERVER_ERROR) } catch (e) { @@ -256,7 +259,8 @@ export { EFU, MFU, GenericErrors as GE } }, user: { content: `enum ErrorForUser { - NOT_FOUND = 'The requested user does not exists' + NOT_FOUND = 'The requested user does not exists', + NOTHING_TO_DELETE = 'There is no user to be deleted' } enum MessageForUser {