feat: 支持获取我创建的分享挑战列表以及详情数据
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user