Skip to content

Commit

Permalink
👉👇👈 username and email should be unique for User
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyoumi committed Dec 8, 2024
1 parent e10a3e9 commit 41895ea
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "NODE_ENV=dev ts-node src/index.ts",
"test": "vitest",
"test": "vitest --inspect-brk --no-file-parallelism --disable-console-intercept",
"test:int": "./scripts/run-integration.sh"
},
"keywords": [],
Expand Down
12 changes: 12 additions & 0 deletions backend/prisma/migrations/20241208123401_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- A unique constraint covering the columns `[username]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[email]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
4 changes: 2 additions & 2 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ enum UserType {

model User {
id Int @id @default(autoincrement())
username String
email String
username String @unique
email String @unique
password String
userType UserType
salt String
Expand Down
14 changes: 9 additions & 5 deletions backend/src/routes/OTP/OTPToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ export interface OTPToken {


export const getUserFromEmail = async (emailAddress: string) => {
try {
const result = await prisma.user.findUnique({
where: {
email: emailAddress,
},
});
where: {
email: emailAddress,
},
});
return result;
} catch (error) {
throw new Error("Error finding user");
}

return result;
}
3 changes: 2 additions & 1 deletion backend/tests/otp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ describe("Tests", () => {
const response = await request(app).post("/auth/otp/generate").send({
email: "[email protected]"
});
console.log(response.body);
expect(response.status).toBe(200);

const hash = await redisClient.get(newUser.email);

expect(hash).not.toBeNull();

if(hash) {
console.log(hash);
//console.log(hash);

await new Promise(resolve => setTimeout(resolve, 70000));

Expand Down

0 comments on commit 41895ea

Please sign in to comment.