Skip to content

Commit eba1bc5

Browse files
committed
fix: include only most recent editions in info query
1 parent 9963866 commit eba1bc5

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

apps/api/src/instruments/instruments.service.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import type {
2828
InstrumentInfo,
2929
ScalarInstrumentBundleContainer
3030
} from '@opendatacapture/schemas/instrument';
31+
import { pick } from 'lodash-es';
3132

3233
import type { EntityOperationOptions } from '@/core/types';
3334

@@ -179,16 +180,28 @@ export class InstrumentsService {
179180
options: EntityOperationOptions = {}
180181
): Promise<InstrumentInfo[]> {
181182
const instances = await this.find(query, options);
182-
return instances.map(({ __runtimeVersion, clientDetails, details, id, internal, kind, language, tags }) => ({
183-
__runtimeVersion,
184-
clientDetails,
185-
details,
186-
id,
187-
internal,
188-
kind,
189-
language,
190-
tags
191-
}));
183+
const results = new Map<string, InstrumentInfo>();
184+
for (const instance of instances) {
185+
const info = pick(instance, [
186+
'__runtimeVersion',
187+
'clientDetails',
188+
'details',
189+
'id',
190+
'internal',
191+
'kind',
192+
'language',
193+
'tags'
194+
]);
195+
if (!info.internal) {
196+
results.set(info.id, info);
197+
continue;
198+
}
199+
const currentEntry = results.get(info.internal.name);
200+
if (!currentEntry || info.internal.edition > currentEntry.internal!.edition) {
201+
results.set(info.internal.name, info);
202+
}
203+
}
204+
return Array.from(results.values());
192205
}
193206

194207
generateInstrumentId(instrument: AnyInstrument) {

0 commit comments

Comments
 (0)