feat: 支持获取我创建的分享挑战列表以及详情数据

This commit is contained in:
richarjiang
2026-04-13 09:08:11 +08:00
parent fe2c13258e
commit 1d6cd0cdc0
10 changed files with 569 additions and 82 deletions

View File

@@ -3,6 +3,11 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ShareParticipant } from '../entities/share-participant.entity';
type ShareParticipantCountRow = {
shareConfigId: string;
participantCount: string;
};
@Injectable()
export class ShareParticipantRepository {
constructor(
@@ -28,6 +33,28 @@ export class ShareParticipantRepository {
return this.repository.count({ where: { shareConfigId } });
}
async countByShareConfigIds(
shareConfigIds: string[],
): Promise<Map<string, number>> {
if (shareConfigIds.length === 0) {
return new Map();
}
const rows = await this.repository
.createQueryBuilder('participant')
.select('participant.shareConfigId', 'shareConfigId')
.addSelect('COUNT(participant.id)', 'participantCount')
.where('participant.shareConfigId IN (:...shareConfigIds)', {
shareConfigIds,
})
.groupBy('participant.shareConfigId')
.getRawMany<ShareParticipantCountRow>();
return new Map(
rows.map((row) => [row.shareConfigId, Number(row.participantCount)]),
);
}
async findByShareConfigAndParticipant(
shareConfigId: string,
participantId: string,