mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.0 KiB
38 lines
1.0 KiB
2 years ago
|
import { ViewTypes } from 'nocodb-sdk';
|
||
2 years ago
|
import request from 'supertest';
|
||
2 years ago
|
import Model from '../../../src/lib/models/Model';
|
||
|
import View from '../../../src/lib/models/View';
|
||
2 years ago
|
|
||
|
const createView = async (context, {title, table, type}: {title: string, table: Model, type: ViewTypes}) => {
|
||
|
const viewTypeStr = (type) => {
|
||
|
switch (type) {
|
||
|
case ViewTypes.GALLERY:
|
||
|
return 'galleries';
|
||
|
case ViewTypes.FORM:
|
||
|
return 'forms';
|
||
|
case ViewTypes.GRID:
|
||
|
return 'grids';
|
||
|
case ViewTypes.KANBAN:
|
||
|
return 'kanbans';
|
||
|
default:
|
||
|
throw new Error('Invalid view type');
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
const response = await request(context.app)
|
||
2 years ago
|
.post(`/api/v1/db/meta/tables/${table.id}/${viewTypeStr(type)}`)
|
||
|
.set('xc-auth', context.token)
|
||
|
.send({
|
||
|
title,
|
||
|
type,
|
||
|
});
|
||
2 years ago
|
if(response.status !== 200) {
|
||
|
throw new Error('createView',response.body.message);
|
||
|
}
|
||
2 years ago
|
|
||
|
const view = await View.getByTitleOrId({fk_model_id: table.id, titleOrId:title}) as View;
|
||
|
|
||
|
return view
|
||
|
}
|
||
|
|
||
|
export {createView}
|