Tuto part 53-58
This commit is contained in:
parent
134afde21c
commit
3f61a16324
31
docker-compose.yaml
Normal file
31
docker-compose.yaml
Normal file
@ -0,0 +1,31 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
database:
|
||||
image: 'postgres:latest'
|
||||
ports:
|
||||
- 15432:5432
|
||||
env_file:
|
||||
- .env
|
||||
networks:
|
||||
- postgres-network
|
||||
volumes:
|
||||
- ./db-data/:/var/lib/postgresql/data/
|
||||
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4
|
||||
ports:
|
||||
- 15433:80
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
- database
|
||||
networks:
|
||||
- postgres-network
|
||||
volumes:
|
||||
- ./pgadmin-data/:/var/lib/pgadmin/
|
||||
|
||||
networks:
|
||||
postgres-network:
|
||||
driver: bridge
|
11
init.sql
Normal file
11
init.sql
Normal file
@ -0,0 +1,11 @@
|
||||
-- create a table
|
||||
CREATE TABLE test(
|
||||
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||
name TEXT NOT NULL,
|
||||
archived BOOLEAN NOT NULL DEFAULT FALSE
|
||||
);
|
||||
|
||||
-- add test data
|
||||
INSERT INTO test (name, archived)
|
||||
VALUES ('test row 1', true),
|
||||
('test row 2', false);
|
@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "template",
|
||||
"name": "bookmarks-back",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"author": "Mathis Herriot",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "biome --apply src test",
|
||||
"format": "biome format src test",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
@ -23,6 +23,7 @@
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@prisma/client": "^5.10.2",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
@ -36,6 +37,7 @@
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"prisma": "^5.10.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
|
24
prisma/migrations/20240223131946_init/migration.sql
Normal file
24
prisma/migrations/20240223131946_init/migration.sql
Normal file
@ -0,0 +1,24 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE `User` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`email` VARCHAR(191) NOT NULL,
|
||||
`hash` VARCHAR(191) NOT NULL,
|
||||
`firstName` VARCHAR(191) NULL,
|
||||
`lastName` VARCHAR(191) NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Bookmark` (
|
||||
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
`title` VARCHAR(191) NOT NULL,
|
||||
`description` VARCHAR(191) NULL,
|
||||
`link` VARCHAR(191) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
3
prisma/migrations/migration_lock.toml
Normal file
3
prisma/migrations/migration_lock.toml
Normal file
@ -0,0 +1,3 @@
|
||||
# Please do not edit this file manually
|
||||
# It should be added in your version-control system (i.e. Git)
|
||||
provider = "mysql"
|
36
prisma/schema.prisma
Normal file
36
prisma/schema.prisma
Normal file
@ -0,0 +1,36 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
||||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
email String
|
||||
hash String
|
||||
|
||||
firstName String?
|
||||
lastName String?
|
||||
}
|
||||
|
||||
model Bookmark {
|
||||
id Int @id @default(autoincrement())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
title String
|
||||
description String?
|
||||
link String
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
@ -1,12 +0,0 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
import { BookmarkModule } from './bookmark/bookmark.module';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { AuthController } from './auth/auth.controller';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
imports: [AuthModule, PrismaModule, UserModule, BookmarkModule],
|
||||
providers: [AuthService],
|
||||
controllers: [AuthController]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
20
src/auth/auth.controller.ts
Normal file
20
src/auth/auth.controller.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Body, Controller, Post } from "@nestjs/common";
|
||||
import { AuthService } from "./auth.service";
|
||||
import { AuthDto } from "./dto";
|
||||
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private authService: AuthService) {}
|
||||
|
||||
@Post('signup')
|
||||
signup(@Body() dto: AuthDto) {
|
||||
console.log({dto});
|
||||
return this.authService.signup()
|
||||
}
|
||||
|
||||
@Post('signin')
|
||||
signin(@Body() dto: AuthDto) {
|
||||
console.log({dto});
|
||||
return this.authService.signin()
|
||||
}
|
||||
}
|
11
src/auth/auth.module.ts
Normal file
11
src/auth/auth.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { PrismaModule } from "src/prisma/prisma.module";
|
||||
import { AuthController } from "./auth.controller";
|
||||
import { AuthService } from "./auth.service";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [AuthController],
|
||||
providers: [AuthService]
|
||||
})
|
||||
export class AuthModule {}
|
17
src/auth/auth.service.ts
Normal file
17
src/auth/auth.service.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { PrismaService } from "src/prisma/prisma.service";
|
||||
|
||||
@Injectable({})
|
||||
export class AuthService {
|
||||
constructor(private prisma: PrismaService) {
|
||||
|
||||
}
|
||||
|
||||
signin() {
|
||||
return {response: "Sign IN"}
|
||||
}
|
||||
|
||||
signup() {
|
||||
return {response: "Sign UP"}
|
||||
}
|
||||
}
|
4
src/auth/dto/auth.dto.ts
Normal file
4
src/auth/dto/auth.dto.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface AuthDto {
|
||||
email: string,
|
||||
password: string
|
||||
}
|
1
src/auth/dto/index.ts
Normal file
1
src/auth/dto/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './auth.dto';
|
4
src/bookmark/bookmark.module.ts
Normal file
4
src/bookmark/bookmark.module.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class BookmarkModule {}
|
@ -3,6 +3,6 @@ import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
await app.listen(3333);
|
||||
}
|
||||
bootstrap();
|
||||
|
8
src/prisma/prisma.module.ts
Normal file
8
src/prisma/prisma.module.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service';
|
||||
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService]
|
||||
})
|
||||
export class PrismaModule {}
|
15
src/prisma/prisma.service.ts
Normal file
15
src/prisma/prisma.service.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient {
|
||||
constructor() {
|
||||
super({
|
||||
datasources: {
|
||||
db: {
|
||||
url: "mysql://avnyr:orpmocclealis8havele@127.0.0.1:3306/bookmarks"
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
4
src/user/user.module.ts
Normal file
4
src/user/user.module.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class UserModule {}
|
Loading…
x
Reference in New Issue
Block a user