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

alkem-io / server / #8050

16 Aug 2024 11:21AM UTC coverage: 13.92%. First build
#8050

Pull #4411

travis-ci

Pull Request #4411: Type added to authorization policy entity

80 of 4158 branches covered (1.92%)

Branch coverage included in aggregate %.

61 of 116 new or added lines in 50 files covered. (52.59%)

1945 of 10389 relevant lines covered (18.72%)

3.01 hits per line

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

30.0
/src/domain/timeline/timeline/timeline.service.ts
1
import { LogContext } from '@common/enums/logging.context';
17✔
2
import { EntityNotFoundException } from '@common/exceptions/entity.not.found.exception';
17✔
3
import { AuthorizationPolicy } from '@domain/common/authorization-policy/authorization.policy.entity';
17✔
4
import { AuthorizationPolicyService } from '@domain/common/authorization-policy/authorization.policy.service';
17✔
5
import { Inject, Injectable, LoggerService } from '@nestjs/common';
17✔
6
import { InjectRepository } from '@nestjs/typeorm';
17✔
7
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
17✔
8
import { FindOneOptions, Repository } from 'typeorm';
17✔
9
import { ICalendar } from '../calendar/calendar.interface';
10
import { CalendarService } from '../calendar/calendar.service';
17✔
11
import { Timeline } from './timeline.entity';
17✔
12
import { ITimeline } from './timeline.interface';
13
import { AuthorizationPolicyType } from '@common/enums/authorization.policy.type';
17✔
14

15
@Injectable()
16
export class TimelineService {
17✔
17
  constructor(
18
    private calendarService: CalendarService,
×
19
    private authorizationPolicyService: AuthorizationPolicyService,
×
20
    @InjectRepository(Timeline)
21
    private timelineRepository: Repository<Timeline>,
×
22
    @Inject(WINSTON_MODULE_NEST_PROVIDER) private readonly logger: LoggerService
×
23
  ) {}
24

25
  public createTimeline(): ITimeline {
26
    const timeline: ITimeline = new Timeline();
×
NEW
27
    timeline.authorization = new AuthorizationPolicy(
×
28
      AuthorizationPolicyType.TIMELINE
29
    );
30
    timeline.calendar = this.calendarService.createCalendar();
×
31

32
    return timeline;
×
33
  }
34

35
  async deleteTimeline(timelineID: string): Promise<ITimeline> {
36
    const timeline = await this.getTimelineOrFail(timelineID, {
×
37
      relations: { calendar: true },
38
    });
39

40
    if (timeline.authorization)
×
41
      await this.authorizationPolicyService.delete(timeline.authorization);
×
42

43
    if (timeline.calendar) {
×
44
      await this.calendarService.deleteCalendar(timeline.calendar.id);
×
45
    }
46

47
    return await this.timelineRepository.remove(timeline as Timeline);
×
48
  }
49

50
  async getTimelineOrFail(
51
    timelineID: string,
52
    options?: FindOneOptions<Timeline>
53
  ): Promise<ITimeline | never> {
54
    const timeline = await this.timelineRepository.findOne({
×
55
      where: { id: timelineID },
56
      ...options,
57
    });
58
    if (!timeline)
×
59
      throw new EntityNotFoundException(
×
60
        `Timeline not found: ${timelineID}`,
61
        LogContext.CALENDAR
62
      );
63
    return timeline;
×
64
  }
65

66
  async saveTimeline(timeline: ITimeline): Promise<ITimeline> {
67
    return await this.timelineRepository.save(timeline);
×
68
  }
69

70
  async getCalendarOrFail(timelineInput: ITimeline): Promise<ICalendar> {
71
    const timeline = await this.getTimelineOrFail(timelineInput.id, {
×
72
      relations: { calendar: true },
73
    });
74
    const calendar = timeline.calendar;
×
75
    if (!calendar) {
×
76
      throw new EntityNotFoundException(
×
77
        `No calendar found on timeline: ${timelineInput.id}`,
78
        LogContext.CALENDAR
79
      );
80
    }
81
    return calendar;
×
82
  }
83
}
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

© 2025 Coveralls, Inc