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.
43 lines
1.2 KiB
43 lines
1.2 KiB
2 years ago
|
import request from 'supertest';
|
||
2 years ago
|
import Model from '../../../src/lib/models/Model';
|
||
|
import Project from '../../../src/lib/models/Project';
|
||
2 years ago
|
import { defaultColumns } from './column';
|
||
|
|
||
2 years ago
|
const defaultTableValue = (context) => ({
|
||
2 years ago
|
table_name: 'Table1',
|
||
2 years ago
|
title: 'Table1_Title',
|
||
2 years ago
|
columns: defaultColumns(context),
|
||
|
});
|
||
2 years ago
|
|
||
2 years ago
|
const createTable = async (context, project, args = {}) => {
|
||
2 years ago
|
const defaultValue = defaultTableValue(context);
|
||
2 years ago
|
const response = await request(context.app)
|
||
2 years ago
|
.post(`/api/v1/db/meta/projects/${project.id}/tables`)
|
||
2 years ago
|
.set('xc-auth', context.token)
|
||
2 years ago
|
.send({ ...defaultValue, ...args });
|
||
2 years ago
|
|
||
2 years ago
|
const table: Model = await Model.get(response.body.id);
|
||
2 years ago
|
return table;
|
||
|
};
|
||
|
|
||
2 years ago
|
const getTable = async ({project, name}: {project: Project, name: string}) => {
|
||
|
const bases = await project.getBases();
|
||
2 years ago
|
return await Model.getByIdOrName({
|
||
|
project_id: project.id,
|
||
2 years ago
|
base_id: bases[0].id!,
|
||
2 years ago
|
table_name: name,
|
||
|
});
|
||
|
}
|
||
|
|
||
2 years ago
|
const getAllTables = async ({project}: {project: Project}) => {
|
||
|
const bases = await project.getBases();
|
||
|
const tables = await Model.list({
|
||
|
project_id: project.id,
|
||
|
base_id: bases[0].id!,
|
||
|
});
|
||
|
|
||
|
return tables;
|
||
|
}
|
||
|
|
||
|
export { createTable, getTable, getAllTables };
|