• 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

78.65
/src/app/application/user/command/updateUser/UpdateUserCommandHandler.ts
1
import { Inject, NotFoundException } from '@nestjs/common';
2
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
1✔
3

4
import { Transactional } from '@khlug/core/persistence/transaction/Transactional';
5

1✔
6
import { UpdateUserCommand } from '@khlug/app/application/user/command/updateUser/UpdateUserCommand';
7
import { UpdateUserCommandResult } from '@khlug/app/application/user/command/updateUser/UpdateUserCommandResult';
8

2✔
9
import {
10
  IInterestRepository,
11
  InterestRepository,
1✔
12
} from '@khlug/app/domain/interest/IInterestRepository';
1✔
13
import {
1✔
14
  IUserInterestRepository,
1✔
15
  UserInterestRepository,
1✔
16
} from '@khlug/app/domain/interest/IUserInterestRepository';
1✔
17
import { UserInterest } from '@khlug/app/domain/interest/model/UserInterest';
1✔
18
import { UserInterestFactory } from '@khlug/app/domain/interest/UserInterestFactory';
1✔
19
import {
1✔
20
  IUserRepository,
1✔
21
  UserRepository,
22
} from '@khlug/app/domain/user/IUserRepository';
4!
23

×
24
import { Message } from '@khlug/constant/message';
25

26
@CommandHandler(UpdateUserCommand)
27
export class UpdateUserCommandHandler
28
  implements ICommandHandler<UpdateUserCommand, UpdateUserCommandResult>
29
{
30
  constructor(
4✔
31
    @Inject(UserInterestFactory)
32
    private readonly userInterestFactory: UserInterestFactory,
4✔
33
    @Inject(UserRepository)
34
    private readonly userRepository: IUserRepository,
35
    @Inject(InterestRepository)
2!
36
    private readonly interestRepository: IInterestRepository,
2!
37
    @Inject(UserInterestRepository)
×
38
    private readonly userInterestRepository: IUserInterestRepository,
2✔
39
  ) {}
40

41
  @Transactional()
5!
42
  async execute(command: UpdateUserCommand): Promise<UpdateUserCommandResult> {
43
    const { userId, email, phone, homepage, language, interestIds, prefer } =
44
      command;
4✔
45

4✔
46
    const user = await this.userRepository.findById(userId);
47
    if (!user) {
48
      throw new NotFoundException(Message.USER_NOT_FOUND);
49
    }
50

7✔
51
    user.setProfile({ email, phone, homepage, language, prefer });
7✔
52
    await this.updateInterests(userId, interestIds);
7✔
53

1✔
54
    await this.userRepository.save(user);
55

6✔
56
    return new UpdateUserCommandResult(user);
57
  }
58

59
  private async updateInterests(
60
    userId: number,
61
    interestIds: string[],
62
  ): Promise<void> {
6✔
63
    const interests = await this.interestRepository.findByIds(interestIds);
5✔
64
    if (interestIds.length !== interests.length) {
5✔
65
      throw new NotFoundException(Message.SOME_INTERESTS_NOT_FOUND);
66
    }
67

6✔
68
    await this.userInterestRepository.removeByUserId(userId);
6✔
69

1✔
70
    const newUserInterests: UserInterest[] = interestIds.map((interestId) => {
71
      const newUserInterest = this.userInterestFactory.create({
5✔
72
        id: this.userInterestRepository.nextId(),
5✔
73
        userId,
10✔
74
        interestId,
75
      });
76
      return newUserInterest;
77
    });
78

10✔
79
    await this.userInterestRepository.save(...newUserInterests);
80
  }
5✔
81
}
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