Browse Source

feat: `CreateTime` or `LastModifiedTime` - update behaviour

pull/7304/head
Pranav C 11 months ago
parent
commit
ae5ccfece9
  1. 12
      packages/nocodb-sdk/src/lib/UITypes.ts
  2. 17
      packages/nocodb/src/services/columns.service.ts

12
packages/nocodb-sdk/src/lib/UITypes.ts

@ -86,6 +86,18 @@ export function isVirtualCol(
// UITypes.Count, // UITypes.Count,
].includes(<UITypes>(typeof col === 'object' ? col?.uidt : col)); ].includes(<UITypes>(typeof col === 'object' ? col?.uidt : col));
} }
export function isCreatedTimeOrUpdatedTimeCol(
col:
| UITypes
| { readonly uidt: UITypes | string }
| ColumnReqType
| ColumnType
) {
return [
UITypes.CreateTime,
UITypes.LastModifiedTime,
].includes(<UITypes>(typeof col === 'object' ? col?.uidt : col));
}
export function isLinksOrLTAR( export function isLinksOrLTAR(
colOrUidt: ColumnType | { uidt: UITypes | string } | UITypes | string colOrUidt: ColumnType | { uidt: UITypes | string } | UITypes | string

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

@ -1,4 +1,11 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import type {
ColumnReqType,
LinkToAnotherColumnReqType,
LinkToAnotherRecordType,
RelationTypes,
UserType,
} from 'nocodb-sdk';
import { import {
AppEvents, AppEvents,
isLinksOrLTAR, isLinksOrLTAR,
@ -56,6 +63,7 @@ import Noco from '~/Noco';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2'; import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import { MetaService } from '~/meta/meta.service'; import { MetaService } from '~/meta/meta.service';
import {isCreatedTimeOrUpdatedTimeCol} from "nocodb-sdk/build/main/lib/UITypes";
// todo: move // todo: move
export enum Altered { export enum Altered {
@ -171,6 +179,7 @@ export class ColumnsService {
if ( if (
!isVirtualCol(param.column) && !isVirtualCol(param.column) &&
!isCreatedTimeOrUpdatedTimeCol(param.column) &&
!(await Column.checkTitleAvailable({ !(await Column.checkTitleAvailable({
column_name: param.column.column_name, column_name: param.column.column_name,
fk_model_id: column.fk_model_id, fk_model_id: column.fk_model_id,
@ -195,6 +204,7 @@ export class ColumnsService {
parsed_tree?: any; parsed_tree?: any;
}; };
if ( if (
isCreatedTimeOrUpdatedTimeCol(column) ||
[ [
UITypes.Lookup, UITypes.Lookup,
UITypes.Rollup, UITypes.Rollup,
@ -295,9 +305,10 @@ export class ColumnsService {
} else if ( } else if (
[UITypes.CreateTime, UITypes.LastModifiedTime].includes(colBody.uidt) [UITypes.CreateTime, UITypes.LastModifiedTime].includes(colBody.uidt)
) { ) {
// todo: correct this // allow updating of title only
const existingColumn = await table.getColumns().then((col) => { await Column.update(param.columnId, {
return col.find((c) => c.uidt === colBody.uidt); ...column,
title: colBody.title,
}); });
if (!existingColumn) { if (!existingColumn) {

Loading…
Cancel
Save