feat: add base
This commit is contained in:
parent
788c7f670a
commit
4ef857ec0b
@ -41,7 +41,6 @@ export class Query {
|
||||
if (options.data) {
|
||||
fetchOptions.body = JSON.stringify(options.data);
|
||||
}
|
||||
console.log(url.href, fetchOptions);
|
||||
return fetch(url.href, fetchOptions).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
return { code: response.status, message: response.statusText };
|
||||
|
20
src/base.ts
20
src/base.ts
@ -1,6 +1,6 @@
|
||||
import { Query } from './api.ts';
|
||||
|
||||
type NocoApiOptions = {
|
||||
export type NocoApiOptions = {
|
||||
table?: string;
|
||||
token?: string;
|
||||
baseURL?: string;
|
||||
@ -73,13 +73,13 @@ class Record {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
update(data: { id: Id; [key: string]: any }) {
|
||||
update(data: { Id?: Id; [key: string]: any }) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
|
||||
method: 'PATCH',
|
||||
data,
|
||||
});
|
||||
}
|
||||
delete(data: { id: Id }) {
|
||||
delete(data: { Id?: Id }) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/records`, {
|
||||
method: 'DELETE',
|
||||
data,
|
||||
@ -90,25 +90,27 @@ class Record {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
listLinks(linkFieldId: Id, id: Id) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
|
||||
listLinks(linkFieldId: Id, Id: Id) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
}
|
||||
updateLinks(linkFieldId: Id, id: Id, data: any) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
|
||||
updateLinks(linkFieldId: Id, Id: Id, data: any) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
|
||||
method: 'POST',
|
||||
data,
|
||||
});
|
||||
}
|
||||
deleteLinks(linkFieldId: Id, id: Id) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${id}`, {
|
||||
deleteLinks(linkFieldId: Id, Id: Id) {
|
||||
return this.query.makeRequest(`/api/v2/tables/${this.table}/links/${linkFieldId}/records/${Id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @url https://nocodb.com/apis/v2/meta
|
||||
*/
|
||||
class Meta {
|
||||
|
Loading…
x
Reference in New Issue
Block a user