Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit b478797

Browse files
Refactored validators
1 parent e4532a3 commit b478797

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/database/users.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export default class Users {
1313
return global.db<User>("users");
1414
}
1515

16-
static async getUsersWithEmailCount(email: string) {
16+
static async emailTaken(email: string) {
1717
const total = (await Users
1818
.getQueryBuilder()
1919
.where("email", email)
2020
.count("*", { as: "total" })
2121
)[0].total;
22-
return Number(total);
22+
return Number(total) != 0;
2323
}
2424

2525
static async getUserByEmail(email: string) {

src/validators/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class AuthValidator {
4141

4242
if (validationResult.error) {
4343
return BadRequestError(res, String(validationResult.error));
44-
} else if (await Users.getUsersWithEmailCount(req.body.email) > 0) {
44+
} else if (await Users.emailTaken(req.body.email)) {
4545
return ConflictError(res, "This email is not available.");
4646
}
4747

0 commit comments

Comments
 (0)