Skip to content

Commit

Permalink
Sprint-entity-CRUD (#6)
Browse files Browse the repository at this point in the history
* Sprint-entity-CRUD

* ESLint fixes

* ESLint fix 2.0
  • Loading branch information
DankaMarci authored Oct 11, 2024
1 parent c4c343d commit 86d92c5
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 31 deletions.
3 changes: 2 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
Expand Down
6 changes: 5 additions & 1 deletion apps/backend/src/sprint/dto/create-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export class CreateSprintDto {}
import { OmitType } from '@nestjs/swagger';

import { Sprint } from '../entities/sprint.entity';

export class CreateSprintDto extends OmitType(Sprint, ['id']) {}
3 changes: 2 additions & 1 deletion apps/backend/src/sprint/dto/update-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -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) {}
19 changes: 18 additions & 1 deletion apps/backend/src/sprint/entities/sprint.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 6 additions & 5 deletions apps/backend/src/sprint/sprint.controller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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));
}
}
3 changes: 2 additions & 1 deletion apps/backend/src/sprint/sprint.module.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
47 changes: 36 additions & 11 deletions apps/backend/src/sprint/sprint.service.ts
Original file line number Diff line number Diff line change
@@ -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<Sprint> {
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<Sprint[]> {
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<Sprint> {
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<Sprint> {
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<Sprint> {
try {
return await this.prisma.sprint.delete({ where: { id } });
} catch (error) {
throw new NotFoundException(`Sprint with ID ${id} not found ${error.message}`);
}
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { PartialType } from '@nestjs/swagger';

import { CreateUserDto } from './create-user.dto';

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}

Expand Down
8 changes: 0 additions & 8 deletions apps/frontend/src/components/CurrentJobs.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className='flex flex-col min-h-screen w-1/2'>
<Navbar />
Expand Down

0 comments on commit 86d92c5

Please sign in to comment.