-
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.
Merge branch 'main' of https://codeberg.org/YamanQD/Labeeb
- Loading branch information
Showing
21 changed files
with
347 additions
and
34 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { Priority } from 'src/enums/priority.enum'; | ||
import { Task } from 'src/tasks/task.entity'; | ||
import { define } from "typeorm-seeding"; | ||
|
||
const priorities = [Priority.HIGH, Priority.MEDIUM, Priority.LOW, Priority.NONE]; | ||
|
||
define(Task, () => { | ||
const task = new Task(); | ||
task.title = faker.lorem.sentence(); | ||
task.description = faker.lorem.paragraph(); | ||
task.priority = priorities[Math.floor(Math.random() * 100) % priorities.length]; | ||
task.deadline = faker.date.future(); | ||
return task; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { User } from "src/users/user.entity"; | ||
import { define } from "typeorm-seeding"; | ||
|
||
define(User, () => { | ||
const user = new User(); | ||
user.username = faker.internet.userName(); | ||
user.password = faker.internet.password(); | ||
return user; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Type } from 'class-transformer'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateListDto { | ||
@IsNotEmpty() | ||
@Type(() => String) | ||
name: string; | ||
|
||
@IsNotEmpty() | ||
projectId: number; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from "@nestjs/mapped-types"; | ||
import { CreateListDto } from "./create-list-dto"; | ||
|
||
export class UpdateListDto extends PartialType(CreateListDto) { } |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Project } from 'src/projects/project.entity'; | ||
import { Task } from 'src/tasks/task.entity'; | ||
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne } from 'typeorm'; | ||
|
||
@Entity() | ||
export class List { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: string; | ||
|
||
@ManyToOne(() => Project, project => project.lists) | ||
project: Project; | ||
|
||
@OneToMany(() => Task, task => task.list) | ||
tasks: Task[]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'; | ||
import { Task } from 'src/tasks/task.entity'; | ||
import { CreateListDto } from './dto/create-list-dto'; | ||
import { List } from './list.entity'; | ||
import { ListsService } from './lists.service'; | ||
|
||
@Controller('lists') | ||
export class ListsController { | ||
constructor(private readonly listsService: ListsService) { } | ||
|
||
@Get(':id') | ||
async findListTasks(@Param('id') id: number): Promise<Task[]> { | ||
return await this.listsService.findListTasks(id); | ||
} | ||
|
||
@Post() | ||
async create(@Body() body: CreateListDto): Promise<List> { | ||
return await this.listsService.create(body); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Project } from 'src/projects/project.entity'; | ||
import { List } from './list.entity'; | ||
import { ListsController } from './lists.controller'; | ||
import { ListsService } from './lists.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([List, Project])], | ||
controllers: [ListsController], | ||
providers: [ListsService] | ||
}) | ||
export class ListsModule { } |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Project } from 'src/projects/project.entity'; | ||
import { Task } from 'src/tasks/task.entity'; | ||
import { Repository } from 'typeorm'; | ||
import { CreateListDto } from './dto/create-list-dto'; | ||
import { List } from './list.entity'; | ||
|
||
@Injectable() | ||
export class ListsService { | ||
constructor( | ||
@InjectRepository(List) | ||
private readonly listRepository: Repository<List>, | ||
@InjectRepository(Project) | ||
private readonly projectRepository: Repository<Project> | ||
) { } | ||
|
||
async create(list: CreateListDto): Promise<List> { | ||
const project = await this.projectRepository.findOne({ where: { id: list.projectId } }); | ||
if (!project) { | ||
throw new NotFoundException('Project not found'); | ||
} | ||
|
||
return await this.listRepository.save({ ...list, project }); | ||
} | ||
|
||
async findListTasks(id: number): Promise<Task[]> { | ||
const list = await this.listRepository.findOne({ | ||
where: { id }, | ||
relations: { tasks: true } | ||
}); | ||
if (!list) { | ||
throw new NotFoundException('List not found'); | ||
} | ||
|
||
return list.tasks; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Type } from 'class-transformer'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class CreateProjectDto { | ||
@IsNotEmpty() | ||
@Type(() => String) | ||
name: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from "@nestjs/mapped-types"; | ||
import { CreateProjectDto } from "./create-project-dto"; | ||
|
||
export class UpdateProjectDto extends PartialType(CreateProjectDto) { } |
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,22 +1,24 @@ | ||
import { Body, Controller, Get, Param, Post, } from '@nestjs/common'; | ||
import { Task } from 'src/tasks/task.entity'; | ||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'; | ||
import { CreateProjectDto } from './dto/create-project-dto'; | ||
import { Project } from './project.entity'; | ||
import { ProjectsService } from './projects.service'; | ||
|
||
@Controller('projects') | ||
export class ProjectsController { | ||
constructor(private readonly projectsService: ProjectsService) { } | ||
|
||
@Get() | ||
async findAll(): Promise<Project[]> { | ||
return await this.projectsService.findAll(); | ||
} | ||
|
||
@Get(':id/tasks') | ||
async findProjectTasks(@Param('id') id): Promise<Task[]> { | ||
async findProjectTasks(@Param('id') id: number): Promise<any> { | ||
return await this.projectsService.findProjectTasks(id); | ||
} | ||
|
||
@Post() | ||
async create(@Body() body: any): Promise<Project> { | ||
async create(@Body() body: CreateProjectDto): Promise<Project> { | ||
return await this.projectsService.create(body); | ||
} | ||
|
||
// } | ||
} |
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
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
Oops, something went wrong.