@@ -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
3024type 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 }[][])
227202export 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