interface

This commit is contained in:
monoid 2021-01-15 20:20:55 +09:00
parent 90d329cfd8
commit dfc154b711
1 changed files with 22 additions and 4 deletions

View File

@ -15,6 +15,12 @@ export class FetchFailError implements Error{
}
}
export class ClientDocumentAccessor implements DocumentAccessor{
async findByPath(basepath: string, filename?: string): Promise<Document[]>{
throw new Error("not allowed");
};
async findDeleted(content_type: string): Promise<Document[]>{
throw new Error("not allowed");
};
async findList(option?: QueryListOption | undefined): Promise<Document[]>{
let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`);
if(res.status !== 200) throw new FetchFailError("findList Failed");
@ -38,7 +44,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}`,{
method: "POST",
body: JSON.stringify(rest)
body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
});
const ret = await res.json();
return ret;
@ -47,7 +56,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
throw new Error("not allow");
const res = await fetch(`${baseurl}`,{
method: "POST",
body: JSON.stringify(c)
body: JSON.stringify(c),
headers:{
'content-type':"application/json"
}
});
const ret = await res.json();
return ret;
@ -63,7 +75,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{
method: "POST",
body: JSON.stringify(rest)
body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
});
const ret = await res.json();
return ret;
@ -72,7 +87,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{
method: "DELETE",
body: JSON.stringify(rest)
body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
});
const ret = await res.json();
return ret;