Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"google-auth-library": "^10.5.0",
"jsonwebtoken": "^9.0.3",
"pino-pretty": "^13.1.3",
"prisma": "^7.4.2",
"resend": "^6.9.3",
"uuid": "^13.0.0",
"zod": "^4.1.12"
Expand All @@ -45,6 +44,7 @@
"eslint-plugin-perfectionist": "^4.15.1",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-unused-imports": "^4.2.0",
"prisma": "^7.4.2",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { OrganizationsRepository } from '@/adapters/outbound/prisma/repositories
import { Route } from '@/adapters/inbound/http/decorators/route-decorator'
import type { FastifyReply, FastifyRequest } from 'fastify'
import { GetAllOrganizationsUseCase } from '@/core/use-cases/organizations/get-all-organizations'
import { getAllOrganizationsQuerySchema } from './schema'

export class GetAllOrganizationsController {
private organizationRepository: OrganizationsRepository
Expand All @@ -14,7 +15,9 @@ export class GetAllOrganizationsController {

@Route('GET', '/organizations')
async execute(request: FastifyRequest, reply: FastifyReply): Promise<void> {
const response = await this.useCase.execute()
const { name } = getAllOrganizationsQuerySchema.parse(request.query)

const response = await this.useCase.execute({ name })

return reply.status(200).send(response)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { z } from 'zod'

export const getAllOrganizationsQuerySchema = z.object({
name: z.string().optional()
})
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ export class OrganizationsRepository implements OrganizationInterface {
})
}

getAllOrganizations = async () => {
getAllOrganizations = async (filters?: { name?: string }) => {
return await prisma.organization.findMany({
where: filters?.name
? { organization_profile: { name: { contains: filters.name, mode: 'insensitive' } } }
: undefined,
include: {
organization_profile: true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface OrganizationInterface {
createOrganization: (
payload: Prisma.OrganizationUncheckedCreateInput
) => Promise<Organization>
getAllOrganizations: () => Promise<Organization[]>
getAllOrganizations: (filters?: { name?: string }) => Promise<Organization[]>
getOrganizationById: (
id: string
) => Promise<OrganizationWithProfileInclude | null>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { GetAllOrganizationsUseCaseReturn } from './types'
export class GetAllOrganizationsUseCase {
constructor(
protected readonly organizationsRepository: OrganizationsRepository
) {}
) { }

execute = async (): Promise<GetAllOrganizationsUseCaseReturn> => {
const data = await this.organizationsRepository.getAllOrganizations()
execute = async (filters?: { name?: string }): Promise<GetAllOrganizationsUseCaseReturn> => {
const data = await this.organizationsRepository.getAllOrganizations(filters)

if (!data) {
throw new OrganizationDoesNotExistError()
Expand Down
Loading