Browse Source

refactor: handler to service-controller - table and column

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5239/head
Pranav C 2 years ago
parent
commit
60507cc433
  1. 6
      packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts
  2. 11
      packages/nocodb-sdk/src/lib/sqlUi/SqlUiFactory.ts
  3. 1780
      packages/nocodb/src/lib/controllers/columnController.ts
  4. 24
      packages/nocodb/src/lib/controllers/filterController.ts
  5. 8
      packages/nocodb/src/lib/meta/api/helpers/columnHelpers.ts
  6. 1778
      packages/nocodb/src/lib/services/columnService.ts
  7. 11
      packages/nocodb/src/lib/services/filterService.ts
  8. 2
      packages/nocodb/src/lib/services/index.ts
  9. 4
      packages/nocodb/src/lib/services/tableService.ts

6
packages/nocodb-sdk/src/lib/sqlUi/OracleUi.ts

@ -1,3 +1,4 @@
import { NormalColumnRequestType } from '../Api'
import UITypes from '../UITypes'; import UITypes from '../UITypes';
import { IDType } from './index'; import { IDType } from './index';
@ -794,7 +795,10 @@ export class OracleUi {
} }
} }
static getDataTypeForUiType(col: { uidt: UITypes }, idType?: IDType) { static getDataTypeForUiType(
col: { uidt: UITypes | NormalColumnRequestType['uidt'] },
idType?: IDType
) {
const colProp: any = {}; const colProp: any = {};
switch (col.uidt) { switch (col.uidt) {
case 'ID': case 'ID':

11
packages/nocodb-sdk/src/lib/sqlUi/SqlUiFactory.ts

@ -1,3 +1,4 @@
import { BoolType } from '../Api'
import UITypes from '../UITypes'; import UITypes from '../UITypes';
import { MssqlUi } from './MssqlUi'; import { MssqlUi } from './MssqlUi';
@ -56,12 +57,12 @@ export type SqlUIColumn = {
dt?: string; dt?: string;
dtx?: string; dtx?: string;
ct?: string; ct?: string;
nrqd?: boolean; nrqd?: BoolType;
rqd?: boolean; rqd?: BoolType;
ck?: string; ck?: string;
pk?: boolean; pk?: BoolType;
un?: boolean; un?: BoolType;
ai?: boolean; ai?: BoolType;
cdf?: string | any; cdf?: string | any;
clen?: number | any; clen?: number | any;
np?: string; np?: string;

1780
packages/nocodb/src/lib/controllers/columnController.ts

File diff suppressed because it is too large Load Diff

24
packages/nocodb/src/lib/controllers/filterController.ts

@ -16,15 +16,8 @@ import { metaApiMetrics } from '../meta/helpers/apiMetrics';
import { getAjvValidatorMw } from '../meta/api/helpers'; import { getAjvValidatorMw } from '../meta/api/helpers';
// @ts-ignore // @ts-ignore
export async function filterGet(req: Request, res: Response, next) { export async function filterGet(req: Request, res: Response) {
try { res.json(await Filter.get(req.params.filterId));
const filter = await Filter.get(req.params.filterId);
res.json(filter);
} catch (e) {
console.log(e);
next(e);
}
} }
// @ts-ignore // @ts-ignore
@ -33,14 +26,11 @@ export async function filterList(
res: Response, res: Response,
next next
) { ) {
try { res.json(
const filter = await Filter.rootFilterList({ viewId: req.params.viewId }); await Filter.rootFilterList({
viewId: req.params.viewId,
res.json(filter); })
} catch (e) { );
console.log(e);
next(e);
}
} }
// @ts-ignore // @ts-ignore
export async function filterChildrenRead( export async function filterChildrenRead(

8
packages/nocodb/src/lib/meta/api/helpers/columnHelpers.ts

@ -1,9 +1,9 @@
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import { import {
BoolType,
ColumnReqType, ColumnReqType,
LinkToAnotherRecordType, LinkToAnotherRecordType,
LookupColumnReqType, LookupColumnReqType,
BoolType,
RelationTypes, RelationTypes,
RollupColumnReqType, RollupColumnReqType,
TableType, TableType,
@ -77,9 +77,7 @@ export async function createHmAndBtColumn(
} }
} }
export async function validateRollupPayload( export async function validateRollupPayload(payload: ColumnReqType | Column) {
payload: ColumnReqType & { uidt: UITypes }
) {
validateParams( validateParams(
[ [
'title', 'title',
@ -125,7 +123,7 @@ export async function validateRollupPayload(
} }
export async function validateLookupPayload( export async function validateLookupPayload(
payload: ColumnReqType & { uidt: UITypes }, payload: ColumnReqType,
columnId?: string columnId?: string
) { ) {
validateParams( validateParams(

1778
packages/nocodb/src/lib/services/columnService.ts

File diff suppressed because it is too large Load Diff

11
packages/nocodb/src/lib/services/filterService.ts

@ -0,0 +1,11 @@
import Filter from '../models/Filter'
export async function filterGet(param: { filterId: string }) {
const filter = await Filter.get(param.filterId)
return filter
}
export async function filterList(param: { viewId: string }) {
const filter = await Filter.rootFilterList({ viewId: param.viewId })
return filter
}

2
packages/nocodb/src/lib/services/index.ts

@ -1,2 +1,4 @@
// export * as projectService from './projectService'; // export * as projectService from './projectService';
export * as tableService from './tableService'; export * as tableService from './tableService';
export * as columnService from './columnService';
export * as filterService from './filterService';

4
packages/nocodb/src/lib/services/tableService.ts

@ -32,7 +32,7 @@ export function reorderTable(param: { tableId: string; order: any }) {
return Model.updateOrder(param.tableId, param.order); return Model.updateOrder(param.tableId, param.order);
} }
export async function deleteTable(param: { tableId: string; user: User }) { export async function tableDelete(param: { tableId: string; user: User }) {
const table = await Model.getByIdOrName({ id: param.tableId }); const table = await Model.getByIdOrName({ id: param.tableId });
await table.getColumns(); await table.getColumns();
@ -193,7 +193,7 @@ export async function getAccessibleTables(param: {
: (tableList.filter((t) => !t.mm) as Model[]); : (tableList.filter((t) => !t.mm) as Model[]);
} }
export async function createTable(args: { export async function tableCreate(args: {
projectId: string; projectId: string;
baseId?: string; baseId?: string;
table: TableReqType; table: TableReqType;

Loading…
Cancel
Save