Browse Source

feat: created/modified time - column creation - WIP

pull/7304/head
Pranav C 11 months ago
parent
commit
1df4b2c2f5
  1. 1
      packages/nocodb-sdk/src/lib/index.ts
  2. 16
      packages/nocodb/src/helpers/getColumnPropsFromUIDT.ts
  3. 9
      packages/nocodb/src/services/columns.service.ts

1
packages/nocodb-sdk/src/lib/index.ts

@ -13,6 +13,7 @@ export {
isNumericCol,
isVirtualCol,
isLinksOrLTAR,
isCreatedTimeOrUpdatedTimeCol,
} from '~/lib/UITypes';
export { default as CustomAPI, FileType } from '~/lib/CustomAPI';
export { default as TemplateGenerator } from '~/lib/TemplateGenerator';

16
packages/nocodb/src/helpers/getColumnPropsFromUIDT.ts

@ -23,12 +23,6 @@ export default async function getColumnPropsFromUIDT(
...colProp,
};
if (newColumn.uidt === UITypes.CreateTime) {
newColumn.column_name = 'created_at';
} else if (newColumn.uidt === UITypes.LastModifiedTime) {
newColumn.column_name = 'updated_at';
}
newColumn.dtxp = sqlUi.getDefaultLengthForDatatype(newColumn.dt);
newColumn.dtxs = sqlUi.getDefaultScaleForDatatype(newColumn.dt);
@ -43,5 +37,13 @@ export default async function getColumnPropsFromUIDT(
newColumn.altered = column.altered || 2;
return { ...newColumn, ...column };
const finalColumnMeta = { ...newColumn, ...column };
if (finalColumnMeta.uidt === UITypes.CreateTime) {
finalColumnMeta.column_name = 'created_at';
} else if (finalColumnMeta.uidt === UITypes.LastModifiedTime) {
finalColumnMeta.column_name = 'updated_at';
}
return finalColumnMeta;
}

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

@ -8,6 +8,7 @@ import type {
} from 'nocodb-sdk';
import {
AppEvents,
isCreatedTimeOrUpdatedTimeCol,
isLinksOrLTAR,
isVirtualCol,
substituteColumnAliasWithIdInFormula,
@ -17,7 +18,6 @@ import {
} from 'nocodb-sdk';
import { pluralize, singularize } from 'inflection';
import hash from 'object-hash';
import { isCreatedTimeOrUpdatedTimeCol } from 'nocodb-sdk/build/main/lib/UITypes';
import type {
ColumnReqType,
LinkToAnotherColumnReqType,
@ -1734,7 +1734,12 @@ export class ColumnsService {
// check if column already exists, then just create a new column in meta
// else create a new column in meta and db
const existingColumn = await table.getColumns().then((col) => {
return col.find((c) => c.uidt === colBody.uidt);
return col.find(
(c) =>
c.uidt === colBody.uidt ||
c.column_name ===
(c.uidt === UITypes.CreateTime ? 'created_at' : 'updated_at'),
);
});
if (!existingColumn) {

Loading…
Cancel
Save