• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

khu-khlug / sight-backend / 13616929463

02 Mar 2025 03:40PM UTC coverage: 57.19% (-1.0%) from 58.222%
13616929463

push

github

web-flow
chore: yarn에서 npm으로 롤백 (#105)

637 of 1702 branches covered (37.43%)

Branch coverage included in aggregate %.

1797 of 2554 relevant lines covered (70.36%)

15.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/app/application/user/query/listUser/ListUserQueryHandler.ts
1
import { EntityRepository } from '@mikro-orm/mysql';
2
import { InjectRepository } from '@mikro-orm/nestjs';
×
3
import { Injectable } from '@nestjs/common';
×
4
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs';
5

6
import { ListUserQuery } from '@khlug/app/application/user/query/listUser/ListUserQuery';
7
import { ListUserQueryResult } from '@khlug/app/application/user/query/listUser/ListUserQueryResult';
8
import { UserWithTagListView } from '@khlug/app/application/user/query/view/UserListView';
9

10
import { FeeHistory } from '@khlug/app/domain/fee/model/FeeHistory';
×
11
import {
12
  StudentStatus,
×
13
  UserStatus,
14
} from '@khlug/app/domain/user/model/constant';
15
import { User } from '@khlug/app/domain/user/model/User';
×
16

×
17
import { UnivPeriod } from '@khlug/util/univPeriod';
×
18

×
19
@Injectable()
20
@QueryHandler(ListUserQuery)
21
export class ListUserQueryHandler
×
22
  implements IQueryHandler<ListUserQuery, ListUserQueryResult>
23
{
24
  constructor(
×
25
    @InjectRepository(User)
×
26
    private readonly userRepository: EntityRepository<User>,
27
    @InjectRepository(FeeHistory)
28
    private readonly feeHistoryRepository: EntityRepository<FeeHistory>,
29
  ) {}
30

31
  async execute(query: ListUserQuery): Promise<ListUserQueryResult> {
32
    const {
33
      email,
34
      phone,
35
      name,
36
      number,
37
      college,
38
      grade,
39
      studentStatus,
40
      limit,
×
41
      offset,
×
42
    } = query;
×
43

×
44
    const qb = this.userRepository.createQueryBuilder('user');
45

46
    if (email !== null) {
47
      qb.andWhere('email LIKE ?', [`%${email}%`]);
×
48
    }
×
49

50
    if (phone !== null) {
51
      qb.andWhere('phone LIKE ?', [`%${phone}%`]);
52
    }
×
53

×
54
    if (name !== null) {
55
      qb.andWhere('realname LIKE ?', [`%${name}%`]);
56
    }
57

×
58
    if (number !== null) {
×
59
      qb.andWhere('number LIKE ?', [`%${number}%`]);
60
    }
61

62
    if (college !== null) {
×
63
      qb.andWhere('college LIKE ?', [`%${college}%`]);
×
64
    }
65

66
    if (grade !== null) {
67
      qb.andWhere('grade = ?', [grade]);
×
68
    }
×
69

70
    if (studentStatus !== null) {
71
      qb.andWhere('state = ?', [studentStatus]);
72
    }
×
73

×
74
    const [users, count] = await qb
75
      .andWhere('active != 0')
76
      .andWhere('state != ?', [StudentStatus.UNITED])
77
      .limit(limit)
×
78
      .offset(offset)
79
      .orderBy({ realname: 'ASC' })
80
      .getResultAndCount();
81

82
    const feeTargetUserIds = users
×
83
      .filter((user) => user.needPayFee())
×
84
      .map((user) => user.id);
×
85
    const thisTerm = UnivPeriod.fromDate(new Date()).toTerm();
86

87
    const feeHistories = await this.feeHistoryRepository.find({
88
      user: { $in: feeTargetUserIds },
89
      year: thisTerm.year,
90
      semester: thisTerm.semester,
91
    });
×
92
    const userFeeHistorySet = new Set<number>(
×
93
      feeHistories.map((feeHistory) => feeHistory.user),
94
    );
95

×
96
    const listView: UserWithTagListView = {
×
97
      count,
×
98
      users: users.map((user) => {
×
99
        const normalTags: string[] = [];
100
        const redTags: string[] = [];
×
101

×
102
        if (user.needAuth()) {
103
          redTags.push('미인증');
×
104
        }
×
105

106
        if (user.status === UserStatus.INACTIVE) {
×
107
          redTags.push('차단');
×
108
        }
×
109

110
        if (user.point < 0) {
×
111
          redTags.push('-exp');
112
        }
113

×
114
        if (user.needPayFee() && !userFeeHistorySet.has(user.id)) {
115
          if (user.needPayHalfFee()) {
116
            normalTags.push('반액 납부 대상');
117
          } else {
118
            normalTags.push('납부 대상');
119
          }
120
        }
121

122
        return {
123
          id: user.id,
124
          name: user.name,
125
          profile: {
126
            name: user.profile.name,
127
            college: user.profile.college,
128
            grade: user.profile.grade,
129
            number: user.profile.number,
130
            email: user.profile.email,
131
            phone: user.profile.phone,
132
            homepage: user.profile.homepage,
133
            language: user.profile.language,
134
            prefer: user.profile.prefer,
135
          },
136
          admission: user.admission,
137
          studentStatus: user.studentStatus,
138
          point: user.point,
139
          status: user.status,
140
          manager: user.manager,
141
          slack: user.slack,
142
          rememberToken: user.rememberToken,
143
          khuisAuthAt: user.khuisAuthAt,
144
          returnAt: user.returnAt,
145
          returnReason: user.returnReason,
146
          lastLoginAt: user.lastLoginAt,
×
147
          lastEnterAt: user.lastEnterAt,
148
          createdAt: user.createdAt,
149
          updatedAt: user.updatedAt,
×
150
          normalTags,
×
151
          redTags,
×
152
        };
×
153
      }),
154
    };
155
    return new ListUserQueryResult(listView);
×
156
  }
157
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc