• 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/aggregation/get-aggregation.ts
1
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
×
NEW
2
import { IdPrefix, StatisticsFunc } from '@teable/core';
×
3
import { axios } from '../axios';
×
NEW
4
import { queryBaseSchema } from '../record';
×
5
import { registerRoute, urlBuilder } from '../utils';
×
6
import { z } from '../zod';
×
7

×
NEW
8
export { StatisticsFunc } from '@teable/core';
×
NEW
9

×
NEW
10
export const aggregationFieldSchema = z.object({
×
NEW
11
  fieldId: z.string(),
×
NEW
12
  statisticFunc: z.nativeEnum(StatisticsFunc),
×
NEW
13
});
×
NEW
14

×
NEW
15
export type IAggregationField = z.infer<typeof aggregationFieldSchema>;
×
NEW
16

×
NEW
17
export const aggregationRoSchema = queryBaseSchema.extend({
×
NEW
18
  field: z.record(z.nativeEnum(StatisticsFunc), z.string().array()).optional(),
×
NEW
19
});
×
NEW
20

×
NEW
21
export type IAggregationRo = z.infer<typeof aggregationRoSchema>;
×
NEW
22

×
NEW
23
export const aggFuncSchema = z.nativeEnum(StatisticsFunc);
×
NEW
24

×
NEW
25
export const rawAggregationsValueSchema = z.object({
×
NEW
26
  value: z.union([z.string(), z.number()]).nullable(),
×
NEW
27
  aggFunc: aggFuncSchema,
×
NEW
28
});
×
NEW
29

×
NEW
30
export type IRawAggregationsValue = z.infer<typeof rawAggregationsValueSchema>;
×
NEW
31

×
NEW
32
export const rawAggregationsSchema = z
×
NEW
33
  .object({
×
NEW
34
    fieldId: z.string().startsWith(IdPrefix.Field).openapi({
×
NEW
35
      description: 'The id of the field.',
×
NEW
36
    }),
×
NEW
37
    total: rawAggregationsValueSchema.nullable().openapi({
×
NEW
38
      description: 'Aggregations by all data in field',
×
NEW
39
    }),
×
NEW
40
    group: z.record(z.string(), rawAggregationsValueSchema).optional().nullable().openapi({
×
NEW
41
      description: 'Aggregations by grouped data in field',
×
NEW
42
    }),
×
NEW
43
  })
×
NEW
44
  .array();
×
NEW
45

×
NEW
46
export type IRawAggregations = z.infer<typeof rawAggregationsSchema>;
×
NEW
47

×
NEW
48
export const baseRawAggregationValueSchema = z.object({
×
NEW
49
  viewId: z.string().startsWith(IdPrefix.View),
×
NEW
50
  aggregations: rawAggregationsSchema,
×
NEW
51
  rowCount: z.number(),
×
NEW
52
});
×
NEW
53

×
NEW
54
export const rawAggregationValueSchema = baseRawAggregationValueSchema
×
NEW
55
  .pick({
×
NEW
56
    aggregations: true,
×
NEW
57
  })
×
NEW
58
  .partial();
×
NEW
59

×
NEW
60
export type IRawAggregationValue = z.infer<typeof rawAggregationValueSchema>;
×
NEW
61

×
NEW
62
export const aggregationVoSchema = rawAggregationValueSchema;
×
NEW
63

×
NEW
64
export type IAggregationVo = z.infer<typeof aggregationVoSchema>;
×
NEW
65

×
66
export const GET_AGGREGATION_LIST = '/table/{tableId}/aggregation';
×
67

×
68
export const GetAggregationRoute: RouteConfig = registerRoute({
×
69
  method: 'get',
×
70
  path: GET_AGGREGATION_LIST,
×
71
  description: 'Get aggregations by query',
×
72
  request: {
×
73
    params: z.object({
×
74
      tableId: z.string(),
×
75
    }),
×
76
    query: z.object({}),
×
77
  },
×
78
  responses: {
×
79
    200: {
×
80
      description: 'Returns aggregations list.',
×
81
      content: {
×
82
        'application/json': {
×
83
          schema: z.array(aggregationVoSchema),
×
84
        },
×
85
      },
×
86
    },
×
87
  },
×
88
  tags: ['aggregation'],
×
89
});
×
90

×
91
export const getAggregation = async (tableId: string, query?: IAggregationRo) => {
×
92
  return axios.get<IAggregationVo>(urlBuilder(GET_AGGREGATION_LIST, { tableId }), {
×
93
    params: query,
×
94
  });
×
95
};
×
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