-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Janderson Souza Matias
authored and
Janderson Souza Matias
committed
Jan 15, 2024
1 parent
203910a
commit 1240677
Showing
5 changed files
with
89 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class Migrations1705331535248 implements MigrationInterface { | ||
name = "Migrations1705331535248"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "otp" DROP CONSTRAINT "FK_2b232c6eac98f99d29a0ec6950e"` | ||
); | ||
await queryRunner.query(`ALTER TABLE "otp" DROP COLUMN "coach_id"`); | ||
await queryRunner.query( | ||
`ALTER TABLE "otp" ADD "email" character varying NOT NULL` | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "otp" DROP COLUMN "email"`); | ||
await queryRunner.query(`ALTER TABLE "otp" ADD "coach_id" uuid`); | ||
await queryRunner.query( | ||
`ALTER TABLE "otp" ADD CONSTRAINT "FK_2b232c6eac98f99d29a0ec6950e" FOREIGN KEY ("coach_id") REFERENCES "coach"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,12 +131,12 @@ export default class Authentication { | |
} | ||
}; | ||
|
||
public static sendEmailOTP = async (coach: Coach) => { | ||
public static sendEmailOTP = async (email: string) => { | ||
sgMail.setApiKey(process.env.SENDGRID_API_KEY || ""); | ||
|
||
const code = Math.floor(1000 + Math.random() * 9000).toString(); | ||
const msg = { | ||
to: coach.email, | ||
to: email, | ||
from: "[email protected]", | ||
subject: "Coach Digital - OTP", | ||
html: OTP_EMAIL.replace("#{code}", code), | ||
|
@@ -147,18 +147,18 @@ export default class Authentication { | |
await sgMail.send(msg); | ||
|
||
return await otpRepository.save({ | ||
coach, | ||
email, | ||
code, | ||
created_at: new Date().getTime(), | ||
}); | ||
}; | ||
|
||
public static verifyOTP = async (coach: Coach, code: string) => { | ||
public static verifyOTP = async (email: string, code: string) => { | ||
const otpRepository = await dataSource.getRepository(Otp); | ||
const tenMinutesAgo = new Date().getTime() - 10 * 60 * 1000; | ||
|
||
return await otpRepository.findOneBy({ | ||
coach, | ||
email, | ||
code, | ||
created_at: MoreThan(tenMinutesAgo), | ||
}); | ||
|