Skip to content

Commit

Permalink
Update - removendo limite de supplies na listagem de abrigos (#136)
Browse files Browse the repository at this point in the history
### Melhorar a descoberta de que existem mais itens depois que o limite
de 10 é excedido no card

Conforme solicitado na issue
[#257](SOS-RS/frontend#257) foi removido o
limite no retorno dos supplies de abrigo.
PR do Frontend: SOS-RS/frontend#249
  • Loading branch information
xlucaix authored Jun 1, 2024
1 parent 2f50428 commit b5ba7b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
33 changes: 7 additions & 26 deletions src/shelter/ShelterSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
} from './types/search.types';

const defaultTagsData: ShelterTagInfo = {
NeedDonations: 10,
NeedVolunteers: 10,
RemainingSupplies: 10,
NeedDonations: true,
NeedVolunteers: true,
RemainingSupplies: true,
};

class ShelterSearch {
Expand Down Expand Up @@ -204,27 +204,17 @@ function parseTagResponse(
};

const parsed = results.map((result) => {
const qtd: Required<ShelterTagInfo> = {
NeedDonations: 0,
NeedVolunteers: 0,
RemainingSupplies: 0,
};
return {
...result,
shelterSupplies: result.shelterSupplies.reduce((prev, shelterSupply) => {
const supplyTags: ShelterTagType[] = [];
let tagged: boolean = false;
if (
tags.NeedDonations &&
[SupplyPriority.Needing, SupplyPriority.Urgent].includes(
shelterSupply.priority,
)
) {
if (qtd.NeedDonations < tags.NeedDonations) {
qtd.NeedDonations++;
tagged = true;
supplyTags.push('NeedDonations');
}
supplyTags.push('NeedDonations');
}
if (
tags.NeedVolunteers &&
Expand All @@ -233,24 +223,15 @@ function parseTagResponse(
shelterSupply.priority,
)
) {
if (qtd.NeedVolunteers < tags.NeedVolunteers) {
qtd.NeedVolunteers++;
tagged = true;
supplyTags.push('NeedVolunteers');
}
supplyTags.push('NeedVolunteers');
}
if (
tags.RemainingSupplies &&
[SupplyPriority.Remaining].includes(shelterSupply.priority)
) {
if (qtd.RemainingSupplies < tags.RemainingSupplies) {
qtd.RemainingSupplies++;
tagged = true;
supplyTags.push('RemainingSupplies');
}
supplyTags.push('RemainingSupplies');
}
if (tagged) return [...prev, { ...shelterSupply, tags: supplyTags }];
else return prev;
return [...prev, { ...shelterSupply, tags: supplyTags }];
}, [] as any),
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/shelter/types/search.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ShelterTagTypeSchema = z.enum([

const ShelterTagInfoSchema = z.record(
ShelterTagTypeSchema,
z.number().optional(),
z.boolean().optional(),
);

export type ShelterTagType = z.infer<typeof ShelterTagTypeSchema>;
Expand Down

0 comments on commit b5ba7b3

Please sign in to comment.