Skip to content

Commit

Permalink
remove password from user
Browse files Browse the repository at this point in the history
  • Loading branch information
Janderson Souza Matias authored and Janderson Souza Matias committed Jan 15, 2024
1 parent 8486b45 commit 8b4d9f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
14 changes: 14 additions & 0 deletions src/database/migrations/1705334249846-migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class Migrations1705334249846 implements MigrationInterface {
name = 'Migrations1705334249846'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "password"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user" ADD "password" character varying`);
}

}
26 changes: 0 additions & 26 deletions src/modules/user/entity/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {
BeforeInsert,
BeforeUpdate,
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from "typeorm";
import config from "../../../config";
import Encryption from "../../encryption/controller";
import { Region } from "../../region/entity/region.entity";

@Entity()
Expand All @@ -29,9 +25,6 @@ export class User {
@Column({ nullable: true })
email?: string;

@Column({ nullable: true })
password?: string;

@Column({ nullable: true })
region_id?: string;

Expand All @@ -47,23 +40,4 @@ export class User {

@Column({ nullable: true })
deleted_at?: Date;

async verifyIsSamePassword(password: string): Promise<void> {
const hash = await Encryption.encrypt(password, config.salt).catch(
(error) => Promise.reject(error)
);
if (hash === this.password) return Promise.resolve();
return Promise.reject();
}

@BeforeUpdate()
@BeforeInsert()
async hashPassword() {
const newPassword = await Encryption.encrypt(
this.password as string,
config.salt
).catch((error) => Promise.reject(error));

this.password = newPassword;
}
}

0 comments on commit 8b4d9f6

Please sign in to comment.