Skip to content

Commit

Permalink
Merge pull request #15 from seatable/add-new-callings
Browse files Browse the repository at this point in the history
Add new callings
  • Loading branch information
freeplant authored Jan 12, 2024
2 parents eba1e85 + 704fc9a commit 69ab3f8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

# lib
/lib

/.idea
75 changes: 71 additions & 4 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,20 @@ class Base {
}

getDTable() {
const url = `dtables/${this.dtableUuid}/?lang=${this.lang}`;
const url = `/dtables/${this.dtableUuid}/?lang=${this.lang}`;
return this.req.get(url);
}

async getTables() {
const res = await this.getMetadata();
return res ? res.tables : [];
}

async getTableByName(table_name) {
const res = await this.getTables();
return res.find(table=> table.name === table_name);
}

getMetadata() {
const url = `/api/v1/dtables/${this.dtableUuid}/metadata/`;
return this.req.get(url);
Expand All @@ -89,6 +99,24 @@ class Base {
return this.req.post(url, {...data});
}

renameTable(old_name, new_name) {
const url = `/api/v1/dtables/${this.dtableUuid}/tables/`;
const data = {
table_name: old_name,
new_table_name: new_name
}
return this.req.put(url, {...data});
}

deleteTable(table_name) {
const url = `/api/v1/dtables/${this.dtableUuid}/tables/`;
const data = {
table_name: table_name,
}
return this.req.delete(url, {data:data});

}

listViews(table_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/`;
const params = {
Expand All @@ -97,6 +125,34 @@ class Base {
return this.req.get(url, {params});
}

getViewByName(table_name, view_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/${view_name}/?table_name=` + table_name;
return this.req.get(url)
}

addView(table_name, view_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/?table_name=` + table_name;
const data = {
name: view_name
};
return this.req.post(url, {...data});
}

renameView(table_name, view_name, new_view_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/${view_name}/?table_name=` + table_name;
const data = {
name: new_view_name,
}
return this.req.put(url, {...data});

}

deleteView(table_name, view_name) {
const url = `api/v1/dtables/${this.dtableUuid}/views/${view_name}/?table_name=` + table_name;
return this.req.delete(url);

}

listColumns(table_name, view_name) {
const url = `api/v1/dtables/${this.dtableUuid}/columns/`;
const params = {
Expand All @@ -106,6 +162,16 @@ class Base {
return this.req.get(url, {params});
}

async getColumnByName(table_name, column_name) {
const res = await this.listColumns(table_name);
return res.find(col=> col.name === column_name);
}

async getColumnsByType(table_name, column_type) {
const res = await this.listColumns(table_name);
return res.filter(col=> col.type === column_type);
}

insertColumn(table_name, column_name, column_type, column_key, column_data) {
const url = `api/v1/dtables/${this.dtableUuid}/columns/`;
const data = {
Expand Down Expand Up @@ -314,8 +380,8 @@ class Base {
const url = `api/v1/dtables/${this.dtableUuid}/links/`;
const data = {
link_id: link_id,
table_id: table_id,
other_table_id: other_table_id,
table_name: table_id,
other_table_name: other_table_id,
row_id: row_id,
other_rows_ids: other_rows_ids,
};
Expand Down Expand Up @@ -346,7 +412,8 @@ class Base {
return this.req.put(url, {...data});
}

getColumnLinkId(columns, column_name) {
async getColumnLinkId(table_name, column_name) {
const columns = await this.listColumns(table_name);
const column = columns.find(column => column.name === column_name);
if (!column) {
return Promise.reject({error_message: 'column is not exist',});
Expand Down

0 comments on commit 69ab3f8

Please sign in to comment.