-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
DocManager.ts
82 lines (77 loc) · 2.42 KB
/
DocManager.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type { DocPayload, DocsService } from "@guildedjs/api";
import type { OptionBody } from "../../typings";
import { GlobalManager } from "./GlobalManager";
/**
* A manager class for Docs
*/
export class GlobalDocManager extends GlobalManager {
/**
* Create a new Doc.
*
* @param channelId - The ID of the channel where the Doc should be created.
* @param options - The options for the Doc to be created.
* @returns A Promise that resolves with the Doc payload of the newly created Doc.
*/
async create(channelId: string, options: OptionBody<DocsService["docCreate"]>): Promise<DocPayload> {
const data = await this.client.rest.router.docs.docCreate({
channelId,
requestBody: options,
});
return data.doc;
}
/**
* Fetches multiple Docs from a channel.
*
* @param channelId - The ID of the channel where the Docs are located.
* @returns A Promise that resolves with an array of Doc payloads.
*/
async fetchMany(channelId: string): Promise<DocPayload[]> {
const data = await this.client.rest.router.docs.docReadMany({
channelId,
});
return data.docs;
}
/**
* Fetch a Doc from a channel.
*
* @param channelId - The ID of the channel where the Doc is located.
* @param docId - The ID of the Doc to fetch.
* @returns A Promise that resolves with the Doc payload of the fetched Doc.
*/
async fetch(channelId: string, docId: number): Promise<DocPayload> {
const data = await this.client.rest.router.docs.docRead({
channelId,
docId,
});
return data.doc;
}
/**
* Update a Doc.
*
* @param channelId - The ID of the channel where the Doc is located.
* @param docId - The ID of the Doc to update.
* @param options - The options for the Doc update.
* @returns A Promise that resolves with the Doc payload of the updated Doc.
*/
async update(channelId: string, docId: number, options: OptionBody<DocsService["docUpdate"]>): Promise<DocPayload> {
const data = await this.client.rest.router.docs.docUpdate({
channelId,
docId,
requestBody: options,
});
return data.doc;
}
/**
* Delete a Doc from a channel.
*
* @param channelId - The ID of the channel where the Doc is located.
* @param docId - The ID of the Doc to delete.
* @returns A Promise that resolves with void when the Doc is successfully deleted.
*/
async delete(channelId: string, docId: number): Promise<void> {
await this.client.rest.router.docs.docDelete({
channelId,
docId,
});
}
}