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

alkem-io / server / #7097

21 May 2024 07:40AM UTC coverage: 13.69%. First build
#7097

Pull #3905

travis-ci

Pull Request #3905: Create & Read - Community Guidelines template

114 of 4228 branches covered (2.7%)

Branch coverage included in aggregate %.

15 of 64 new or added lines in 3 files covered. (23.44%)

1771 of 9541 relevant lines covered (18.56%)

2.8 hits per line

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

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

21
@Injectable()
19✔
22
export class CommunityGuidelinesService {
23
  constructor(
×
24
    private profileService: ProfileService,
NEW
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> {
×
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