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.
39 lines
1.0 KiB
39 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/models/Model';
|
||
|
import View from '../../../src/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;
|
||
2 years ago
|
|
||
2 years ago
|
return view
|
||
|
}
|
||
|
|
||
2 years ago
|
export {createView}
|