@foru-ms/sdk 1.2.7 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -552,6 +552,9 @@ We welcome contributions! Please see our contributing guidelines for more inform
|
|
|
552
552
|
|
|
553
553
|
## Changelog
|
|
554
554
|
|
|
555
|
+
### v1.2.8
|
|
556
|
+
- Added Poll resource for poll management
|
|
557
|
+
|
|
555
558
|
### v1.2.7
|
|
556
559
|
- Fixed issue with optional parameters not being optional in typescript
|
|
557
560
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
2
|
import { ThreadListResponse, ThreadFilter, InteractionType } from '../types';
|
|
3
|
+
import { PollResults } from '../response-types';
|
|
3
4
|
export declare class ThreadsResource {
|
|
4
5
|
private client;
|
|
5
6
|
constructor(client: ForumClient);
|
|
@@ -57,6 +58,7 @@ export declare class ThreadsResource {
|
|
|
57
58
|
limit?: number;
|
|
58
59
|
}): Promise<any>;
|
|
59
60
|
getPoll(threadId: string, userId?: string): Promise<any>;
|
|
61
|
+
getPollResults(threadId: string, userId?: string): Promise<PollResults>;
|
|
60
62
|
vote(id: string, optionId: string, userId?: string): Promise<any>;
|
|
61
63
|
voteUpdate(id: string, optionId: string, userId?: string): Promise<any>;
|
|
62
64
|
unvote(id: string, userId?: string): Promise<any>;
|
|
@@ -175,6 +175,14 @@ class ThreadsResource {
|
|
|
175
175
|
const query = searchParams.toString();
|
|
176
176
|
return this.client.request(`/thread/${threadId}/poll${query ? `?${query}` : ''}`, { method: 'GET' });
|
|
177
177
|
}
|
|
178
|
+
async getPollResults(threadId, userId) {
|
|
179
|
+
const searchParams = new URLSearchParams();
|
|
180
|
+
if (userId) {
|
|
181
|
+
searchParams.append('userId', userId);
|
|
182
|
+
}
|
|
183
|
+
const query = searchParams.toString();
|
|
184
|
+
return this.client.request(`/thread/${threadId}/poll/results${query ? `?${query}` : ''}`, { method: 'GET' });
|
|
185
|
+
}
|
|
178
186
|
async vote(id, optionId, userId) {
|
|
179
187
|
return this.client.request(`/thread/${id}/poll/votes`, {
|
|
180
188
|
method: 'POST',
|
package/dist/response-types.d.ts
CHANGED
|
@@ -78,6 +78,28 @@ export interface PollOption {
|
|
|
78
78
|
/** Extended data */
|
|
79
79
|
extendedData?: Record<string, any>;
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Simplified poll option for results
|
|
83
|
+
*/
|
|
84
|
+
export interface PollOptionResult {
|
|
85
|
+
/** The ID of the poll option */
|
|
86
|
+
id: string;
|
|
87
|
+
/** The title of the poll option */
|
|
88
|
+
title: string;
|
|
89
|
+
/** The color of the poll option */
|
|
90
|
+
color?: string;
|
|
91
|
+
/** The number of votes this option received */
|
|
92
|
+
votes: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Poll results data
|
|
96
|
+
*/
|
|
97
|
+
export interface PollResults {
|
|
98
|
+
/** List of poll options with results */
|
|
99
|
+
options: PollOptionResult[];
|
|
100
|
+
/** The option ID that the user voted for, or null if they haven't voted */
|
|
101
|
+
userVote?: string | null;
|
|
102
|
+
}
|
|
81
103
|
/**
|
|
82
104
|
* Response for batch operations
|
|
83
105
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import { ForumClient } from '@foru-ms/sdk';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -70,8 +71,12 @@ async function main() {
|
|
|
70
71
|
await client.threads.vote(pollThread.id, 'option-id-1', userId);
|
|
71
72
|
console.log('Vote cast');
|
|
72
73
|
|
|
74
|
+
// Get poll
|
|
75
|
+
const poll = await client.threads.getPoll(pollThread.id, userId);
|
|
76
|
+
console.log('Poll:', poll);
|
|
77
|
+
|
|
73
78
|
// Get poll results
|
|
74
|
-
const pollResults = await client.threads.
|
|
79
|
+
const pollResults = await client.threads.getPollResults(pollThread.id, userId);
|
|
75
80
|
console.log('Poll results:', pollResults);
|
|
76
81
|
|
|
77
82
|
// Example 7: Add Posts to Thread
|
package/package.json
CHANGED
package/src/resources/Threads.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ForumClient } from '../Client';
|
|
2
2
|
import { ThreadListResponse, ThreadFilter, InteractionType } from '../types';
|
|
3
|
+
import { PollResults } from '../response-types';
|
|
3
4
|
|
|
4
5
|
export class ThreadsResource {
|
|
5
6
|
private client: ForumClient;
|
|
@@ -232,6 +233,19 @@ export class ThreadsResource {
|
|
|
232
233
|
);
|
|
233
234
|
}
|
|
234
235
|
|
|
236
|
+
async getPollResults(threadId: string, userId?: string): Promise<PollResults> {
|
|
237
|
+
const searchParams = new URLSearchParams();
|
|
238
|
+
if (userId) {
|
|
239
|
+
searchParams.append('userId', userId);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const query = searchParams.toString();
|
|
243
|
+
return this.client.request<PollResults>(
|
|
244
|
+
`/thread/${threadId}/poll/results${query ? `?${query}` : ''}`,
|
|
245
|
+
{ method: 'GET' }
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
235
249
|
async vote(id: string, optionId: string, userId?: string): Promise<any> {
|
|
236
250
|
return this.client.request(`/thread/${id}/poll/votes`, {
|
|
237
251
|
method: 'POST',
|
package/src/response-types.ts
CHANGED
|
@@ -85,6 +85,30 @@ export interface PollOption {
|
|
|
85
85
|
extendedData?: Record<string, any>;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Simplified poll option for results
|
|
90
|
+
*/
|
|
91
|
+
export interface PollOptionResult {
|
|
92
|
+
/** The ID of the poll option */
|
|
93
|
+
id: string;
|
|
94
|
+
/** The title of the poll option */
|
|
95
|
+
title: string;
|
|
96
|
+
/** The color of the poll option */
|
|
97
|
+
color?: string;
|
|
98
|
+
/** The number of votes this option received */
|
|
99
|
+
votes: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Poll results data
|
|
104
|
+
*/
|
|
105
|
+
export interface PollResults {
|
|
106
|
+
/** List of poll options with results */
|
|
107
|
+
options: PollOptionResult[];
|
|
108
|
+
/** The option ID that the user voted for, or null if they haven't voted */
|
|
109
|
+
userVote?: string | null;
|
|
110
|
+
}
|
|
111
|
+
|
|
88
112
|
/**
|
|
89
113
|
* Response for batch operations
|
|
90
114
|
*/
|