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

teableio / teable / 8389034572

22 Mar 2024 10:38AM CUT coverage: 26.087% (-2.1%) from 28.208%
8389034572

Pull #487

github

web-flow
Merge 3045b1f94 into a06c6afb1
Pull Request #487: refactor: move zod schema to openapi

2100 of 3363 branches covered (62.44%)

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

224 existing lines in 8 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

0.0
/packages/openapi/src/record/create.ts
1
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
×
NEW
2
import { recordSchema } from '@teable/core';
×
3
import { axios } from '../axios';
×
4
import { registerRoute, urlBuilder } from '../utils';
×
5
import { z } from '../zod';
×
NEW
6
import { fieldKeyTypeRoSchema, typecastSchema } from './get';
×
NEW
7
import { recordsVoSchema } from './get-list';
×
NEW
8

×
NEW
9
export const recordInsertOrderRoSchema = z
×
NEW
10
  .object({
×
NEW
11
    viewId: z.string().openapi({
×
NEW
12
      description:
×
NEW
13
        'You can only specify order in one view when create record, other views appear last by default',
×
NEW
14
    }),
×
NEW
15
    anchorId: z.string().openapi({
×
NEW
16
      description: 'The record id to anchor to',
×
NEW
17
    }),
×
NEW
18
    position: z.enum(['before', 'after']),
×
NEW
19
  })
×
NEW
20
  .openapi({
×
NEW
21
    description: 'Where this record to insert to',
×
NEW
22
  });
×
NEW
23

×
NEW
24
export type IRecordInsertOrderRo = z.infer<typeof recordInsertOrderRoSchema>;
×
NEW
25

×
NEW
26
export const createRecordsRoSchema = z
×
NEW
27
  .object({
×
NEW
28
    fieldKeyType: fieldKeyTypeRoSchema,
×
NEW
29
    typecast: typecastSchema,
×
NEW
30
    order: recordInsertOrderRoSchema.optional(),
×
NEW
31
    records: z
×
NEW
32
      .object({
×
NEW
33
        fields: recordSchema.shape.fields,
×
NEW
34
      })
×
NEW
35
      .array()
×
NEW
36
      .openapi({
×
NEW
37
        example: [
×
NEW
38
          {
×
NEW
39
            fields: {
×
NEW
40
              'single line text': 'text value',
×
NEW
41
            },
×
NEW
42
          },
×
NEW
43
        ],
×
NEW
44
        description: 'Array of record objects ',
×
NEW
45
      }),
×
NEW
46
  })
×
NEW
47
  .openapi({
×
NEW
48
    description: 'Multiple Create records',
×
NEW
49
  });
×
NEW
50

×
NEW
51
export type ICreateRecordsRo = z.infer<typeof createRecordsRoSchema>;
×
NEW
52

×
NEW
53
export const createRecordsVoSchema = recordsVoSchema.omit({
×
NEW
54
  offset: true,
×
NEW
55
});
×
NEW
56

×
NEW
57
export type ICreateRecordsVo = z.infer<typeof createRecordsVoSchema>;
×
58

×
59
export const CREATE_RECORD = '/table/{tableId}/record';
×
60

×
61
export const CreateRecordRoute: RouteConfig = registerRoute({
×
62
  method: 'post',
×
63
  path: CREATE_RECORD,
×
64
  description: 'Create multiple records',
×
65
  request: {
×
66
    params: z.object({
×
67
      tableId: z.string(),
×
68
    }),
×
69
    body: {
×
70
      content: {
×
71
        'application/json': {
×
72
          schema: createRecordsRoSchema,
×
73
        },
×
74
      },
×
75
    },
×
76
  },
×
77
  responses: {
×
78
    201: {
×
79
      description: 'Returns data about the records.',
×
80
      content: {
×
81
        'application/json': {
×
82
          schema: createRecordsVoSchema,
×
83
        },
×
84
      },
×
85
    },
×
86
  },
×
87
  tags: ['record'],
×
88
});
×
89

×
90
export const createRecords = async (tableId: string, recordsRo: ICreateRecordsRo) => {
×
91
  return axios.post<ICreateRecordsVo>(urlBuilder(CREATE_RECORD, { tableId }), recordsRo);
×
92
};
×
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