• 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

31.82
/src/domain/community/community-guidelines/community.guidelines.service.ts
1
import { Injectable } from '@nestjs/common';
21✔
2
import { InjectRepository } from '@nestjs/typeorm';
21✔
3
import { FindOneOptions, FindOptionsRelations, Repository } from 'typeorm';
21✔
4
import { CommunityGuidelines } from './community.guidelines.entity';
21✔
5
import { ICommunityGuidelines } from './community.guidelines.interface';
6
import { UpdateCommunityGuidelinesInput } from './dto/community.guidelines.dto.update';
7
import { CreateCommunityGuidelinesInput } from './dto/community.guidelines.dto.create';
8
import { AuthorizationPolicy } from '@domain/common/authorization-policy/authorization.policy.entity';
21✔
9
import { IProfile } from '@domain/common/profile/profile.interface';
10
import { ProfileService } from '@domain/common/profile/profile.service';
21✔
11
import { VisualType } from '@common/enums/visual.type';
21✔
12
import { TagsetReservedName } from '@common/enums/tagset.reserved.name';
21✔
13
import { LogContext, ProfileType } from '@common/enums';
21✔
14
import { EntityNotFoundException } from '@common/exceptions';
21✔
15
import { IStorageAggregator } from '@domain/storage/storage-aggregator/storage.aggregator.interface';
21✔
16
import { TagsetType } from '@common/enums/tagset.type';
17
import { CreateTagsetInput } from '@domain/common/tagset/dto/tagset.dto.create';
21✔
18
import { AuthorizationPolicyType } from '@common/enums/authorization.policy.type';
19
import { TagsetService } from '@domain/common/tagset/tagset.service';
21✔
20

21
@Injectable()
22
export class CommunityGuidelinesService {
21✔
23
  constructor(
24
    private profileService: ProfileService,
×
25
    private tagsetService: TagsetService,
26
    @InjectRepository(CommunityGuidelines)
×
27
    private communityGuidelinesRepository: Repository<CommunityGuidelines>
28
  ) {}
29

30
  async createCommunityGuidelines(
31
    communityGuidelinesData: CreateCommunityGuidelinesInput,
32
    storageAggregator: IStorageAggregator
33
  ): Promise<ICommunityGuidelines> {
×
NEW
34
    const communityGuidelines: ICommunityGuidelines = new CommunityGuidelines();
×
35
    communityGuidelines.authorization = new AuthorizationPolicy(
36
      AuthorizationPolicyType.COMMUNITY_GUIDELINES
37
    );
38

×
39
    const defaultTagset: CreateTagsetInput = {
40
      name: TagsetReservedName.DEFAULT,
41
      type: TagsetType.FREEFORM,
42
      tags: [],
43
    };
×
44
    communityGuidelinesData.profile.tagsets =
45
      this.tagsetService.updateTagsetInputs(
46
        communityGuidelinesData.profile.tagsets,
47
        [defaultTagset]
48
      );
49

×
50
    communityGuidelines.profile = await this.profileService.createProfile(
51
      communityGuidelinesData.profile,
52
      ProfileType.COMMUNITY_GUIDELINES,
53
      storageAggregator
54
    );
55

×
56
    await this.profileService.addVisualsOnProfile(
57
      communityGuidelines.profile,
58
      communityGuidelinesData.profile.visuals,
59
      [VisualType.CARD]
60
    );
×
61

62
    return communityGuidelines;
63
  }
64

65
  async save(
66
    communityGuidelines: ICommunityGuidelines
×
67
  ): Promise<ICommunityGuidelines> {
68
    return await this.communityGuidelinesRepository.save(communityGuidelines);
69
  }
70

71
  async update(
72
    communityGuidelines: ICommunityGuidelines,
73
    communityGuidelinesData: UpdateCommunityGuidelinesInput
×
74
  ): Promise<ICommunityGuidelines> {
75
    communityGuidelines.profile = await this.profileService.updateProfile(
76
      communityGuidelines.profile,
77
      communityGuidelinesData.profile
78
    );
×
79

80
    return await this.communityGuidelinesRepository.save(communityGuidelines);
81
  }
82

83
  async eraseContent(
84
    communityGuidelines: ICommunityGuidelines
×
85
  ): Promise<ICommunityGuidelines> {
86
    communityGuidelines.profile = await this.profileService.updateProfile(
87
      communityGuidelines.profile,
88
      {
89
        displayName: '',
90
        description: '',
91
      }
×
92
    );
93

×
94
    await this.profileService.deleteAllReferencesFromProfile(
95
      communityGuidelines.profile.id
96
    );
×
97
    communityGuidelines.profile.references = [];
×
98

99
    return await this.communityGuidelinesRepository.save(communityGuidelines);
100
  }
101

102
  async deleteCommunityGuidelines(
103
    communityGuidelinesID: string
104
  ): Promise<ICommunityGuidelines> {
×
105
    const communityGuidelines = await this.getCommunityGuidelinesOrFail(
×
106
      communityGuidelinesID,
×
107
      {
108
        relations: { profile: true },
109
      }
110
    );
111

112
    await this.profileService.deleteProfile(communityGuidelines.profile.id);
×
113

×
114
    const result = await this.communityGuidelinesRepository.remove(
115
      communityGuidelines as CommunityGuidelines
116
    );
117
    result.id = communityGuidelinesID;
×
118
    return result;
119
  }
120

121
  async getCommunityGuidelinesOrFail(
122
    communityGuidelinesID: string,
123
    options?: FindOneOptions<CommunityGuidelines>
124
  ): Promise<ICommunityGuidelines | never> {
×
125
    const communityGuidelines =
126
      await this.communityGuidelinesRepository.findOne({
127
        where: { id: communityGuidelinesID },
128
        ...options,
129
      });
130

×
131
    if (!communityGuidelines)
×
132
      throw new EntityNotFoundException(
133
        `Unable to find CommunityGuidelines with ID: ${communityGuidelinesID}`,
134
        LogContext.SPACES
135
      );
136
    return communityGuidelines;
×
137
  }
138

139
  public async getProfile(
140
    communityGuidelinesInput: ICommunityGuidelines,
141
    relations?: FindOptionsRelations<ICommunityGuidelines>
142
  ): Promise<IProfile> {
143
    const communityGuidelines = await this.getCommunityGuidelinesOrFail(
144
      communityGuidelinesInput.id,
145
      {
146
        relations: { profile: true, ...relations },
147
      }
148
    );
149
    if (!communityGuidelines.profile)
150
      throw new EntityNotFoundException(
151
        `CommunityGuidelines profile not initialised: ${communityGuidelines.id}`,
152
        LogContext.COLLABORATION
153
      );
154

155
    return communityGuidelines.profile;
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

© 2025 Coveralls, Inc