From f114b4de15f9ec5a7e01cebb851df90821614e33 Mon Sep 17 00:00:00 2001 From: Daniel Spaude Date: Fri, 25 Nov 2022 00:23:44 +0300 Subject: [PATCH] qr code: delete qr code if referenced columns type change to non supported one --- packages/nocodb/src/lib/models/Column.ts | 37 ++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/lib/models/Column.ts b/packages/nocodb/src/lib/models/Column.ts index e9e07b75a9..7b467efb9b 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -573,12 +573,14 @@ export default class Column implements ColumnType { // get qr code columns and delete { - let qrCodeCols = await NocoCache.getList(CacheScope.COL_QRCODE, [id]); - if (!qrCodeCols.length) { - qrCodeCols = await ncMeta.metaList2(null, null, MetaTable.COL_QRCODE, { + const qrCodeCols = await ncMeta.metaList2( + null, + null, + MetaTable.COL_QRCODE, + { condition: { fk_qr_value_column_id: id }, - }); - } + } + ); for (const qrCodeCol of qrCodeCols) { await Column.delete(qrCodeCol.fk_column_id, ncMeta); } @@ -947,6 +949,31 @@ export default class Column implements ColumnType { else updateObj.validate = JSON.stringify(column.validate); } + // get qr code columns and delete if target type is not supported by QR code column type + // TODO: consider to extraxt the list of allowedColumnTypesForQrValue into a global one, + // ideally in sdk sine it's also used in FE + const allowedColumnTypesForQrValue = [ + UITypes.Formula, + UITypes.SingleLineText, + UITypes.LongText, + UITypes.PhoneNumber, + UITypes.URL, + UITypes.Email, + ]; + if (!allowedColumnTypesForQrValue.includes(updateObj.uidt)) { + const qrCodeCols = await ncMeta.metaList2( + null, + null, + MetaTable.COL_QRCODE, + { + condition: { fk_qr_value_column_id: colId }, + } + ); + for (const qrCodeCol of qrCodeCols) { + await Column.delete(qrCodeCol.fk_column_id, ncMeta); + } + } + // get existing cache const key = `${CacheScope.COLUMN}:${colId}`; let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);