421e204711
Memind CI / Test, build, and release guards (push) Successful in 3m28s
Ship the M成果 page with list/delete UX, fix deletePage for incomplete page records, route /space/achievements, and add M成果 under the WeChat M空间 menu. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { enrichPagesWithAchievementStats } from './mindspace-page-achievement-stats.mjs';
|
|
|
|
export const DEFAULT_ACHIEVEMENT_LIMIT = 20;
|
|
|
|
export function parseAchievementQuery(query = {}) {
|
|
const limit = Number.parseInt(String(query.limit ?? ''), 10);
|
|
const offset = Number.parseInt(String(query.offset ?? ''), 10);
|
|
const includeStatsRaw = String(query.include_stats ?? '0').trim().toLowerCase();
|
|
const includeStats = includeStatsRaw === '1' || includeStatsRaw === 'true';
|
|
|
|
return {
|
|
status: typeof query.status === 'string' ? query.status : undefined,
|
|
categoryCode: typeof query.category_code === 'string' ? query.category_code : undefined,
|
|
limit: Number.isFinite(limit) ? Math.min(Math.max(limit, 1), 100) : DEFAULT_ACHIEVEMENT_LIMIT,
|
|
offset: Number.isFinite(offset) ? Math.max(offset, 0) : 0,
|
|
includeStats,
|
|
};
|
|
}
|
|
|
|
export async function listAchievementPagesForUser({
|
|
pages,
|
|
userId,
|
|
query = {},
|
|
pool = null,
|
|
logger = console,
|
|
} = {}) {
|
|
if (!pages || typeof pages.listPages !== 'function') {
|
|
throw new Error('MindSpace page service unavailable');
|
|
}
|
|
|
|
const parsed = parseAchievementQuery(query);
|
|
const result = await pages.listPages(userId, {
|
|
status: parsed.status,
|
|
categoryCode: parsed.categoryCode,
|
|
limit: parsed.limit,
|
|
offset: parsed.offset,
|
|
});
|
|
|
|
const items = await enrichPagesWithAchievementStats(result.items, {
|
|
ownerUserId: userId,
|
|
pool,
|
|
logger,
|
|
skipUmami: !parsed.includeStats,
|
|
});
|
|
|
|
return {
|
|
items,
|
|
total: result.total,
|
|
limit: result.limit,
|
|
offset: result.offset,
|
|
hasMore: Boolean(result.hasMore ?? result.offset + result.items.length < result.total),
|
|
};
|
|
}
|