-
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.
Merge pull request #5 from devixid/feat/unit_test
feat(backend): add auth, fix prisma migrate problem
- Loading branch information
Showing
40 changed files
with
1,948 additions
and
1,454 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM postgres:15 | ||
FROM postgres:13 | ||
|
||
ENV POSTGRES_USER=${POSTGRES_USER} | ||
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM postgres:15 | ||
FROM postgres:13 | ||
|
||
ARG POSTGRES_USER | ||
ARG POSTGRES_PASSWORD | ||
|
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,11 @@ | ||
module.exports = { | ||
roots: ["."], | ||
transform: { | ||
"^.+\\.ts?$": "ts-jest", | ||
}, | ||
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.ts?$", | ||
moduleFileExtensions: ["ts", "js", "json", "node"], | ||
collectCoverage: true, | ||
clearMocks: true, | ||
coverageDirectory: "coverage", | ||
}; |
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
35 changes: 35 additions & 0 deletions
35
apps/backend/prisma/migrations/20240820041805_init/migration.sql
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,35 @@ | ||
-- CreateEnum | ||
CREATE TYPE "UserRole" AS ENUM ('ADMIN', 'SUPER_ADMIN'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "portfolios" ( | ||
"id" SERIAL NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"url" TEXT NOT NULL, | ||
"image" VARCHAR(255) NOT NULL, | ||
"keywords" TEXT[], | ||
"uploaderId" INTEGER NOT NULL, | ||
|
||
CONSTRAINT "portfolios_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "User" ( | ||
"id" SERIAL NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"email" TEXT NOT NULL, | ||
"hash" TEXT NOT NULL, | ||
"userName" TEXT, | ||
"fullName" TEXT, | ||
"role" "UserRole" NOT NULL DEFAULT 'ADMIN', | ||
|
||
CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "portfolios_title_keywords_idx" ON "portfolios"("title", "keywords"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); |
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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { PrismaClient, type User } from "@prisma/client"; | ||
import { Injectable } from "@nestjs/common"; | ||
|
||
@Injectable() | ||
export class AdminService { | ||
private readonly prisma = new PrismaClient(); | ||
|
||
async findById(id: number): Promise<User | null> { | ||
return await this.prisma.user.findUnique({ where: { id } }); | ||
} | ||
} |
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,16 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { | ||
type CanActivate, | ||
type ExecutionContext, | ||
Injectable, | ||
} from "@nestjs/common"; | ||
import { type Observable } from "rxjs"; | ||
|
||
@Injectable() | ||
export class AdminGuard implements CanActivate { | ||
canActivate( | ||
context: ExecutionContext, | ||
): boolean | Promise<boolean> | Observable<boolean> { | ||
return true; | ||
} | ||
} |
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,3 @@ | ||
export * from "./admin.service"; | ||
export * from "./guard/admin.guard"; | ||
export * from "./middleware/admin.middleware"; |
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,9 @@ | ||
import { Injectable, type NestMiddleware } from "@nestjs/common"; | ||
import { type Request, type Response } from "express"; | ||
|
||
@Injectable() | ||
export class AdminMiddleware implements NestMiddleware { | ||
use(req: Request, res: Response, next: () => void) { | ||
next(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,38 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { | ||
type NestModule, | ||
type MiddlewareConsumer, | ||
Module, | ||
RequestMethod, | ||
} from "@nestjs/common"; | ||
import { AppController } from "./app.controller"; | ||
import { AppService } from "./app.service"; | ||
import { ConfigModule } from "@nestjs/config"; | ||
import { PassportModule } from "@nestjs/passport"; | ||
import { JwtModule } from "@nestjs/jwt"; | ||
import { AppService } from "./app.service"; | ||
import { AuthService } from "./auth/auth.service"; | ||
import { AdminService } from "./admin/admin.service"; | ||
import { AuthController } from "./auth/auth.controller"; | ||
import { JwtStrategy } from "./auth"; | ||
import { LoggerMiddleware } from "./log/log.middleware"; | ||
|
||
@Module({ | ||
imports: [ConfigModule.forRoot({ isGlobal: true })], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
isGlobal: true, | ||
}), | ||
PassportModule.register({ defaultStrategy: "jwt" }), | ||
JwtModule.register({ | ||
secret: process.env.JWT_SECRET, | ||
signOptions: { expiresIn: process.env.JWT_EXPIRES_IN }, | ||
}), | ||
], | ||
controllers: [AppController, AuthController], | ||
providers: [AppService, AuthService, AdminService, JwtStrategy], | ||
}) | ||
export class AppModule {} | ||
export class AppModule implements NestModule { | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply(LoggerMiddleware) | ||
.forRoutes({ path: "*", method: RequestMethod.ALL }); | ||
} | ||
} |
Oops, something went wrong.