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

teableio / teable / 8421654220

25 Mar 2024 02:22PM CUT coverage: 79.934% (+53.8%) from 26.087%
8421654220

Pull #495

github

web-flow
Merge 4faeebea5 into 1869c986d
Pull Request #495: chore: add licenses for non-NPM packages

3256 of 3853 branches covered (84.51%)

25152 of 31466 relevant lines covered (79.93%)

1188.29 hits per line

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

31.25
/apps/nestjs-backend/src/features/automation/actions/records/create-record/create-record.ts
1
import { Injectable, Logger, Scope } from '@nestjs/common';
2✔
2
import { FieldKeyType } from '@teable/core';
2✔
3
import type { ICreateRecordsRo } from '@teable/openapi';
2✔
4
import type { Almanac, Event, RuleResult } from 'json-rules-engine';
2✔
5
import { RecordOpenApiService } from '../../../../record/open-api/record-open-api.service';
2✔
6
import type { IActionResponse, IConstSchema, IObjectSchema } from '../../action-core';
2✔
7
import { actionConst, ActionCore, ActionResponseStatus } from '../../action-core';
2✔
8

2✔
9
export interface ICreateRecordSchema extends Record<string, unknown> {
2✔
10
  tableId: IConstSchema;
2✔
11
  fields: IObjectSchema;
2✔
12
}
2✔
13

2✔
14
export interface ICreateRecordOptions {
2✔
15
  tableId: string;
2✔
16
  fields: { [fieldIdOrName: string]: unknown };
2✔
17
}
2✔
18

2✔
19
@Injectable({ scope: Scope.REQUEST })
2✔
20
export class CreateRecord extends ActionCore {
2✔
21
  private logger = new Logger(CreateRecord.name);
×
22

×
23
  constructor(private readonly recordOpenApiService: RecordOpenApiService) {
×
24
    super();
×
25
  }
×
26

×
27
  bindParams(id: string, params: ICreateRecordSchema, priority?: number): this {
×
28
    return this.setName(id).setEvent({ type: id, params: params }).setPriority(priority);
×
29
  }
×
30

×
31
  onSuccess = async (event: Event, almanac: Almanac, _ruleResult: RuleResult): Promise<void> => {
×
32
    const { tableId, fields } = await this.parseInputSchema<ICreateRecordOptions>(
×
33
      event.params as ICreateRecordSchema,
×
34
      almanac
×
35
    );
×
36

×
37
    const createData: ICreateRecordsRo = {
×
38
      fieldKeyType: FieldKeyType.Id,
×
39
      records: [{ fields }],
×
40
    };
×
41

×
42
    let outPut: IActionResponse<unknown>;
×
43

×
44
    await this.recordOpenApiService
×
45
      .multipleCreateRecords(tableId, createData)
×
46
      .then((recordsVo) => {
×
47
        const {
×
48
          records: [record],
×
49
        } = recordsVo;
×
50
        outPut = { data: record, status: ActionResponseStatus.OK };
×
51
      })
×
52
      .catch((error) => {
×
53
        this.logger.error(error.message, error?.stack);
×
54
        outPut = {
×
55
          error: error.message,
×
56
          data: undefined,
×
57
          status: ActionResponseStatus.InternalServerError,
×
58
        };
×
59
      })
×
60
      .finally(() => {
×
61
        almanac.addRuntimeFact(`${actionConst.OutPutFlag}${this.name}`, outPut);
×
62
      });
×
63
  };
×
64
}
×
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