Browse Source

refactor(api): reuse serialize/deserialize function

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3683/head
Pranav C 2 years ago
parent
commit
c988af541a
  1. 13
      packages/nocodb/src/lib/models/FormView.ts
  2. 25
      packages/nocodb/src/lib/models/FormViewColumn.ts

13
packages/nocodb/src/lib/models/FormView.ts

@ -1,6 +1,7 @@
import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import { FormType } from 'nocodb-sdk';
import { deserializeJSON, serializeJSON } from '../utils/searialize';
import FormViewColumn from './FormViewColumn';
import View from './View';
import NocoCache from '../cache/NocoCache';
@ -44,10 +45,7 @@ export default class FormView implements FormType {
fk_view_id: viewId,
});
if (view) {
view.meta =
view.meta && typeof view.meta === 'string'
? JSON.parse(view.meta)
: view.meta;
view.meta = deserializeJSON(view.meta);
await NocoCache.set(`${CacheScope.FORM_VIEW}:${viewId}`, view);
}
}
@ -69,10 +67,7 @@ export default class FormView implements FormType {
logo_url: view.logo_url,
submit_another_form: view.submit_another_form,
show_blank_form: view.show_blank_form,
meta:
view.meta && typeof view.meta === 'object'
? JSON.stringify(view.meta)
: view.meta,
meta: serializeJSON(view.meta),
};
if (!(view.project_id && view.base_id)) {
const viewRef = await View.get(view.fk_view_id);
@ -103,8 +98,10 @@ export default class FormView implements FormType {
o.logo_url = body.logo_url;
o.submit_another_form = body.submit_another_form;
o.show_blank_form = body.show_blank_form;
o.meta = body.meta;
// set cache
await NocoCache.set(key, o);
o.meta = serializeJSON(body.meta);
}
// update meta
return await ncMeta.metaUpdate(

25
packages/nocodb/src/lib/models/FormViewColumn.ts

@ -1,6 +1,7 @@
import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import { FormColumnType } from 'nocodb-sdk';
import { deserializeJSON, serializeJSON } from '../utils/searialize';
import View from './View';
import NocoCache from '../cache/NocoCache';
import { extractProps } from '../meta/helpers/extractProps';
@ -69,11 +70,8 @@ export default class FormViewColumn implements FormColumnType {
required: column.required,
};
if (insertObj.meta) {
insertObj.meta =
typeof insertObj.meta === 'object'
? JSON.stringify(insertObj.meta)
: insertObj.meta;
if (column.meta) {
insertObj.meta = serializeJSON(column.meta);
}
if (!(column.project_id && column.base_id)) {
@ -130,10 +128,7 @@ export default class FormViewColumn implements FormColumnType {
);
for (const viewColumn of viewColumns) {
viewColumn.meta =
viewColumn.meta && typeof viewColumn.meta === 'string'
? JSON.parse(viewColumn.meta)
: viewColumn.meta;
viewColumn.meta = deserializeJSON(viewColumn.meta);
}
await NocoCache.setList(
@ -165,13 +160,6 @@ export default class FormViewColumn implements FormColumnType {
'meta',
]);
if (insertObj.meta) {
insertObj.meta =
insertObj.meta && typeof insertObj.meta === 'object'
? JSON.stringify(insertObj.meta)
: insertObj.meta;
}
// get existing cache
const key = `${CacheScope.FORM_VIEW_COLUMN}:${columnId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
@ -180,6 +168,11 @@ export default class FormViewColumn implements FormColumnType {
// set cache
await NocoCache.set(key, o);
}
if (insertObj.meta) {
insertObj.meta = serializeJSON(insertObj.meta);
}
// update meta
await ncMeta.metaUpdate(
null,

Loading…
Cancel
Save