teableio/teable

View on GitHub
packages/openapi/src/trash/get-items.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { RouteConfig } from '@asteasolutions/zod-to-openapi';
import { IdPrefix } from '@teable/core';
import { axios } from '../axios';
import { registerRoute } from '../utils';
import { z } from '../zod';
import type { ITrashVo } from './get';
import { ResourceType, trashVoSchema } from './get';

export const GET_TRASH_ITEMS = '/trash/items';

export const trashItemsRoSchema = z.object({
  resourceId: z.string().startsWith(IdPrefix.Base),
  resourceType: z.literal(ResourceType.Base),
});

export type ITrashItemsRo = z.infer<typeof trashItemsRoSchema>;

export const GetTrashItemsRoute: RouteConfig = registerRoute({
  method: 'get',
  path: GET_TRASH_ITEMS,
  description: 'Get trash items for base or table',
  request: {
    query: trashItemsRoSchema,
  },
  responses: {
    200: {
      description: 'Get trash successfully',
      content: {
        'application/json': {
          schema: trashVoSchema,
        },
      },
    },
  },
  tags: ['trash'],
});

export const getTrashItems = (trashItemsRo: ITrashItemsRo) => {
  return axios.get<ITrashVo>(GET_TRASH_ITEMS, { params: trashItemsRo });
};