Browse Source

refactor: sharedBaseApi hander

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5239/head
Pranav C 2 years ago
parent
commit
afd73c02a0
  1. 1
      packages/nocodb/src/lib/services/index.ts
  2. 108
      packages/nocodb/src/lib/services/sharedBaseService.ts

1
packages/nocodb/src/lib/services/index.ts

@ -19,3 +19,4 @@ export * as viewColumnService from './viewColumnService';
export * as metaDiffService from './metaDiffService';
export * as mapViewService from './mapViewService';
export * as modelVisibilityService from './modelVisibilityService';
export * as sharedBaseService from './sharedBaseService';

108
packages/nocodb/src/lib/services/sharedBaseService.ts

@ -0,0 +1,108 @@
import { Tele } from 'nc-help';
import { v4 as uuidv4 } from 'uuid';
import Project from '../models/Project';
import { NcError } from '../meta/helpers/catchError';
// todo: load from config
const config = {
dashboardPath: '/nc',
};
export async function createSharedBaseLink(param:{
projectId: string;
roles: string;
password: string;
siteUrl: string;
}): Promise<any> {
const project = await Project.get(param.projectId);
let roles = param?.roles;
if (!roles || (roles !== 'editor' && roles !== 'viewer')) {
roles = 'viewer';
}
if (!project) {
NcError.badRequest('Invalid project id');
}
const data: any = {
uuid: uuidv4(),
password: param?.password,
roles,
};
await Project.update(project.id, data);
data.url = `${param.siteUrl}${config.dashboardPath}#/nc/base/${data.uuid}`;
delete data.password;
Tele.emit('evt', { evt_type: 'sharedBase:generated-link' });
return data;
}
export async function updateSharedBaseLink(param: {
projectId: string;
roles: string;
password: string;
siteUrl: string;
}): Promise<any> {
const project = await Project.get(param.projectId);
let roles = param.roles;
if (!roles || (roles !== 'editor' && roles !== 'viewer')) {
roles = 'viewer';
}
if (!project) {
NcError.badRequest('Invalid project id');
}
const data: any = {
uuid: project.uuid || uuidv4(),
password: param.password,
roles,
};
await Project.update(project.id, data);
data.url = `${param.siteUrl}${config.dashboardPath}#/nc/base/${data.uuid}`;
delete data.password;
Tele.emit('evt', { evt_type: 'sharedBase:generated-link' });
return data;
}
export async function disableSharedBaseLink(param:{
projectId: string;
}): Promise<any> {
const project = await Project.get(param.projectId);
if (!project) {
NcError.badRequest('Invalid project id');
}
const data: any = {
uuid: null,
};
await Project.update(project.id, data);
Tele.emit('evt', { evt_type: 'sharedBase:disable-link' });
return { uuid: null }
}
export async function getSharedBaseLink(param:{
projectId: string;
siteUrl: string;
}): Promise<any> {
const project = await Project.get(param.projectId);
if (!project) {
NcError.badRequest('Invalid project id');
}
const data: any = {
uuid: project.uuid,
roles: project.roles,
};
if (data.uuid)
data.url = `${param.siteUrl}${config.dashboardPath}#/nc/base/${data.shared_base_id}`;
return data;
}
Loading…
Cancel
Save