Skip to content

Commit b15d170

Browse files
committed
fixed indentation
1 parent 65c3164 commit b15d170

1 file changed

Lines changed: 31 additions & 38 deletions

File tree

‎src/services/allocationSuggestionService.ts‎

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,37 @@ type NormalizedItem = {
1111

1212
export class AllocationSuggestionService {
1313
private static async buildWishlistMatches(
14-
generalItemId: number,
15-
lineItemIds: number[],
16-
partnerIds: number[]
17-
): Promise<Map<number, Map<number, boolean>>> {
18-
const wishlistMatches = new Map<number, Map<number, boolean>>();
19-
20-
if (!partnerIds.length) return wishlistMatches;
21-
22-
const generalItem = await db.generalItem.findUnique({
23-
where: { id: generalItemId },
24-
select: { title: true },
25-
});
26-
27-
if (!generalItem) return wishlistMatches;
28-
29-
const wishlists = await db.wishlist.findMany({
30-
where: {
31-
partnerId: { in: partnerIds },
32-
generalItemId: null, // only unfulfilled/unlinked wishlists
33-
name: generalItem.title,
34-
},
35-
select: {
36-
partnerId: true,
37-
},
38-
});
39-
40-
const partnersWithWishlist = new Set(wishlists.map((w) => w.partnerId));
41-
42-
for (const lineItemId of lineItemIds) {
43-
const partnerMatches = new Map<number, boolean>();
44-
for (const partnerId of partnerIds) {
45-
partnerMatches.set(partnerId, partnersWithWishlist.has(partnerId));
14+
generalItemTitle: string,
15+
lineItemIds: number[],
16+
partnerIds: number[]
17+
): Promise<Map<number, Map<number, boolean>>> {
18+
const wishlistMatches = new Map<number, Map<number, boolean>>();
19+
20+
if (!partnerIds.length) return wishlistMatches;
21+
22+
const wishlists = await db.wishlist.findMany({
23+
where: {
24+
partnerId: { in: partnerIds },
25+
generalItemId: null, // only unfulfilled/unlinked wishlists
26+
name: generalItemTitle,
27+
},
28+
select: {
29+
partnerId: true,
30+
},
31+
});
32+
33+
const partnersWithWishlist = new Set(wishlists.map((w) => w.partnerId));
34+
35+
for (const lineItemId of lineItemIds) {
36+
const partnerMatches = new Map<number, boolean>();
37+
for (const partnerId of partnerIds) {
38+
partnerMatches.set(partnerId, partnersWithWishlist.has(partnerId));
39+
}
40+
wishlistMatches.set(lineItemId, partnerMatches);
4641
}
47-
wishlistMatches.set(lineItemId, partnerMatches);
48-
}
4942

50-
return wishlistMatches;
51-
}
43+
return wishlistMatches;
44+
}
5245

5346
static async suggestForDonorOffer(
5447
donorOfferId: number
@@ -153,7 +146,7 @@ export class AllocationSuggestionService {
153146
const lineItemIds = lineItemsForItem.map((li) => li.lineItemId);
154147
const partnerIds = requests.map((r) => r.partnerId);
155148
const wishlistMatches = await this.buildWishlistMatches(
156-
item.id,
149+
item.title,
157150
lineItemIds,
158151
partnerIds
159152
);
@@ -221,7 +214,7 @@ export class AllocationSuggestionService {
221214
const lineItemIds = lineItems.map((li) => li.lineItemId);
222215
const partnerIds = requests.map((r) => r.partnerId);
223216
const wishlistMatches = await this.buildWishlistMatches(
224-
item.id,
217+
item.title,
225218
lineItemIds,
226219
partnerIds
227220
);

0 commit comments

Comments
 (0)