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
import { ViewTypes } from 'nocodb-sdk'; |
|
import request from 'supertest'; |
|
import Model from '../../../src/models/Model'; |
|
import View from '../../../src/models/View'; |
|
|
|
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'); |
|
} |
|
}; |
|
|
|
const response = await request(context.app) |
|
.post(`/api/v1/db/meta/tables/${table.id}/${viewTypeStr(type)}`) |
|
.set('xc-auth', context.token) |
|
.send({ |
|
title, |
|
type, |
|
}); |
|
if(response.status !== 200) { |
|
throw new Error('createView',response.body.message); |
|
} |
|
|
|
const view = await View.getByTitleOrId({fk_model_id: table.id, titleOrId:title}) as View; |
|
|
|
return view |
|
} |
|
|
|
export {createView}
|
|
|