-
Notifications
You must be signed in to change notification settings - Fork 303
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
feat: Add dashboard endpoints #131
Merged
rodrigooler
merged 19 commits into
SOS-RS:develop
from
LeonardoSantosBR:dashboard-endpoints
May 28, 2024
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d3cd6c2
feat: dashboard endpoints
LeonardoSantosBR 0e919b0
feat: add supplies in return shelters
M4rcxs 480a6ce
Merge branch 'SOS-RS:develop' into dashboard-endpoints
LeonardoSantosBR 16406e9
feat: cron e query no dashboard
LeonardoSantosBR 4ba38bd
Merge branch 'develop' into dashboard-endpoints
M4rcxs 11e224d
fix: cron retirado
LeonardoSantosBR 7e0d8df
Merge branch 'develop' of https://github.com/SOS-RS/backend into dash…
M4rcxs ada487b
refact: changing the logic of the query implementations
M4rcxs 18e94cb
refact: adding sheltered people
M4rcxs 4e2b486
refact: removing unused columns
M4rcxs ea15045
refact: changing the logic of counting categories
M4rcxs 6bbb19b
Merge branch 'develop' into dashboard-endpoints
M4rcxs 8bb3ed8
refact: adding sheltered people
M4rcxs 454cee6
Merge branch 'dashboard-endpoints' of https://github.com/LeonardoSant…
M4rcxs 29f2a52
fix: entity removido
LeonardoSantosBR 13290c7
Merge branch 'dashboard-endpoints' of https://github.com/LeonardoSant…
LeonardoSantosBR e29f419
fix: comentarios removidos
LeonardoSantosBR 48f2dea
refact: added missing props
M4rcxs 1dd16d3
feat: add dump updated
M4rcxs 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 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,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DashboardController } from './dashboard.controller'; | ||
import { DashboardService } from './dashboard.service'; | ||
|
||
describe('DashboardController', () => { | ||
let controller: DashboardController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [DashboardController], | ||
providers: [DashboardService], | ||
}).compile(); | ||
|
||
controller = module.get<DashboardController>(DashboardController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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,20 @@ | ||
import { Controller, Get, HttpException, Logger, Query } from '@nestjs/common'; | ||
import { DashboardService } from './dashboard.service'; | ||
import { ServerResponse } from '@/utils/utils'; | ||
|
||
@Controller('dashboard') | ||
export class DashboardController { | ||
private logger = new Logger(); | ||
constructor(private readonly dashboardService: DashboardService) {} | ||
|
||
@Get('') | ||
async index() { | ||
try { | ||
const data = await this.dashboardService.index(); | ||
return new ServerResponse(200, 'Successfully get dashboard', data); | ||
} catch (err: any) { | ||
this.logger.error(`Failed to get shelters: ${err}`); | ||
throw new HttpException(err?.code ?? err?.name ?? `${err}`, 400); | ||
} | ||
} | ||
} |
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,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { DashboardService } from './dashboard.service'; | ||
import { DashboardController } from './dashboard.controller'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
controllers: [DashboardController], | ||
providers: [DashboardService], | ||
}) | ||
export class DashboardModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DashboardService } from './dashboard.service'; | ||
|
||
describe('DashboardService', () => { | ||
let service: DashboardService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [DashboardService], | ||
}).compile(); | ||
|
||
service = module.get<DashboardService>(DashboardService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,40 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class DashboardService { | ||
constructor(private readonly prismaService: PrismaService) {} | ||
|
||
async index() { | ||
const allShelters = await this.prismaService.shelter.findMany({ include: { shelterSupplies: true }}); | ||
|
||
const allPeopleSheltered = allShelters.reduce((accumulator, current) => { | ||
return accumulator + (current.shelteredPeople ?? 0); | ||
}, 0); | ||
|
||
let shelterAvailable = 0; | ||
let shelterFull = 0; | ||
let shelterWithoutInformation = 0; | ||
|
||
allShelters.forEach((shelter) => { | ||
if (shelter.shelteredPeople !== null && shelter.capacity !== null) { | ||
if (shelter.shelteredPeople < shelter.capacity) { | ||
shelterAvailable++; | ||
} else if (shelter.shelteredPeople >= shelter.capacity) { | ||
shelterFull++; | ||
} | ||
} else { | ||
shelterWithoutInformation++; | ||
} | ||
}); | ||
|
||
|
||
return { | ||
allShelters: allShelters.length, | ||
allPeopleSheltered: allPeopleSheltered, | ||
shelterAvailable: shelterAvailable, | ||
shelterFull: shelterFull, | ||
shelterWithoutInformation: shelterWithoutInformation, | ||
}; | ||
} | ||
} |
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 @@ | ||
export class Dashboard {} | ||
rodrigooler marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Não é nada indicado buscar todos os dados do banco assim e fazer processamento em memória, o correto é fazer a consulta SQL já trazendo as informações necessárias