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

teableio / teable / 8421671885

25 Mar 2024 02:23PM UTC coverage: 79.959% (+53.9%) from 26.087%
8421671885

Pull #496

github

web-flow
Merge f587f00fb into 9313e45fb
Pull Request #496: fix: unexpected link convert

3265 of 3865 branches covered (84.48%)

63 of 63 new or added lines in 4 files covered. (100.0%)

762 existing lines in 27 files now uncovered.

25183 of 31495 relevant lines covered (79.96%)

1188.33 hits per line

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

50.0
/apps/nestjs-backend/src/features/field/model/field-dto/attachment-field.dto.ts
1
import type { IAttachmentCellValue, IAttachmentItem } from '@teable/core';
2✔
2
import { AttachmentFieldCore, generateAttachmentId } from '@teable/core';
2✔
3
import { omit } from 'lodash';
2✔
4
import type { IFieldBase } from '../field-base';
2✔
5

2✔
6
export class AttachmentFieldDto extends AttachmentFieldCore implements IFieldBase {
2✔
7
  static getTokenAndNameByString(value: string): { token: string; name: string } | undefined {
2✔
UNCOV
8
    const openParenIndex = value.lastIndexOf('(');
×
UNCOV
9

×
UNCOV
10
    if (openParenIndex === -1) {
×
11
      return;
×
12
    }
×
UNCOV
13
    const name = value.slice(0, openParenIndex).trim();
×
UNCOV
14
    const token = value.slice(openParenIndex + 1, -1).trim();
×
UNCOV
15
    return { name, token };
×
UNCOV
16
  }
×
17

2✔
18
  convertCellValue2DBValue(value: unknown): unknown {
2✔
19
    return (
10✔
20
      value &&
10✔
21
      JSON.stringify((value as IAttachmentCellValue).map((item) => omit(item, ['presignedUrl'])))
2✔
22
    );
10✔
23
  }
10✔
24

2✔
25
  convertDBValue2CellValue(value: unknown): unknown {
2✔
26
    return value == null || typeof value === 'object' ? value : JSON.parse(value as string);
766✔
27
  }
766✔
28

2✔
29
  override convertStringToCellValue(
2✔
30
    value: string,
8✔
31
    attachments?: Omit<IAttachmentItem, 'id' | 'name'>[]
8✔
32
  ) {
8✔
33
    // value is ddd.svg (token)
8✔
34
    if (!attachments?.length || !value) {
8!
35
      return null;
8✔
36
    }
8!
37
    const tokensAndNames = value.split(',').map(AttachmentFieldDto.getTokenAndNameByString);
×
38
    return tokensAndNames
×
39
      .map((tokenAndName) => {
×
40
        const { token, name } = tokenAndName || {};
×
41
        if (!token) {
×
42
          return;
×
43
        }
×
44
        const attachment = attachments.find((attachment) => attachment.token === token);
×
45
        if (!attachment) {
×
46
          return;
×
47
        }
×
48
        return {
×
49
          ...attachment,
×
50
          name,
×
51
          id: generateAttachmentId(),
×
52
        };
×
53
      })
×
54
      .filter(Boolean) as IAttachmentItem[];
×
55
  }
×
56
}
2✔
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