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

teableio / teable / 8389227144

22 Mar 2024 10:56AM UTC coverage: 26.087% (-53.9%) from 79.937%
8389227144

push

github

web-flow
refactor: move zod schema to openapi (#487)

2100 of 3363 branches covered (62.44%)

282 of 757 new or added lines in 74 files covered. (37.25%)

14879 existing lines in 182 files now uncovered.

25574 of 98035 relevant lines covered (26.09%)

5.17 hits per line

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

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

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

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

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

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

1✔
29
  override convertStringToCellValue(
1✔
UNCOV
30
    value: string,
×
UNCOV
31
    attachments?: Omit<IAttachmentItem, 'id' | 'name'>[]
×
UNCOV
32
  ) {
×
UNCOV
33
    // value is ddd.svg (token)
×
UNCOV
34
    if (!attachments?.length || !value) {
×
UNCOV
35
      return null;
×
UNCOV
36
    }
×
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
}
1✔
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