Browse Source

refactor(nocodb): list response

pull/5269/head
Wing-Kam Wong 2 years ago
parent
commit
6d7754fe80
  1. 4
      packages/nocodb/src/lib/controllers/filter.ctl.ts
  2. 15
      packages/nocodb/src/lib/controllers/hook.ctl.ts
  3. 16
      packages/nocodb/src/lib/controllers/sort.ctl.ts
  4. 15
      packages/nocodb/src/lib/controllers/view.ctl.ts

4
packages/nocodb/src/lib/controllers/filter.ctl.ts

@ -3,14 +3,14 @@ import ncMetaAclMw from '../meta/helpers/ncMetaAclMw';
import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { metaApiMetrics } from '../meta/helpers/apiMetrics';
import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse';
import { filterService } from '../services'; import { filterService } from '../services';
import type { FilterReqType } from 'nocodb-sdk'; import type { FilterListType, FilterReqType } from 'nocodb-sdk';
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
export async function filterGet(req: Request, res: Response) { export async function filterGet(req: Request, res: Response) {
res.json(await filterService.filterGet({ filterId: req.params.filterId })); res.json(await filterService.filterGet({ filterId: req.params.filterId }));
} }
export async function filterList(req: Request, res: Response) { export async function filterList(req: Request, res: Response<FilterListType>) {
res.json( res.json(
new PagedResponseImpl( new PagedResponseImpl(
await filterService.filterList({ await filterService.filterList({

15
packages/nocodb/src/lib/controllers/hook.ctl.ts

@ -54,14 +54,13 @@ export async function hookTest(req: Request<any, any>, res: Response) {
} }
export async function tableSampleData(req: Request, res: Response) { export async function tableSampleData(req: Request, res: Response) {
res // todo: pagination res.json(
.json( await hookService.tableSampleData({
await hookService.tableSampleData({ tableId: req.params.tableId,
tableId: req.params.tableId, // todo: replace any with type
// todo: replace any with type operation: req.params.operation as any,
operation: req.params.operation as any, })
}) );
);
} }
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });

16
packages/nocodb/src/lib/controllers/sort.ctl.ts

@ -6,20 +6,19 @@ import { sortService } from '../services';
import type { SortListType, SortReqType } from 'nocodb-sdk'; import type { SortListType, SortReqType } from 'nocodb-sdk';
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
// @ts-ignore
export async function sortList( export async function sortList(
req: Request<any, any, any>, req: Request<any, any, any>,
res: Response<SortListType> res: Response<SortListType>
) { ) {
const sortList = await sortService.sortList({ res.json(
viewId: req.params.viewId, new PagedResponseImpl(
}); await sortService.sortList({
res.json({ viewId: req.params.viewId,
sorts: new PagedResponseImpl(sortList), })
}); )
);
} }
// @ts-ignore
export async function sortCreate(req: Request<any, any, SortReqType>, res) { export async function sortCreate(req: Request<any, any, SortReqType>, res) {
const sort = await sortService.sortCreate({ const sort = await sortService.sortCreate({
sort: req.body, sort: req.body,
@ -42,6 +41,7 @@ export async function sortDelete(req: Request, res: Response) {
}); });
res.json(sort); res.json(sort);
} }
export async function sortGet(req: Request, res: Response) { export async function sortGet(req: Request, res: Response) {
const sort = await sortService.sortGet({ const sort = await sortService.sortGet({
sortId: req.params.sortId, sortId: req.params.sortId,

15
packages/nocodb/src/lib/controllers/view.ctl.ts

@ -9,14 +9,15 @@ import type { Request, Response } from 'express';
// @ts-ignore // @ts-ignore
export async function viewGet(req: Request, res: Response) {} export async function viewGet(req: Request, res: Response) {}
// @ts-ignore
export async function viewList(req: Request<any, any, any>, res: Response) { export async function viewList(req: Request<any, any, any>, res: Response) {
const filteredViewList = await viewService.viewList({ res.json(
tableId: req.params.tableId, new PagedResponseImpl(
user: (req as any).session?.passport?.user, await viewService.viewList({
}); tableId: req.params.tableId,
user: (req as any).session?.passport?.user,
res.json(new PagedResponseImpl(filteredViewList)); })
)
);
} }
// @ts-ignore // @ts-ignore

Loading…
Cancel
Save