This repository was archived by the owner on Jan 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathapi.js
58 lines (46 loc) · 1.51 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Client as Appwrite, Databases, Account, ID} from 'appwrite';
import { Server } from '../utils/config';
let api = {
sdk: null,
provider: () => {
if (api.sdk) {
return api.sdk;
}
let appwrite = new Appwrite();
appwrite.setEndpoint(Server.endpoint).setProject(Server.project);
const account = new Account(appwrite);
const database = new Databases(appwrite);
api.sdk = { database, account };
return api.sdk;
},
createAccount: (email, password, name) => {
return api.provider().account.create(ID.unique(), email, password, name);
},
getAccount: () => {
let account = api.provider().account;
return account.get();
},
createSession: (email, password) => {
return api.provider().account.createEmailSession(email, password);
},
deleteCurrentSession: () => {
return api.provider().account.deleteSession("current");
},
createDocument: (data, permissions) => {
return api
.provider()
.database.createDocument(Server.databaseID, Server.collectionID, 'unique()', data, permissions);
},
listDocuments: () => {
return api.provider().database.listDocuments(Server.databaseID, Server.collectionID);
},
updateDocument: (documentId, data) => {
return api
.provider()
.database.updateDocument(Server.databaseID, Server.collectionID, documentId, data);
},
deleteDocument: (documentId) => {
return api.provider().database.deleteDocument(Server.databaseID, Server.collectionID, documentId);
},
};
export default api;