Skip to content

Commit e826f0d

Browse files
committed
removed pagination guide
1 parent 8131299 commit e826f0d

3 files changed

Lines changed: 6 additions & 135 deletions

File tree

‎Backend-Pagination-Filtering-Guide.md‎

Lines changed: 0 additions & 96 deletions
This file was deleted.

‎src/app/api/suggest/unfinalized/route.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const bodySchema = z.object({
2323
).min(1),
2424
})
2525
).min(1),
26-
includeDetails: z.boolean().optional(),
2726
});
2827

2928
export async function POST(req: NextRequest) {
@@ -43,7 +42,7 @@ export async function POST(req: NextRequest) {
4342
throw new ArgumentError(parsed.error.message);
4443
}
4544

46-
const result = await UnfinalizedSuggestionService.suggestAllocations(parsed.data.generalItems, { includeDetails: parsed.data.includeDetails });
45+
const result = await UnfinalizedSuggestionService.suggestAllocations(parsed.data.generalItems);
4746
return NextResponse.json(result, { status: 200 });
4847
} catch (error) {
4948
return errorResponse(error);

‎src/services/unfinalizedSuggestionService.ts‎

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,10 @@ export type GeneralItemInput = {
1616
requests: PartnerRequest[];
1717
};
1818

19-
export type AllocationSuggestionBasic = {
19+
export type AllocationSuggestion = {
2020
items: { requests: { partnerId: number; quantity: number }[] }[];
2121
};
2222

23-
export type AllocationSuggestionDetailed = {
24-
items: {
25-
before: { requests: { partnerId: number; quantity: number }[] };
26-
after: { requests: { partnerId: number; quantity: number }[] };
27-
}[];
28-
};
2923

3024
type PartnerTotals = {
3125
normalizedTotal: number;
@@ -198,27 +192,8 @@ function sanitizeAllocations(
198192
}));
199193
}
200194

201-
function buildDetailedResult(
202-
items: GeneralItemInput[],
203-
normalized: number[][],
204-
adjusted: { partnerId: number; quantity: number }[][]
205-
): AllocationSuggestionDetailed {
206-
return {
207-
items: items.map((item, index) => ({
208-
before: {
209-
requests: item.requests.map((request, requestIndex) => ({
210-
partnerId: request.partnerId,
211-
quantity: normalized[index][requestIndex] ?? 0,
212-
})),
213-
},
214-
after: {
215-
requests: adjusted[index],
216-
},
217-
})),
218-
};
219-
}
220195

221-
function buildBasicResult(adjusted: { partnerId: number; quantity: number }[][]): AllocationSuggestionBasic {
196+
function buildBasicResult(adjusted: { partnerId: number; quantity: number }[][]): AllocationSuggestion {
222197
return {
223198
items: adjusted.map((requests) => ({ requests })),
224199
};
@@ -227,12 +202,9 @@ function buildBasicResult(adjusted: { partnerId: number; quantity: number }[][])
227202
export class UnfinalizedSuggestionService {
228203
static async suggestAllocations(
229204
generalItems: GeneralItemInput[],
230-
options?: { includeDetails?: boolean }
231-
): Promise<AllocationSuggestionBasic | AllocationSuggestionDetailed> {
205+
): Promise<AllocationSuggestion> {
232206
if (generalItems.length === 0) {
233-
return options?.includeDetails
234-
? ({ items: [] } satisfies AllocationSuggestionDetailed)
235-
: ({ items: [] } satisfies AllocationSuggestionBasic);
207+
return { items: [] };
236208
}
237209

238210
const normalized = generalItems.map(normalizeRequests);
@@ -289,17 +261,13 @@ export class UnfinalizedSuggestionService {
289261
},
290262
});
291263

292-
modelResponse = parseModelResponse(response.choices?.[0]?.message?.content);
264+
modelResponse = parseModelResponse(response.choices?.[0]?.message?.content ?? undefined);
293265
}
294266

295267
const adjusted = generalItems.map((item, index) =>
296268
sanitizeAllocations(item, normalized[index], modelResponse?.items?.[index]?.requests)
297269
);
298270

299-
if (options?.includeDetails) {
300-
return buildDetailedResult(generalItems, normalized, adjusted);
301-
}
302-
303271
return buildBasicResult(adjusted);
304272
}
305273
}

0 commit comments

Comments
 (0)