-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: padronizar dominios service-types e documents #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
The head ref may contain hidden characters: "732-8---refatora\u00E7\u00E3o-do-dom\u00EDnio-service-types-documents"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esse teste cobre Como a issue pede padronização, o ideal seria renomear também testes, métodos, services e DTOs para |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { EditServiceTypePage } from "@/domains/service-types/pages/edit-service-type-page"; | ||
|
|
||
| export default function Page() { | ||
| return <EditServiceTypePage />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { ServiceTypesPage } from "@/domains/service-types/pages/service-types-page"; | ||
|
|
||
| export default function Page() { | ||
| return <ServiceTypesPage />; | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { AxiosError } from "axios"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| import { createBaseApi } from "@/lib/axios"; | ||
|
|
||
| const categoryRouteMap: Record<string, string> = { | ||
| medical: "medicals", | ||
| medicals: "medicals", | ||
| medicos: "medicals", | ||
| personal: "personals", | ||
| personals: "personals", | ||
| pessoais: "personals", | ||
| school: "schools", | ||
| schools: "schools", | ||
| escolares: "schools", | ||
| }; | ||
|
|
||
| function normalizeCategory(category: string | null) { | ||
| if (!category) { | ||
| return null; | ||
| } | ||
|
|
||
| return categoryRouteMap[category.toLowerCase()] || null; | ||
| } | ||
|
|
||
| export async function GET( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const { id } = await params; | ||
| const category = normalizeCategory(request.nextUrl.searchParams.get("category")); | ||
| const year = request.nextUrl.searchParams.get("year"); | ||
| const type = request.nextUrl.searchParams.get("type"); | ||
|
|
||
| if (!category) { | ||
| return NextResponse.json({ message: "Categoria de documento invalida." }, { status: 400 }); | ||
| } | ||
|
|
||
| try { | ||
| const api = await createBaseApi(); | ||
| const searchParams = new URLSearchParams(); | ||
|
|
||
| if (year) { | ||
| searchParams.set("year", year); | ||
| } | ||
|
|
||
| const suffix = searchParams.size > 0 ? `?${searchParams.toString()}` : ""; | ||
| const response = await api.get(`/patients/${id}/documents/${category}${suffix}`); | ||
| const documents = Array.isArray(response.data) ? response.data : []; | ||
| const filteredDocuments = type | ||
| ? documents.filter((document: { type?: string }) => document.type === type) | ||
| : documents; | ||
|
|
||
| return NextResponse.json(filteredDocuments); | ||
| } catch (error) { | ||
| const err = error as AxiosError; | ||
| return NextResponse.json( | ||
| { message: err.response?.data || "Erro ao buscar documentos" }, | ||
| { status: err.response?.status || 500 }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export async function POST( | ||
| request: NextRequest, | ||
| { params }: { params: Promise<{ id: string }> }, | ||
| ) { | ||
| const { id } = await params; | ||
|
|
||
| try { | ||
| const incomingFormData = await request.formData(); | ||
| const file = incomingFormData.get("file"); | ||
| const category = incomingFormData.get("category"); | ||
| const type = incomingFormData.get("type"); | ||
| const year = incomingFormData.get("year"); | ||
|
|
||
| if (!(file instanceof File) || typeof category !== "string" || typeof type !== "string") { | ||
| return NextResponse.json({ message: "Dados de upload invalidos." }, { status: 400 }); | ||
| } | ||
|
|
||
| const formData = new FormData(); | ||
| formData.append("file", file); | ||
| formData.append("category", category); | ||
| formData.append("type", type); | ||
|
|
||
| if (typeof year === "string" && year.trim()) { | ||
| formData.append("year", year); | ||
| } | ||
|
|
||
| const api = await createBaseApi(); | ||
| const response = await api.post(`/patients/${id}/documents`, formData, { | ||
| headers: { | ||
| "Content-Type": "multipart/form-data", | ||
| }, | ||
| }); | ||
|
|
||
| return NextResponse.json(response.data, { status: response.status }); | ||
| } catch (error) { | ||
| const err = error as AxiosError; | ||
| return NextResponse.json( | ||
| { message: err.response?.data || "Erro ao enviar documento" }, | ||
| { status: err.response?.status || 500 }, | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esse ajuste resolve a rota, mas ainda mantém o domínio antigo
service-areasacoplado ao controller.Como a issue pede padronização de nomenclatura e separação de responsabilidades, acredito que o ideal seria renomear o domínio para
service-typesde forma consistente: controller, service, repository, DTOs e Swagger.Manter
/service-areasjunto com/service-typessó faria sentido como compatibilidade temporária.