@@ -12,6 +12,7 @@ import { FollowInfoRequestDto } from "./dto/follow-info-request.dto";
1212import { buildBaseFindOptions } from "../utils/buildBaseFindOptions" ;
1313import { TPaginationData } from "../utils/pagination/pagination-response.dto" ;
1414import { ActivitiesQueueService } from "../activities/activities-queue/activities-queue.service" ;
15+ import { PeriodRange } from "../utils/period" ;
1516
1617@Injectable ( )
1718export class FollowService {
@@ -24,6 +25,28 @@ export class FollowService {
2425 private readonly activitiesQueueService : ActivitiesQueueService ,
2526 ) { }
2627
28+ public async countFollowers (
29+ userId : string ,
30+ period : PeriodRange ,
31+ ) : Promise < number > {
32+ const qb = this . userFollowRepository
33+ . createQueryBuilder ( "uf" )
34+ . where ( "uf.followedUserId = :userId" , { userId } ) ;
35+
36+ if ( period . startDate ) {
37+ qb . andWhere ( "uf.createdAt >= :startDate" , {
38+ startDate : period . startDate ,
39+ } ) ;
40+ }
41+ if ( period . endDate ) {
42+ qb . andWhere ( "uf.createdAt <= :endDate" , {
43+ endDate : period . endDate ,
44+ } ) ;
45+ }
46+
47+ return qb . getCount ( ) ;
48+ }
49+
2750 public async findOneById ( id : number ) {
2851 return this . userFollowRepository . findOne ( {
2952 where : {
@@ -54,7 +77,7 @@ export class FollowService {
5477 ) ;
5578 }
5679 try {
57- const persistedEntry = await this . userFollowRepository . save ( {
80+ await this . userFollowRepository . save ( {
5881 follower : {
5982 userId : followerUserId ,
6083 } ,
0 commit comments