generated from kir-dev/next-nest-template
-
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.
* Sprint-entity-CRUD * ESLint fixes * ESLint fix 2.0
- Loading branch information
1 parent
c4c343d
commit 86d92c5
Showing
10 changed files
with
73 additions
and
31 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
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']) {} |
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,5 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { PartialType } from '@nestjs/swagger'; | ||
|
||
import { CreateSprintDto } from './create-sprint.dto'; | ||
|
||
export class UpdateSprintDto extends PartialType(CreateSprintDto) {} |
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 +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; | ||
} |
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,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}`); | ||
} | ||
} | ||
} |
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