Skip to content

Commit

Permalink
Check user uniqueness in parallel (by email and username).
Browse files Browse the repository at this point in the history
  • Loading branch information
aaabramov authored and geromegrignon committed May 27, 2024
1 parent 11c81f6 commit 77b112c
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions apps/api/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import generateToken from '../utils/token.utils';
import { User } from '../models/user.model';

const checkUserUniqueness = async (email: string, username: string) => {
const existingUserByEmail = await prisma.user.findUnique({
where: {
email,
},
select: {
id: true,
},
});

const existingUserByUsername = await prisma.user.findUnique({
where: {
username,
},
select: {
id: true,
},
});
const [existingUserByEmail, existingUserByUsername] = await Promise.all([
prisma.user.findUnique({
where: {
email,
},
select: {
id: true,
},
}),
prisma.user.findUnique({
where: {
username,
},
select: {
id: true,
},
}),
]);

if (existingUserByEmail || existingUserByUsername) {
throw new HttpException(422, {
Expand Down

0 comments on commit 77b112c

Please sign in to comment.