From ae5ccfece9c323f3f86460c04561233f0909d660 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:18 +0000 Subject: [PATCH] feat: `CreateTime` or `LastModifiedTime` - update behaviour --- packages/nocodb-sdk/src/lib/UITypes.ts | 12 ++++++++++++ .../nocodb/src/services/columns.service.ts | 19 +++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/nocodb-sdk/src/lib/UITypes.ts b/packages/nocodb-sdk/src/lib/UITypes.ts index 80f45d87ae..f9bffcb6b6 100644 --- a/packages/nocodb-sdk/src/lib/UITypes.ts +++ b/packages/nocodb-sdk/src/lib/UITypes.ts @@ -86,6 +86,18 @@ export function isVirtualCol( // UITypes.Count, ].includes((typeof col === 'object' ? col?.uidt : col)); } +export function isCreatedTimeOrUpdatedTimeCol( + col: + | UITypes + | { readonly uidt: UITypes | string } + | ColumnReqType + | ColumnType +) { + return [ + UITypes.CreateTime, + UITypes.LastModifiedTime, + ].includes((typeof col === 'object' ? col?.uidt : col)); +} export function isLinksOrLTAR( colOrUidt: ColumnType | { uidt: UITypes | string } | UITypes | string diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 6264829b1f..0548d25c18 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -1,4 +1,11 @@ import { Injectable } from '@nestjs/common'; +import type { + ColumnReqType, + LinkToAnotherColumnReqType, + LinkToAnotherRecordType, + RelationTypes, + UserType, +} from 'nocodb-sdk'; import { AppEvents, isLinksOrLTAR, @@ -11,7 +18,7 @@ import { import { pluralize, singularize } from 'inflection'; import hash from 'object-hash'; import type SqlMgrv2 from '~/db/sql-mgr/v2/SqlMgrv2'; -import type { Base, LinkToAnotherRecordColumn } from '~/models'; +import type {Base, LinkToAnotherRecordColumn} from '~/models'; import type { ColumnReqType, LinkToAnotherColumnReqType, @@ -56,6 +63,7 @@ import Noco from '~/Noco'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import { MetaTable } from '~/utils/globals'; import { MetaService } from '~/meta/meta.service'; +import {isCreatedTimeOrUpdatedTimeCol} from "nocodb-sdk/build/main/lib/UITypes"; // todo: move export enum Altered { @@ -171,6 +179,7 @@ export class ColumnsService { if ( !isVirtualCol(param.column) && + !isCreatedTimeOrUpdatedTimeCol(param.column) && !(await Column.checkTitleAvailable({ column_name: param.column.column_name, fk_model_id: column.fk_model_id, @@ -195,6 +204,7 @@ export class ColumnsService { parsed_tree?: any; }; if ( + isCreatedTimeOrUpdatedTimeCol(column) || [ UITypes.Lookup, UITypes.Rollup, @@ -295,9 +305,10 @@ export class ColumnsService { } else if ( [UITypes.CreateTime, UITypes.LastModifiedTime].includes(colBody.uidt) ) { - // todo: correct this - const existingColumn = await table.getColumns().then((col) => { - return col.find((c) => c.uidt === colBody.uidt); + // allow updating of title only + await Column.update(param.columnId, { + ...column, + title: colBody.title, }); if (!existingColumn) {