Skip to content

feat: add top endpoint to supplies#45

Closed
balsemao wants to merge 3 commits intoSOS-RS:developfrom
balsemao:ft-top-10
Closed

feat: add top endpoint to supplies#45
balsemao wants to merge 3 commits intoSOS-RS:developfrom
balsemao:ft-top-10

Conversation

@balsemao
Copy link
Copy Markdown

@balsemao balsemao commented May 10, 2024

Adicionado o endpoint /supplies/top com os parâmetros page e perPage.

curl 'localhost:4000/supplies/top?perPage=3&page=1'
{
  "statusCode": 200,
  "message": "Successfully get top supplies",
  "data": [
    {
      "name": "1 Notebook pode ser usado",
      "amount": 1
    },
    {
      "name": "Aparelho de barbear",
      "amount": 1
    },
    {
      "name": "Turnos de manhã",
      "amount": 1
    }
  ]
}

Em seguida atualizo com o filtro por abrigo.

Comment thread src/supply/supply.controller.ts Outdated
@Get('top')
async top(@Query('limit') limit: number = 10, @Query('skip') skip: number) {
try {
if (limit && typeof limit === 'string') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

é só usar o pipe ParseIntPipe

see: https://docs.nestjs.com/pipes#built-in-pipes

Copy link
Copy Markdown
Author

@balsemao balsemao May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boa, ajustado!

Comment thread src/supply/supply.service.ts Outdated
@balsemao
Copy link
Copy Markdown
Author

Vou precisar mudar a abordagem. O Prisma, ao que tudo indica, não suporta JOIN no aggregate(). Desta forma, vou precisar incluir a query bruta de SQL.

@balsemao
Copy link
Copy Markdown
Author

@AndersonCRocha atualizei o PR utilizando uma nova query para que sejam contados os top N items por abrigo. Incluído também o filtro por abrigo (shelterId, opcional)

@pastorini-cesar
Copy link
Copy Markdown

@balsemao Veja o que consegue usar desse commit cesarpastorini@e74abe5

@balsemao
Copy link
Copy Markdown
Author

@balsemao Veja o que consegue usar desse commit cesarpastorini@e74abe5

Valeu! Eu acabei fazendo o CAST para int na própria query e resolveu o problema.

@balsemao balsemao closed this Mar 31, 2026
@balsemao balsemao deleted the ft-top-10 branch March 31, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants