Browse Source

qr code: delete qr code if referenced columns type change to non supported one

pr-4468-qr-code-extraction
Daniel Spaude 2 years ago
parent
commit
f114b4de15
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 37
      packages/nocodb/src/lib/models/Column.ts

37
packages/nocodb/src/lib/models/Column.ts

@ -573,12 +573,14 @@ export default class Column<T = any> 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<T = any> 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);

Loading…
Cancel
Save