-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add filters on getAllOrgs #12
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9790c99
feat: add filters on getAllOrgs
medinavs 1a1d9d2
feat: try to fix ci and add another filter
medinavs 3e5fe12
chore: fix ci
medinavs aa1c2eb
chore: ultima tentativa do mestre
medinavs a198f37
fix(ci.yml): adjust node version
vitingr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
29 changes: 29 additions & 0 deletions
29
src/adapters/inbound/http/controllers/organizations/get-all-organizations/schema.ts
This file contains hidden or 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,29 @@ | ||
| import { z } from 'zod' | ||
|
|
||
| const ongCategoryEnum = z.enum([ | ||
| 'animais', | ||
| 'meioAmbiente', | ||
| 'educacao', | ||
| 'saude', | ||
| 'direitosHumanos', | ||
| 'combateAFome', | ||
| 'criancasEAdolescentes', | ||
| 'idosos', | ||
| 'pessoasComDeficiencia', | ||
| 'moradoresDeRua', | ||
| 'igualdadeDeGenero', | ||
| 'refugiadosEImigrantes', | ||
| 'protecaoAnimal', | ||
| 'desenvolvimentoComunitario', | ||
| 'culturaEArte', | ||
| 'esporteEInclusao', | ||
| 'voluntariadoEDoacoes', | ||
| 'tecnologiaSocial', | ||
| 'direitosDasMulheres', | ||
| 'outros' | ||
| ]) | ||
|
|
||
| export const getAllOrganizationsQuerySchema = z.object({ | ||
| name: z.string().optional(), | ||
| ong_type: ongCategoryEnum.optional() | ||
| }) |
This file contains hidden or 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 hidden or 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
7 changes: 4 additions & 3 deletions
7
src/core/use-cases/organizations/get-all-organizations/index.ts
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 1177
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 1197
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 9161
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 2745
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 3141
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 2793
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 389
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 3621
🏁 Script executed:
Repository: ifsp-projects/backend
Length of output: 715
Filtering always requires
organization_profile, unintentionally excluding organizations without profiles.When no filters are provided to
getAllOrganizations, thewhere: { organization_profile: {} }clause still matches only organizations that have a profile, silently excluding organizations without one. Sinceorganization_profileis optional, this causes unexpected data loss for plainGET /organizationsrequests.Conditionally apply the
organization_profilefilter only when actual filters exist (nameorong_type). When no filters are provided, omit thewhereclause entirely to return all organizations.Suggested fix
getAllOrganizations = async (filters?: { name?: string; ong_type?: OngCategory }) => { + const name = filters?.name?.trim() + const hasProfileFilters = Boolean(name || filters?.ong_type) + return await prisma.organization.findMany({ - where: { - organization_profile: { - ...(filters?.name && { name: { contains: filters.name, mode: 'insensitive' } }), - ...(filters?.ong_type && { ong_type: filters.ong_type }) - } - }, + where: hasProfileFilters + ? { + organization_profile: { + is: { + ...(name && { name: { contains: name, mode: 'insensitive' } }), + ...(filters?.ong_type && { ong_type: filters.ong_type }) + } + } + } + : undefined, include: { organization_profile: true } }) }🤖 Prompt for AI Agents