Skip to content

Commit

Permalink
fix: fixed error in deleteAll method
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 19, 2021
1 parent acaf8a1 commit 0e3455d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion example/src/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion example/src/controllers/utils/messages/user.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/functions/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0e3455d

Please sign in to comment.