Skip to content
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
merged 19 commits into from
May 28, 2024
Merged
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
Prev Previous commit
Next Next commit
refact: added missing props
  • Loading branch information
M4rcxs committed May 27, 2024
commit 48f2dea29d53a69a0086576eed01f4a9af2b5a64
75 changes: 50 additions & 25 deletions src/modules/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,34 @@ export class DashboardService {
},
});

const categoriesWithPriorities =
await this.prismaService.supplyCategory.findMany({
select: {
id: true,
name: true,
supplies: {
select: {
shelterSupplies: {
select: {
priority: true,
shelterId: true,
},
},
},
},
},
});

const result = categoriesWithPriorities.map((category) => {
const categoriesWithPriorities = await this.prismaService.supplyCategory.findMany({
select: {
id: true,
name: true,
supplies: {
select: {
shelterSupplies: {
select: {
priority: true,
shelterId: true
}
}
}
}
}
});

const result = categoriesWithPriorities.map(category => {
const priorityCounts = {
priority100: 0,
priority10: 0,
priority1: 0,
};

const countedShelters = new Set();

category.supplies.forEach((supply) => {
supply.shelterSupplies.forEach((shelterSupply) => {
category.supplies.forEach(supply => {
supply.shelterSupplies.forEach(shelterSupply => {
if (!countedShelters.has(shelterSupply.shelterId)) {
switch (shelterSupply.priority) {
case 100:
Expand All @@ -101,7 +100,6 @@ export class DashboardService {
default:
break;
}

countedShelters.add(shelterSupply.shelterId);
}
});
Expand All @@ -126,10 +124,37 @@ export class DashboardService {
}
}, 0);

const numSheltersAvailable = allShelters.filter(shelter => {
if (shelter.actived && shelter.capacity !== null && shelter.capacity > 0) {
return (shelter.shelteredPeople ?? 0) < shelter.capacity;
}
return false;
}).length;

const numSheltersFull = allShelters.reduce((count, shelter) => {
if (shelter.actived && shelter.capacity !== null && shelter.capacity > 0) {
if ((shelter.shelteredPeople ?? 0) >= shelter.capacity) {
return count + 1;
}
}
return count;
}, 0);

const shelterWithoutInformation = allShelters.reduce((count, shelter) => {
if (shelter.shelteredPeople === null || shelter.shelteredPeople === undefined) {
return count + 1;
}
return count;
}, 0);


return {
allShelters: allShelters.length,
categoriesWithPriorities: result,
allPeopleSheltered: allPeopleSheltered,
shelterAvaliable: numSheltersAvailable,
shelterFull: numSheltersFull,
shelterWithoutInformation: shelterWithoutInformation,
categoriesWithPriorities: result,
};
}
}