Skip to content

Commit ba248cd

Browse files
authored
Fix: Remove data property from spammer and participation plugin response object (#103)
1 parent e2bdd8e commit ba248cd

File tree

7 files changed

+68
-77
lines changed

7 files changed

+68
-77
lines changed

src/app/components/plugins/Participation.tsx

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -413,21 +413,16 @@ class Participation extends AsyncComponent<unknown, ParticipationState> {
413413
*/
414414
private async fetchEvents(): Promise<void> {
415415
try {
416-
const response = await FetchHelper.json<unknown, {
417-
data?: IParticipationEvents;
418-
error?: {
419-
message: string;
420-
};
421-
}>(
416+
const response = await FetchHelper.json<unknown, IParticipationEvents>(
422417
`${window.location.protocol}//${window.location.host}`,
423418
"/api/plugins/participation/v1/events",
424419
"get",
425420
undefined,
426421
Participation.buildAuthHeaders());
427422

428-
if (response?.data?.eventIds) {
423+
if (response?.eventIds) {
429424
this.setState({
430-
eventIds: response.data.eventIds
425+
eventIds: response.eventIds
431426
});
432427
} else {
433428
console.log(response.error);
@@ -443,23 +438,18 @@ class Participation extends AsyncComponent<unknown, ParticipationState> {
443438
*/
444439
private async fetchEventInfo(id: string): Promise<void> {
445440
try {
446-
const response = await FetchHelper.json<unknown, {
447-
data?: IParticipationEventInfo;
448-
error?: {
449-
message: string;
450-
};
451-
}>(
441+
const response = await FetchHelper.json<unknown, IParticipationEventInfo>(
452442
`${window.location.protocol}//${window.location.host}`,
453443
`/api/plugins/participation/v1/events/${id}`,
454444
"get",
455445
undefined,
456446
Participation.buildAuthHeaders());
457447

458-
if (response.data) {
448+
if (!response?.error) {
459449
this.setState(prevState => ({
460450
events: {
461451
...prevState.events,
462-
[id]: response.data as IParticipationEventInfo
452+
[id]: response
463453
}
464454
}));
465455
} else {
@@ -476,27 +466,22 @@ class Participation extends AsyncComponent<unknown, ParticipationState> {
476466
*/
477467
private async fetchEventStatus(id: string): Promise<void> {
478468
try {
479-
const response = await FetchHelper.json<unknown, {
480-
data?: IParticipationEventStatus;
481-
error?: {
482-
message: string;
483-
};
484-
}>(
469+
const response = await FetchHelper.json<unknown, IParticipationEventStatus>(
485470
`${window.location.protocol}//${window.location.host}`,
486471
`/api/plugins/participation/v1/events/${id}/status`,
487472
"get",
488473
undefined,
489474
Participation.buildAuthHeaders());
490475

491-
if (response.data) {
476+
if (!response?.error) {
492477
if (this.state.events[id]) {
493478
this.setState(prevState => ({
494479
...prevState,
495480
events: {
496481
...prevState.events,
497482
[id]: {
498483
...prevState.events[id],
499-
status: response.data
484+
status: response
500485
}
501486
}
502487
}));
@@ -546,20 +531,15 @@ class Participation extends AsyncComponent<unknown, ParticipationState> {
546531
dialogStatus: "Adding event, please wait..."
547532
}, async () => {
548533
try {
549-
const response = await FetchHelper.json<unknown, {
550-
data?: IParticipationEvent;
551-
error?: {
552-
message: string;
553-
};
554-
}>(
534+
const response = await FetchHelper.json<unknown, IParticipationEvent>(
555535
`${window.location.protocol}//${window.location.host}`,
556536
"/api/plugins/participation/v1/admin/events",
557537
"post",
558538
eventInfo,
559539
Participation.buildAuthHeaders());
560540

561-
if (response.data) {
562-
const id = response.data.eventId;
541+
if (response.eventId) {
542+
const id = response.eventId;
563543
this.setState(prevState => ({
564544
eventIds: [
565545
id,
@@ -640,30 +620,20 @@ class Participation extends AsyncComponent<unknown, ParticipationState> {
640620
*/
641621
private async fetchEventJsonConfig(url: URL): Promise<IParticipationEventInfo | undefined> {
642622
try {
643-
const response = await FetchHelper.json<unknown, {
644-
data?: IParticipationEventInfo;
645-
error?: {
646-
message: string;
647-
};
648-
}>(
623+
const response = await FetchHelper.json<unknown, IParticipationEventInfo>(
649624
url.origin,
650625
url.pathname,
651626
"get");
652627

653-
return (response.data) ? response.data : response as IParticipationEventInfo;
628+
return response;
654629
} catch {
655630
try {
656-
const response = await FetchHelper.text<unknown, {
657-
data?: IParticipationEventInfo;
658-
error?: {
659-
message: string;
660-
};
661-
}>(
631+
const response = await FetchHelper.text<unknown, IParticipationEventInfo>(
662632
url.origin,
663633
url.pathname,
664634
"get");
665635

666-
return (response.data) ? response.data : response as IParticipationEventInfo;
636+
return response;
667637
} catch (error) {
668638
if (error instanceof Error) {
669639
this.setState({

src/app/components/plugins/Spammer.tsx

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,24 @@ class Spammer extends AsyncComponent<unknown, SpammerState> {
191191
*/
192192
private async pluginStatus(): Promise<void> {
193193
try {
194-
const response = await FetchHelper.json<unknown, {
195-
data?: ISpammerSettings;
196-
error?: {
197-
message: string;
198-
};
199-
}>(
200-
`${window.location.protocol}//${window.location.host}`,
201-
"/api/plugins/spammer/v1/status",
202-
"get",
203-
undefined,
204-
Spammer.buildAuthHeaders());
194+
const response = await FetchHelper.json<unknown, ISpammerSettings>(
195+
`${window.location.protocol}//${window.location.host}`,
196+
"/api/plugins/spammer/v1/status",
197+
"get",
198+
undefined,
199+
Spammer.buildAuthHeaders()
200+
);
205201

206-
if (response.data) {
202+
if (!response?.error) {
207203
this.setState({
208-
isRunning: response.data.running,
209-
bps: response.data.bpsRateLimit.toString(),
210-
cpu: (response.data.cpuMaxUsage * 100).toString(),
211-
workers: response.data.spammerWorkers.toString(),
212-
workersMax: response.data.spammerWorkersMax
204+
isRunning: response.running,
205+
bps: response.bpsRateLimit.toString(),
206+
cpu: (response.cpuMaxUsage * 100).toString(),
207+
workers: response.spammerWorkers.toString(),
208+
workersMax: response.spammerWorkersMax
213209
});
214210
} else {
215-
console.log(response.error);
211+
console.log("loging eror", response.error);
216212
}
217213
} catch (err) {
218214
console.log(err);
@@ -248,12 +244,7 @@ class Spammer extends AsyncComponent<unknown, SpammerState> {
248244
*/
249245
private async pluginStart(): Promise<void> {
250246
try {
251-
await FetchHelper.json<unknown, {
252-
data?: ISpammerSettings;
253-
error?: {
254-
message: string;
255-
};
256-
}>(
247+
await FetchHelper.json<unknown, ISpammerSettings>(
257248
`${window.location.protocol}//${window.location.host}`,
258249
"/api/plugins/spammer/v1/start",
259250
"post",
@@ -275,12 +266,7 @@ class Spammer extends AsyncComponent<unknown, SpammerState> {
275266
*/
276267
private async pluginStop(): Promise<void> {
277268
try {
278-
await FetchHelper.json<unknown, {
279-
data?: ISpammerSettings;
280-
error?: {
281-
message: string;
282-
};
283-
}>(
269+
await FetchHelper.json<unknown, ISpammerSettings>(
284270
`${window.location.protocol}//${window.location.host}`,
285271
"/api/plugins/spammer/v1/stop",
286272
"post",

src/models/plugins/ISpammerSettings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ export interface ISpammerSettings {
2323
* The max number of spam workers.
2424
*/
2525
spammerWorkersMax: number;
26+
27+
/**
28+
* The error messsage.
29+
*/
30+
error?: {
31+
message: string;
32+
};
2633
}

src/models/plugins/participation/IParticipationEvent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ export interface IParticipationEvent {
33
* The hex encoded ID of the created participation event.
44
*/
55
eventId: string;
6+
7+
/**
8+
* The error message.
9+
*/
10+
error?: {
11+
message: string;
12+
};
613
}

src/models/plugins/participation/IParticipationEventInfo.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ export interface IParticipationEventInfo {
3737
*/
3838
status?: IParticipationEventStatus;
3939

40+
41+
/**
42+
* The error message.
43+
*/
44+
error?: {
45+
message: string;
46+
};
4047
}

src/models/plugins/participation/IParticipationEventStatus.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export interface IParticipationEventStatus {
2323
* The SHA256 checksum of all the question and answer status or the staking amount and
2424
* rewards calculated for this MilestoneIndex.
2525
*/
26-
checksum: string;
26+
checksum: string;
27+
28+
/**
29+
* The error message.
30+
*/
31+
error?: {
32+
message: string;
33+
};
2734
}
2835

src/models/plugins/participation/IParticipationEvents.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ export interface IParticipationEvents {
33
* The hex encoded IDs of the found events.
44
*/
55
eventIds: string[];
6+
7+
/**
8+
* The error message.
9+
*/
10+
error?: {
11+
message: string;
12+
};
613
}

0 commit comments

Comments
 (0)