Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projekt #8

Merged
merged 13 commits into from
Oct 11, 2024
7,493 changes: 7,493 additions & 0 deletions apps/backend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@prisma/client": "^5.13.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"backend": "file:",
"nestjs-prisma": "^0.23.0",
"reflect-metadata": "^0.2.2",
"rimraf": "^5.0.5",
Expand Down
50 changes: 50 additions & 0 deletions apps/backend/prisma/migrations/20241011172812_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- CreateEnum
CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER');

-- AlterTable
ALTER TABLE "User" ADD COLUMN "role" "Role" NOT NULL DEFAULT 'USER';

-- CreateTable
CREATE TABLE "Projekt" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Projekt_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Sprint" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"startDate" TIMESTAMP(3) NOT NULL,
"endDate" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Sprint_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tasks" (
"id" SERIAL NOT NULL,
"description" TEXT NOT NULL,
"sprintId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL,
"projektId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Tasks_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Projekt" ADD CONSTRAINT "Projekt_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_sprintId_fkey" FOREIGN KEY ("sprintId") REFERENCES "Sprint"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_projektId_fkey" FOREIGN KEY ("projektId") REFERENCES "Projekt"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
31 changes: 31 additions & 0 deletions apps/backend/prisma/migrations/20241011185901_c_k/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Warnings:

- You are about to drop the `Projekt` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropForeignKey
ALTER TABLE "Projekt" DROP CONSTRAINT "Projekt_userId_fkey";

-- DropForeignKey
ALTER TABLE "Tasks" DROP CONSTRAINT "Tasks_projektId_fkey";

-- DropTable
DROP TABLE "Projekt";

-- CreateTable
CREATE TABLE "Project" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Project" ADD CONSTRAINT "Project_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_projektId_fkey" FOREIGN KEY ("projektId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
16 changes: 16 additions & 0 deletions apps/backend/prisma/migrations/20241011190332_k_c/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:

- You are about to drop the column `projektId` on the `Tasks` table. All the data in the column will be lost.
- Added the required column `projectId` to the `Tasks` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "Tasks" DROP CONSTRAINT "Tasks_projektId_fkey";

-- AlterTable
ALTER TABLE "Tasks" DROP COLUMN "projektId",
ADD COLUMN "projectId" INTEGER NOT NULL;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
10 changes: 5 additions & 5 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ model User {
password String
email String @unique
role Role @default(USER)
Projekt Projekt[]
Project Project[]
Tasks Tasks[]
}

Expand All @@ -29,11 +29,11 @@ enum Role {
USER
}

model Projekt {
model Project {
id Int @id @default(autoincrement())
name String
description String
projektManager User @relation(fields: [userId], references: [id])
projectManager User? @relation(fields: [userId], references: [id])
userId Int
createdAt DateTime @default(now())

Expand All @@ -55,7 +55,7 @@ model Tasks {
sprint Sprint @relation(fields: [sprintId], references: [id])
userId Int?
user User? @relation(fields: [userId], references: [id])
projektId Int?
projekt Projekt? @relation(fields: [projektId], references: [id])
projectId Int?
project Project? @relation(fields: [projectId], references: [id])
createdAt DateTime @default(now())
}
10 changes: 9 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import { PrismaModule } from 'nestjs-prisma';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ProjectModule } from './project/project.module';
import { SprintModule } from './sprint/sprint.module';
import { TasksModule } from './tasks/tasks.module';
import { UserModule } from './user/user.module';

@Module({
imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true }), UserModule, SprintModule, TasksModule],
imports: [
ConfigModule.forRoot(),
PrismaModule.forRoot({ isGlobal: true }),
UserModule,
ProjectModule,
SprintModule,
TasksModule,
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/project/dto/create-project.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class CreateProjectDto {
name: string;
description: string;
}
5 changes: 5 additions & 0 deletions apps/backend/src/project/dto/update-project.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PartialType } from '@nestjs/mapped-types';

import { CreateProjectDto } from './create-project.dto';

export class UpdateProjectDto extends PartialType(CreateProjectDto) {}
1 change: 1 addition & 0 deletions apps/backend/src/project/entities/project.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Project {}
35 changes: 35 additions & 0 deletions apps/backend/src/project/project.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';

import { CreateProjectDto } from './dto/create-project.dto';
import { UpdateProjectDto } from './dto/update-project.dto';
import { ProjectService } from './project.service';

@Controller('project')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}

@Post()
create(@Body() createProjectDto: CreateProjectDto) {
return this.projectService.create(createProjectDto);
}

@Get()
findAll() {
return this.projectService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.projectService.findOne(Number(id));
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateProjectDto: UpdateProjectDto) {
return this.projectService.update(Number(id), updateProjectDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.projectService.remove(Number(id));
}
}
10 changes: 10 additions & 0 deletions apps/backend/src/project/project.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { ProjectController } from './project.controller';
import { ProjectService } from './project.service';

@Module({
controllers: [ProjectController],
providers: [ProjectService],
})
export class ProjectModule {}
28 changes: 28 additions & 0 deletions apps/backend/src/project/project.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@nestjs/common';
import { Prisma, Project } from '@prisma/client';
import { PrismaService } from 'nestjs-prisma';

@Injectable()
export class ProjectService {
constructor(private readonly Prisma: PrismaService) {}

async create(data: Prisma.ProjectCreateInput): Promise<Project> {
return await this.Prisma.project.create({ data });
}

async findAll(): Promise<Project[]> {
return await this.Prisma.project.findMany();
}

async findOne(id: number): Promise<Project> {
return await this.Prisma.project.findUnique({ where: { id } });
}

async update(id: number, data: Prisma.ProjectUpdateInput) {
return await this.Prisma.project.update({ where: { id }, data });
}

async remove(id: number) {
return await this.Prisma.project.delete({ where: { id } });
}
}
1 change: 0 additions & 1 deletion apps/backend/src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export class CreateUserDto {
foreName: string;
password: string;
email: string;
//TODO: user adatelemei
}
Loading
Loading