diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index 8dcc2e2..0822acb 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -4,10 +4,11 @@ import { PrismaModule } from 'nestjs-prisma'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { SprintModule } from './sprint/sprint.module'; import { UserModule } from './user/user.module'; @Module({ - imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true }), UserModule], + imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true }), UserModule, SprintModule], controllers: [AppController], providers: [AppService], }) diff --git a/apps/backend/src/sprint/dto/create-sprint.dto.ts b/apps/backend/src/sprint/dto/create-sprint.dto.ts index 94ee38a..ab68e83 100644 --- a/apps/backend/src/sprint/dto/create-sprint.dto.ts +++ b/apps/backend/src/sprint/dto/create-sprint.dto.ts @@ -1 +1,5 @@ -export class CreateSprintDto {} +import { OmitType } from '@nestjs/swagger'; + +import { Sprint } from '../entities/sprint.entity'; + +export class CreateSprintDto extends OmitType(Sprint, ['id']) {} diff --git a/apps/backend/src/sprint/dto/update-sprint.dto.ts b/apps/backend/src/sprint/dto/update-sprint.dto.ts index 9cbb438..c11c885 100644 --- a/apps/backend/src/sprint/dto/update-sprint.dto.ts +++ b/apps/backend/src/sprint/dto/update-sprint.dto.ts @@ -1,4 +1,5 @@ -import { PartialType } from '@nestjs/mapped-types'; +import { PartialType } from '@nestjs/swagger'; + import { CreateSprintDto } from './create-sprint.dto'; export class UpdateSprintDto extends PartialType(CreateSprintDto) {} diff --git a/apps/backend/src/sprint/entities/sprint.entity.ts b/apps/backend/src/sprint/entities/sprint.entity.ts index 82cd9a5..529bc3c 100644 --- a/apps/backend/src/sprint/entities/sprint.entity.ts +++ b/apps/backend/src/sprint/entities/sprint.entity.ts @@ -1 +1,18 @@ -export class Sprint {} +import { IsDate, IsInt, IsNotEmpty, IsOptional, IsString } from 'class-validator'; + +export class Sprint { + @IsInt() + id: number; + + @IsNotEmpty() + @IsString() + name: string; + + @IsDate() + @IsNotEmpty() + startDate: Date; + + @IsDate() + @IsOptional() + endDate: Date; +} diff --git a/apps/backend/src/sprint/sprint.controller.ts b/apps/backend/src/sprint/sprint.controller.ts index 624aeba..4aefecf 100644 --- a/apps/backend/src/sprint/sprint.controller.ts +++ b/apps/backend/src/sprint/sprint.controller.ts @@ -1,7 +1,8 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; -import { SprintService } from './sprint.service'; +import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'; + import { CreateSprintDto } from './dto/create-sprint.dto'; import { UpdateSprintDto } from './dto/update-sprint.dto'; +import { SprintService } from './sprint.service'; @Controller('sprint') export class SprintController { @@ -19,16 +20,16 @@ export class SprintController { @Get(':id') findOne(@Param('id') id: string) { - return this.sprintService.findOne(+id); + return this.sprintService.findOne(Number(id)); } @Patch(':id') update(@Param('id') id: string, @Body() updateSprintDto: UpdateSprintDto) { - return this.sprintService.update(+id, updateSprintDto); + return this.sprintService.update(Number(id), updateSprintDto); } @Delete(':id') remove(@Param('id') id: string) { - return this.sprintService.remove(+id); + return this.sprintService.remove(Number(id)); } } diff --git a/apps/backend/src/sprint/sprint.module.ts b/apps/backend/src/sprint/sprint.module.ts index 7d19933..5cdf444 100644 --- a/apps/backend/src/sprint/sprint.module.ts +++ b/apps/backend/src/sprint/sprint.module.ts @@ -1,6 +1,7 @@ import { Module } from '@nestjs/common'; -import { SprintService } from './sprint.service'; + import { SprintController } from './sprint.controller'; +import { SprintService } from './sprint.service'; @Module({ controllers: [SprintController], diff --git a/apps/backend/src/sprint/sprint.service.ts b/apps/backend/src/sprint/sprint.service.ts index 38b84f2..2619e06 100644 --- a/apps/backend/src/sprint/sprint.service.ts +++ b/apps/backend/src/sprint/sprint.service.ts @@ -1,27 +1,52 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; +import { PrismaService } from 'nestjs-prisma'; import { CreateSprintDto } from './dto/create-sprint.dto'; import { UpdateSprintDto } from './dto/update-sprint.dto'; +import { Sprint } from './entities/sprint.entity'; @Injectable() export class SprintService { - create(createSprintDto: CreateSprintDto) { - return 'This action adds a new sprint'; + constructor(private readonly prisma: PrismaService) {} + + async create(createSprintDto: CreateSprintDto): Promise { + try { + const newSprint = await this.prisma.sprint.create({ data: createSprintDto }); + return newSprint; + } catch (error) { + throw new Error(`Sprint not created ${error.message}`); + } } - findAll() { - return `This action returns all sprint`; + async findAll(): Promise { + try { + return this.prisma.sprint.findMany(); + } catch (error) { + throw new NotFoundException(`Sprints not found ${error.message}`); + } } - findOne(id: number) { - return `This action returns a #${id} sprint`; + async findOne(id: number): Promise { + const sprint = await this.prisma.sprint.findUnique({ where: { id } }); + if (!sprint) { + throw new NotFoundException(`Sprint with ID ${id} not found`); + } + return sprint; } - update(id: number, updateSprintDto: UpdateSprintDto) { - return `This action updates a #${id} sprint`; + async update(id: number, updateSprintDto: UpdateSprintDto): Promise { + try { + return await this.prisma.sprint.update({ where: { id }, data: updateSprintDto }); + } catch (error) { + throw new NotFoundException(`Sprint with ID ${id} not found ${error.message}`); + } } - remove(id: number) { - return `This action removes a #${id} sprint`; + async remove(id: number): Promise { + try { + return await this.prisma.sprint.delete({ where: { id } }); + } catch (error) { + throw new NotFoundException(`Sprint with ID ${id} not found ${error.message}`); + } } } diff --git a/apps/backend/src/user/dto/update-user.dto.ts b/apps/backend/src/user/dto/update-user.dto.ts index deaf4b4..e1cec90 100644 --- a/apps/backend/src/user/dto/update-user.dto.ts +++ b/apps/backend/src/user/dto/update-user.dto.ts @@ -1,4 +1,4 @@ -import { PartialType } from '@nestjs/mapped-types'; +import { PartialType } from '@nestjs/swagger'; import { CreateUserDto } from './create-user.dto'; diff --git a/apps/backend/src/user/user.controller.ts b/apps/backend/src/user/user.controller.ts index 44dc34c..e30c58f 100644 --- a/apps/backend/src/user/user.controller.ts +++ b/apps/backend/src/user/user.controller.ts @@ -23,7 +23,7 @@ export class UserController { const user = await this.authService.signIn(loginDto.email, loginDto.password); return { ...user, - isRegistered: user ? true : false, + isRegistered: Boolean(user), }; } diff --git a/apps/frontend/src/components/CurrentJobs.tsx b/apps/frontend/src/components/CurrentJobs.tsx index 52f4968..802ce9b 100644 --- a/apps/frontend/src/components/CurrentJobs.tsx +++ b/apps/frontend/src/components/CurrentJobs.tsx @@ -1,14 +1,6 @@ import Navbar from './Navbar'; export default function CurrentJobs() { - function ExpendableTable() { - const [ExpandedRow, setExpandedRow] = useState(false); - - const toggleRow = (rowIndex) => { - setExpandedRow(expandedRow === rowIndex ? null : rowIndex); - }; - } - return (