Browse Source

refactor: avoid extracting columnList in table create and column create ( metadb project )

pull/7403/head
Pranav C 11 months ago
parent
commit
70ee378297
  1. 36
      packages/nocodb/src/services/columns.service.ts
  2. 40
      packages/nocodb/src/services/tables.service.ts

36
packages/nocodb/src/services/columns.service.ts

@ -2009,29 +2009,27 @@ export class ColumnsService {
);
await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody);
const columns: Array<
Omit<Column, 'column_name' | 'title'> & {
cn: string;
system?: boolean;
}
> = (
await sqlClient.columnList({
tn: table.table_name,
schema: source.getConfig()?.schema,
})
)?.data?.list;
if (!source.isMeta()) {
const columns: Array<
Omit<Column, 'column_name' | 'title'> & {
cn: string;
system?: boolean;
}
> = (
await sqlClient.columnList({
tn: table.table_name,
schema: source.getConfig()?.schema,
})
)?.data?.list;
const insertedColumnMeta =
columns.find((c) => c.cn === colBody.column_name) || ({} as any);
const insertedColumnMeta =
columns.find((c) => c.cn === colBody.column_name) || ({} as any);
Object.assign(colBody, insertedColumnMeta);
}
await Column.insert({
...colBody,
...insertedColumnMeta,
dtxp: [UITypes.MultiSelect, UITypes.SingleSelect].includes(
colBody.uidt as any,
)
? colBody.dtxp
: insertedColumnMeta.dtxp,
fk_model_id: table.id,
});
}

40
packages/nocodb/src/services/tables.service.ts

@ -380,7 +380,7 @@ export class TablesService {
validatePayload('swagger.json#/components/schemas/TableReq', param.table);
const tableCreatePayLoad: Omit<TableReqType, 'columns'> & {
columns: (Omit<ColumnType, 'column_name' | 'title'> & { cn?: string })[];
columns: (ColumnType & { cn?: string })[];
} = {
...param.table,
};
@ -603,18 +603,20 @@ export class TablesService {
tn: tableCreatePayLoad.table_name,
});
const columns: Array<
let columns: Array<
Omit<Column, 'column_name' | 'title'> & {
cn: string;
system?: boolean;
}
> = (
await sqlMgr.sqlOpPlus(source, 'columnList', {
tn: tableCreatePayLoad.table_name,
schema: source.getConfig()?.schema,
})
)?.data?.list;
>;
if (!source.isMeta()) {
columns = (
await sqlMgr.sqlOpPlus(source, 'columnList', {
tn: tableCreatePayLoad.table_name,
schema: source.getConfig()?.schema,
})
)?.data?.list;
}
const tables = await Model.list({
base_id: base.id,
source_id: source.id,
@ -625,21 +627,15 @@ export class TablesService {
// todo: type correction
const result = await Model.insert(base.id, source.id, {
...tableCreatePayLoad,
columns: columns.map((c, i) => {
const colMetaFromReq = param.table?.columns?.find(
(c1) => c.cn === c1.column_name,
);
columns: tableCreatePayLoad.columns.map((c, i) => {
const colMetaFromDb = columns?.find((c1) => c.cn === c1.cn);
return {
...colMetaFromReq,
uidt: colMetaFromReq?.uidt || c.uidt || getColumnUiType(source, c),
...c,
dtxp: [UITypes.MultiSelect, UITypes.SingleSelect].includes(
colMetaFromReq.uidt as any,
)
? colMetaFromReq.dtxp
: c.dtxp,
title: colMetaFromReq?.title || getColumnNameAlias(c.cn, source),
column_name: c.cn,
uidt: c.uidt || getColumnUiType(source, colMetaFromDb || c),
...(colMetaFromDb || {}),
dtxp: colMetaFromDb?.dtxp ?? c.dtxp,
title: c.title || getColumnNameAlias(c.cn, source),
column_name: colMetaFromDb?.cn || c.cn || c.column_name,
order: i + 1,
} as NormalColumnRequestType;
}),

Loading…
Cancel
Save