From f3f7115ae803fda4d9464438b6ccf7d7a130cbe6 Mon Sep 17 00:00:00 2001 From: juliecoust Date: Tue, 30 Jan 2024 17:45:24 +0100 Subject: [PATCH] DEV - add default admin user in db + clean code --- src/data/data-sources/sqlite/sqlite-user-data-source.ts | 5 +++++ src/domain/repositories/user-repository.ts | 1 - src/infra/mailer/nodemailer.ts | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/data/data-sources/sqlite/sqlite-user-data-source.ts b/src/data/data-sources/sqlite/sqlite-user-data-source.ts index c52a506..bfdd1a1 100644 --- a/src/data/data-sources/sqlite/sqlite-user-data-source.ts +++ b/src/data/data-sources/sqlite/sqlite-user-data-source.ts @@ -13,8 +13,13 @@ export class SQLiteUserDataSource implements UserDataSource { } init_user_db() { + // Create table if not exist const sql_create = "CREATE TABLE IF NOT EXISTS 'user' (user_id INTEGER PRIMARY KEY AUTOINCREMENT, first_name TEXT NOT NULL, last_name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, password_hash CHAR(60) NOT NULL, valid_email BOOLEAN CHECK (valid_email IN (0, 1)) DEFAULT 0, confirmation_code TEXT , reset_password_code TEXT ,is_admin BOOLEAN CHECK (is_admin IN (0, 1)) DEFAULT 0, organisation TEXT NOT NULL, country TEXT NOT NULL, user_planned_usage TEXT NOT NULL, user_creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, deleted TIMESTAMP DEFAULT NULL);" this.db.run(sql_create, []) + + // Create admin user if not exist + const sql_admin = "INSERT OR IGNORE INTO user (first_name, last_name, email, password_hash, valid_email, is_admin, organisation, country, user_planned_usage) VALUES ('admin', 'admin', 'julie.coustenoble@imev-mer.fr', 'admin', 1, 1, 'admin', 'admin', 'admin');" + this.db.run(sql_admin, []) } async create(user: UserRequesCreationtModel): Promise { diff --git a/src/domain/repositories/user-repository.ts b/src/domain/repositories/user-repository.ts index 96845d7..3baa707 100644 --- a/src/domain/repositories/user-repository.ts +++ b/src/domain/repositories/user-repository.ts @@ -185,7 +185,6 @@ export class UserRepositoryImpl implements UserRepository { // Deleted : current date time deleted: new Date().toISOString() } - console.log(anonymized_user) const nb_of_updated_user = await this.updateUser(anonymized_user, params) return nb_of_updated_user diff --git a/src/infra/mailer/nodemailer.ts b/src/infra/mailer/nodemailer.ts index 5cb8c67..b195299 100644 --- a/src/infra/mailer/nodemailer.ts +++ b/src/infra/mailer/nodemailer.ts @@ -53,7 +53,6 @@ export class NodemailerAdapter implements MailerWrapper {//implements sendeamils } async send_reset_password_email(transporter: nodemailer.Transporter, user: UserResponseModel, resetPasswordToken: string): Promise { - console.log(user) // Read the HTML file let htmlContent = "error" try {