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

teableio / teable / 16064488882

04 Jul 2025 02:27AM UTC coverage: 80.739%. First build
16064488882

Pull #1637

github

web-flow
Merge 74100da6b into 1b3456403
Pull Request #1637: refactor: restructure settings management and introduce OpenAPI endpo…

8113 of 8626 branches covered (94.05%)

121 of 161 new or added lines in 19 files covered. (75.16%)

38532 of 47724 relevant lines covered (80.74%)

1703.44 hits per line

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

98.33
/apps/nestjs-backend/src/features/setting/setting.service.ts
1
/**
4✔
2
 * IMPORTANT LEGAL NOTICE:
3
 *
4
 * This file is part of Teable, licensed under the GNU Affero General Public License (AGPL).
5
 *
6
 * While Teable is open source software, the brand assets (including but not limited to
7
 * the Teable name, logo, and brand identity) are protected intellectual property.
8
 * Modification, replacement, or removal of these brand assets is strictly prohibited
9
 * and constitutes a violation of our trademark rights and the terms of the AGPL license.
10
 *
11
 * Under Section 7(e) of AGPLv3, we explicitly reserve all rights to the
12
 * Teable brand assets. Any unauthorized modification, redistribution, or use
13
 * of these assets, including creating derivative works that remove or replace
14
 * the brand assets, may result in legal action.
15
 */
4✔
16

17
import { Injectable } from '@nestjs/common';
18
import { PrismaService } from '@teable/db-main-prisma';
19
import type { ISettingVo } from '@teable/openapi';
20
import { isArray } from 'lodash';
21
import { ClsService } from 'nestjs-cls';
22
import type { IClsStore } from '../../types/cls';
23
import { getPublicFullStorageUrl } from '../attachments/plugins/utils';
24

25
@Injectable()
26
export class SettingService {
4✔
27
  constructor(
439✔
28
    private readonly prismaService: PrismaService,
439✔
29
    private readonly cls: ClsService<IClsStore>
439✔
30
  ) {}
439✔
31

32
  async getSetting(): Promise<ISettingVo> {
439✔
33
    const settings = await this.prismaService.setting.findMany({
360✔
34
      select: {
360✔
35
        name: true,
360✔
36
        content: true,
360✔
37
      },
360✔
38
    });
360✔
39
    const res: Record<string, unknown> = {
360✔
40
      instanceId: '',
360✔
41
    };
360✔
42
    if (!isArray(settings)) {
360✔
43
      return res as ISettingVo;
8✔
44
    }
8✔
45

46
    for (const setting of settings) {
352✔
47
      const value = this.parseSettingContent(setting.content);
309✔
48
      if (setting.name === 'brandLogo') {
309!
NEW
49
        res[setting.name] = value ? getPublicFullStorageUrl(value as string) : value;
×
50
      } else {
309✔
51
        res[setting.name] = value;
309✔
52
      }
309✔
53
    }
309✔
54

55
    return res as ISettingVo;
352✔
56
  }
352✔
57

58
  async updateSetting(updateSettingRo: Partial<ISettingVo>): Promise<ISettingVo> {
439✔
59
    const userId = this.cls.get('user.id');
13✔
60
    const updates = Object.entries(updateSettingRo).map(([name, value]) => ({
13✔
61
      where: { name },
13✔
62
      update: { content: JSON.stringify(value ?? null), lastModifiedBy: userId },
13✔
63
      create: {
13✔
64
        name,
13✔
65
        content: JSON.stringify(value ?? null),
13✔
66
        createdBy: userId,
13✔
67
      },
13✔
68
    }));
13✔
69

70
    const results = await Promise.all(
13✔
71
      updates.map((update) => this.prismaService.setting.upsert(update))
13✔
72
    );
73

74
    const res: Record<string, unknown> = {};
13✔
75
    for (const setting of results) {
13✔
76
      const value = this.parseSettingContent(setting.content);
13✔
77
      res[setting.name] = value;
13✔
78
    }
13✔
79

80
    return res as ISettingVo;
13✔
81
  }
13✔
82

83
  private parseSettingContent(content: string | null): unknown {
439✔
84
    if (!content) return null;
322✔
85

86
    try {
322✔
87
      return JSON.parse(content);
322✔
88
    } catch (error) {
322✔
89
      // If parsing fails, return the original content
174✔
90
      return content;
174✔
91
    }
174✔
92
  }
322✔
93
}
439✔
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