-
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.
- Loading branch information
Showing
5 changed files
with
79 additions
and
4 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,4 +1,28 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { Controller, HttpStatus } from '@nestjs/common'; | ||
import { tsRestHandler, TsRestHandler } from '@ts-rest/nest'; | ||
import { ControllerResponse } from '@api/types/controller-response.type'; | ||
import { projectsContract } from '@shared/contracts/projects.contract'; | ||
import { ProjectsService } from '@api/modules/projects/projects.service'; | ||
|
||
@Controller('projects') | ||
export class ProjectsController {} | ||
@Controller() | ||
export class ProjectsController { | ||
constructor(private readonly projectsService: ProjectsService) {} | ||
|
||
@TsRestHandler(projectsContract.getProjects) | ||
async getProjects(): ControllerResponse { | ||
return tsRestHandler(projectsContract.getProjects, async ({ query }) => { | ||
const data = await this.projectsService.findAllPaginated(query); | ||
return { body: data, status: HttpStatus.OK }; | ||
}); | ||
} | ||
@TsRestHandler(projectsContract.getProject) | ||
async getProject(): ControllerResponse { | ||
return tsRestHandler( | ||
projectsContract.getProject, | ||
async ({ params: { id }, query }) => { | ||
const data = await this.projectsService.getById(id, query); | ||
return { body: { data }, status: HttpStatus.OK }; | ||
}, | ||
); | ||
} | ||
} |
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,20 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { AppBaseService } from '@api/utils/app-base.service'; | ||
import { Project } from '@shared/entities/users/projects.entity'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
@Injectable() | ||
export class ProjectsService {} | ||
export class ProjectsService extends AppBaseService< | ||
Project, | ||
unknown, | ||
unknown, | ||
unknown | ||
> { | ||
constructor( | ||
@InjectRepository(Project) | ||
private readonly projectRepository: Repository<Project>, | ||
) { | ||
super(projectRepository, 'project', 'projects'); | ||
} | ||
} |
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,31 @@ | ||
import { initContract } from "@ts-rest/core"; | ||
import { generateEntityQuerySchema } from "@shared/schemas/query-param.schema"; | ||
import { z } from "zod"; | ||
import { | ||
ApiPaginationResponse, | ||
ApiResponse, | ||
} from "@shared/dtos/global/api-response.dto"; | ||
import { Project } from "@shared/entities/users/projects.entity"; | ||
|
||
const contract = initContract(); | ||
export const projectsContract = contract.router({ | ||
getProjects: { | ||
method: "GET", | ||
path: "/projects", | ||
responses: { | ||
200: contract.type<ApiPaginationResponse<Project>>(), | ||
}, | ||
query: generateEntityQuerySchema(Project), | ||
}, | ||
getProject: { | ||
method: "GET", | ||
path: "/projects/:id", | ||
pathParams: z.object({ | ||
id: z.coerce.string().uuid(), | ||
}), | ||
responses: { | ||
200: contract.type<ApiResponse<Project>>(), | ||
}, | ||
query: generateEntityQuerySchema(Project), | ||
}, | ||
}); |