From bb482fb896389c77b18ccb32bb103d352b2fa342 Mon Sep 17 00:00:00 2001 From: Mathis Date: Tue, 9 Jul 2024 15:01:36 +0200 Subject: [PATCH] feat(auth): add Auth service and module A new authentication service and module were added to the application. The app.module.ts file was updated to include this newly created AuthModule. Also, an initial structure for the AuthService was set up. --- drizzle.config.ts | 2 +- src/drizzle/drizzle.module.ts | 10 ++--- src/drizzle/drizzle.service.ts | 80 ++++++++++++++++------------------ 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/drizzle.config.ts b/drizzle.config.ts index 0ab8ed3..8a87b13 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'drizzle-kit'; import * as process from "node:process"; export default defineConfig({ - schema: './src/drizzle/schema.ts', + schema: './src/schema.ts', out: './drizzle', dialect: 'postgresql', dbCredentials: { diff --git a/src/drizzle/drizzle.module.ts b/src/drizzle/drizzle.module.ts index f52a867..0b0d60c 100644 --- a/src/drizzle/drizzle.module.ts +++ b/src/drizzle/drizzle.module.ts @@ -1,10 +1,10 @@ -import { Module } from '@nestjs/common'; -import { DrizzleService } from './drizzle.service'; +import { Module } from "@nestjs/common"; import { ConfigModule } from "@nestjs/config"; +import { DrizzleService } from "./drizzle.service"; @Module({ - imports: [ConfigModule], - providers: [DrizzleService], - exports: [DrizzleService] + imports: [ConfigModule], + providers: [DrizzleService], + exports: [DrizzleService], }) export class DrizzleModule {} diff --git a/src/drizzle/drizzle.service.ts b/src/drizzle/drizzle.service.ts index 764e601..ff5bae1 100644 --- a/src/drizzle/drizzle.service.ts +++ b/src/drizzle/drizzle.service.ts @@ -1,56 +1,52 @@ // biome-ignore lint/style/useImportType: used by Next.js -import { Injectable, OnModuleInit, OnModuleDestroy } from "@nestjs/common"; +import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common"; // biome-ignore lint/style/useImportType: used by Next.js import { ConfigService } from "@nestjs/config"; -import { drizzle } from 'drizzle-orm/postgres-js'; -import { migrate } from 'drizzle-orm/postgres-js/migrator'; +import { drizzle } from "drizzle-orm/postgres-js"; +import { migrate } from "drizzle-orm/postgres-js/migrator"; import postgres from "postgres"; - @Injectable() export class DrizzleService implements OnModuleInit, OnModuleDestroy { - private migrationClient: postgres.Sql>; - private standardClient: postgres.Sql>; + private migrationClient: postgres.Sql>; + private standardClient: postgres.Sql>; - constructor( - private configService: ConfigService - ) { } + constructor(private configService: ConfigService) {} - async onModuleInit() { + async onModuleInit() { + const dbConfig = { + host: this.configService.get("POSTGRES_HOST"), + port: Number(this.configService.get("POSTGRES_PORT")), + database: this.configService.get("POSTGRES_DATABASE"), + user: this.configService.get("POSTGRES_USER"), + password: this.configService.get("POSTGRES_PASSWORD"), + ssl: Boolean(this.configService.get("POSTGRES_SSL")), + }; - const dbConfig = { - host: this.configService.get("POSTGRES_HOST"), - port: Number(this.configService.get("POSTGRES_PORT")), - database: this.configService.get("POSTGRES_DATABASE"), - user: this.configService.get("POSTGRES_USER"), - password: this.configService.get("POSTGRES_PASSWORD"), - ssl: Boolean(this.configService.get("POSTGRES_SSL")), - } + this.migrationClient = postgres({ + ...dbConfig, + max: 1, + }); - this.migrationClient = postgres({ - ...dbConfig, - max: 1, - }) + this.standardClient = postgres({ + ...dbConfig, + }); + } - this.standardClient = postgres({ - ...dbConfig - }) - } + //onModuleDestroy + async onModuleDestroy() { + await this.migrationClient.end(); + await this.standardClient.end(); + } - //onModuleDestroy - async onModuleDestroy() { - await this.migrationClient.end(); - await this.standardClient.end(); - } + getMigrationClient() { + return migrate(drizzle(this.migrationClient), { + migrationsFolder: "./migrations", + migrationsSchema: "public", + }); + } - getMigrationClient() { - return migrate(drizzle(this.migrationClient), { - migrationsFolder: "./migrations", - migrationsSchema: "public" - }); - } - - getClient() { - return drizzle(this.standardClient); - } -} \ No newline at end of file + use() { + return drizzle(this.standardClient); + } +}