Browse Source

feat(api): update form view and column models

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

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

@ -26,6 +26,7 @@ export default class FormView implements FormType {
project_id?: string;
base_id?: string;
meta?: string | Record<string, any>;
constructor(data: FormView) {
Object.assign(this, data);
@ -42,7 +43,13 @@ export default class FormView implements FormType {
view = await ncMeta.metaGet2(null, null, MetaTable.FORM_VIEW, {
fk_view_id: viewId,
});
await NocoCache.set(`${CacheScope.FORM_VIEW}:${viewId}`, view);
if (view) {
view.meta =
view.meta && typeof view.meta === 'string'
? JSON.parse(view.meta)
: view.meta;
await NocoCache.set(`${CacheScope.FORM_VIEW}:${viewId}`, view);
}
}
return view && new FormView(view);
}
@ -62,6 +69,10 @@ 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,
};
if (!(view.project_id && view.base_id)) {
const viewRef = await View.get(view.fk_view_id);

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

@ -18,6 +18,7 @@ export default class FormViewColumn implements FormColumnType {
fk_column_id?: string;
project_id?: string;
base_id?: string;
meta?: string | Record<string, any>;
constructor(data: FormViewColumn) {
Object.assign(this, data);
@ -25,28 +26,35 @@ export default class FormViewColumn implements FormColumnType {
uuid?: any;
public static async get(formViewId: string, ncMeta = Noco.ncMeta) {
let view =
formViewId &&
public static async get(formViewColumnId: string, ncMeta = Noco.ncMeta) {
let viewColumn =
formViewColumnId &&
(await NocoCache.get(
`${CacheScope.FORM_VIEW_COLUMN}:${formViewId}`,
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`,
CacheGetType.TYPE_OBJECT
));
if (!view) {
view = await ncMeta.metaGet2(
if (!viewColumn) {
viewColumn = await ncMeta.metaGet2(
null,
null,
MetaTable.FORM_VIEW_COLUMNS,
formViewId
formViewColumnId
);
viewColumn.meta =
viewColumn.meta && typeof viewColumn.meta === 'string'
? JSON.parse(viewColumn.meta)
: viewColumn.meta;
}
await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${formViewId}`, view);
await NocoCache.set(
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`,
viewColumn
);
return view && new FormViewColumn(view);
return viewColumn && new FormViewColumn(viewColumn);
}
static async insert(column: Partial<FormViewColumn>, ncMeta = Noco.ncMeta) {
const insertObj = {
const insertObj: Partial<FormViewColumn> = {
fk_view_id: column.fk_view_id,
fk_column_id: column.fk_column_id,
order: await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMNS, {
@ -61,6 +69,13 @@ 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.project_id && column.base_id)) {
const viewRef = await View.get(column.fk_view_id, ncMeta);
insertObj.project_id = viewRef.project_id;
@ -113,6 +128,14 @@ 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;
}
await NocoCache.setList(
CacheScope.FORM_VIEW_COLUMN,
[viewId],
@ -139,7 +162,16 @@ export default class FormViewColumn implements FormColumnType {
'required',
'show',
'order',
'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);

Loading…
Cancel
Save