Browse Source

wip(nocodb): KanbanView model

pull/3818/head
Wing-Kam Wong 2 years ago
parent
commit
8897b4f941
  1. 81
      packages/nocodb/src/lib/models/KanbanView.ts

81
packages/nocodb/src/lib/models/KanbanView.ts

@ -1,23 +1,92 @@
import Noco from '../Noco';
import { MetaTable } from '../utils/globals';
import { KanbanType } from 'nocodb-sdk';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import View from './View';
import NocoCache from '../cache/NocoCache';
import { isLeafType } from 'graphql';
export default class KanbanView {
export default class KanbanView implements KanbanType{
fk_view_id: string;
title: string;
project_id?: string;
base_id?: string;
// TODO: check these
show: boolean;
is_default: boolean;
order: number;
fk_view_id: string;
constructor(data: KanbanView) {
Object.assign(this, data);
}
public static async get(viewId: string, ncMeta = Noco.ncMeta) {
const view = await ncMeta.metaGet2(null, null, MetaTable.KANBAN_VIEW, {
fk_view_id: viewId,
});
let view =
viewId &&
(await NocoCache.get(
`${CacheScope.KANBAN_VIEW}:${viewId}`,
CacheGetType.TYPE_OBJECT
));
if (!view) {
view = await ncMeta.metaGet2(null, null, MetaTable.KANBAN_VIEW, {
fk_view_id: viewId,
});
await NocoCache.set(`${CacheScope.KANBAN_VIEW}:${viewId}`, view);
}
return view && new KanbanView(view);
}
static async insert(view: Partial<KanbanView>, ncMeta = Noco.ncMeta) {
const insertObj = {
project_id: view.project_id,
base_id: view.base_id,
fk_view_id: view.fk_view_id,
// TODO: more
};
if (!(view.project_id && view.base_id)) {
const viewRef = await View.get(view.fk_view_id);
insertObj.project_id = viewRef.project_id;
insertObj.base_id = viewRef.base_id;
}
await ncMeta.metaInsert2(
null,
null,
MetaTable.KANBAN_VIEW,
insertObj,
true
);
return this.get(view.fk_view_id, ncMeta);
}
static async update(
kanbanId: string,
body: Partial<KanbanView>,
ncMeta = Noco.ncMeta
) {
// get existing cache
const key = `${CacheScope.KANBAN_VIEW}:${kanbanId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = {
// TODO:
}
if (o) {
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(key, o);
}
// update meta
return await ncMeta.metaUpdate(
null,
null,
MetaTable.KANBAN_VIEW,
...updateObj,
{
fk_view_id: kanbanId,
}
);
}
}

Loading…
Cancel
Save