36 lines
972 B
TypeScript
36 lines
972 B
TypeScript
import { Level } from '../wechat-game/entities/level.entity';
|
|
import { NextLevelDto } from './dto/next-level.dto';
|
|
import { pickLevelImageFields } from '../wechat-game/level-fields.helper';
|
|
|
|
/**
|
|
* Convert a Level entity to a NextLevelDto for client consumption.
|
|
*/
|
|
export function toNextLevelDto(level: Level): NextLevelDto {
|
|
return {
|
|
id: level.id,
|
|
level: level.sortOrder,
|
|
...pickLevelImageFields(level),
|
|
answer: level.answer,
|
|
timeLimit: level.timeLimit,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Given all levels (sorted by sortOrder ASC) and the set of completed level IDs,
|
|
* return the next `count` uncompleted levels.
|
|
*/
|
|
export function findNextUncompletedLevels(
|
|
allLevelsOrdered: Level[],
|
|
completedLevelIds: Set<string>,
|
|
count: number,
|
|
): Level[] {
|
|
const result: Level[] = [];
|
|
for (const level of allLevelsOrdered) {
|
|
if (!completedLevelIds.has(level.id)) {
|
|
result.push(level);
|
|
if (result.length >= count) break;
|
|
}
|
|
}
|
|
return result;
|
|
}
|