Skip to content

Commit 6ba415b

Browse files
committed
update usage of getCardsByELO to new type
1 parent 5a1b663 commit 6ba415b

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

packages/mcp/src/resources/cards.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export async function handleCardsAllResource(
4242
const courseInfo = await courseDB.getCourseInfo();
4343

4444
// Get cards using ELO-based query (this gives us all cards sorted by ELO)
45-
const cardIds = await courseDB.getCardsByELO(1500, limit + offset);
45+
const eloCenteredCards = await courseDB.getCardsByELO(1500, limit + offset);
4646

4747
// Skip offset cards and take limit
48-
const targetCardIds = cardIds.slice(offset, offset + limit);
48+
const targetCards = eloCenteredCards.slice(offset, offset + limit);
4949

50-
if (targetCardIds.length === 0) {
50+
if (targetCards.length === 0) {
5151
return {
5252
cards: [],
5353
total: courseInfo.cardCount,
@@ -58,11 +58,11 @@ export async function handleCardsAllResource(
5858
}
5959

6060
// Get card documents
61-
const cardDocs = await courseDB.getCourseDocs(targetCardIds);
61+
const cardDocs = await courseDB.getCourseDocs(targetCards.map(card => card.cardID));
6262

6363
// Get ELO data for these cards
64-
const eloData = await courseDB.getCardEloData(targetCardIds);
65-
const eloMap = new Map(eloData.map((elo, index) => [targetCardIds[index], elo.global?.score || 1500]));
64+
const eloData = await courseDB.getCardEloData(targetCards.map(card => card.cardID));
65+
const eloMap = new Map(eloData.map((elo, index) => [targetCards[index], elo.global?.score || 1500]));
6666

6767
// Transform to CardResourceData format
6868
const cards: CardResourceData[] = [];
@@ -162,7 +162,7 @@ export async function handleCardsShapeResource(
162162
}
163163

164164
// Get card documents to check their shapes
165-
const cardDocs = await courseDB.getCourseDocs(allCardIds);
165+
const cardDocs = await courseDB.getCourseDocs(allCardIds.map(c => c.cardID));
166166

167167
// Filter by shape and collect card IDs
168168
const filteredCardIds: string[] = [];
@@ -240,9 +240,9 @@ export async function handleCardsEloResource(
240240

241241
// Get cards around the middle of the ELO range
242242
const targetElo = Math.floor((parsedRange.min + parsedRange.max) / 2);
243-
const cardIds = await courseDB.getCardsByELO(targetElo, 1000); // Get more to filter from
243+
const cards = await courseDB.getCardsByELO(targetElo, 1000); // Get more to filter from
244244

245-
if (cardIds.length === 0) {
245+
if (cards.length === 0) {
246246
return {
247247
cards: [],
248248
total: 0,
@@ -253,21 +253,21 @@ export async function handleCardsEloResource(
253253
}
254254

255255
// Get ELO data for all cards
256-
const eloData = await courseDB.getCardEloData(cardIds);
256+
const eloData = await courseDB.getCardEloData(cards.map(c => c.cardID));
257257

258258
// Filter by ELO range
259259
const filteredEloData = eloData
260-
.map((elo, index) => ({ elo, cardId: cardIds[index] }))
260+
.map((elo, index) => ({ elo, cardId: cards[index] }))
261261
.filter(({ elo }) => {
262262
const score = elo.global?.score || 1500;
263263
return score >= parsedRange.min && score <= parsedRange.max;
264264
});
265265

266266
// Apply pagination
267267
const paginatedEloData = filteredEloData.slice(offset, offset + limit);
268-
const paginatedCardIds = paginatedEloData.map(({ cardId }) => cardId);
268+
const paginatedCards = paginatedEloData.map(({ cardId }) => cardId);
269269

270-
if (paginatedCardIds.length === 0) {
270+
if (paginatedCards.length === 0) {
271271
return {
272272
cards: [],
273273
total: filteredEloData.length,
@@ -278,15 +278,15 @@ export async function handleCardsEloResource(
278278
}
279279

280280
// Get card documents
281-
const cardDocs = await courseDB.getCourseDocs(paginatedCardIds);
281+
const cardDocs = await courseDB.getCourseDocs(paginatedCards.map(c => c.cardID));
282282
const eloMap = new Map(paginatedEloData.map(({ elo, cardId }) => [cardId, elo.global?.score || 1500]));
283283

284284
// Transform to CardResourceData format
285-
const cards: CardResourceData[] = [];
285+
const cardsData: CardResourceData[] = [];
286286
for (const row of cardDocs.rows) {
287287
if (isSuccessRow(row)) {
288288
const doc = row.doc;
289-
cards.push({
289+
cardsData.push({
290290
cardId: doc._id,
291291
datashape: (doc as any).shape?.name || 'unknown',
292292
data: (doc as any).data || {},
@@ -299,7 +299,7 @@ export async function handleCardsEloResource(
299299
}
300300

301301
return {
302-
cards,
302+
cards: cardsData,
303303
total: filteredEloData.length,
304304
page: Math.floor(offset / limit) + 1,
305305
limit,

packages/mcp/src/resources/shapes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ export async function handleShapeSpecificResource(
8282
let examples: any[] = [];
8383
try {
8484
// Get a few cards that use this shape to provide examples
85-
const cardIds = await courseDB.getCardsByELO(1500, 10); // Get some sample cards
86-
if (cardIds.length > 0) {
87-
const cardDocs = await courseDB.getCourseDocs(cardIds.slice(0, 5)); // Limit to 5 examples
85+
const cards = await courseDB.getCardsByELO(1500, 10); // Get some sample cards
86+
if (cards.length > 0) {
87+
const cardDocs = await courseDB.getCourseDocs(cards.map(c=>c.cardID).slice(0, 5)); // Limit to 5 examples
8888
examples = [];
8989
for (const row of cardDocs.rows) {
9090
if (isSuccessRow(row) && (row.doc as any).shape?.name === shapeName) {

0 commit comments

Comments
 (0)