The banUser function in ChatModerationService was sending an incomplete request body to the /api/chat/users/setenabled endpoint. The API requires both userId and enabled fields, but only userId was being sent. This caused the endpoint to return a 400 Bad Request with the error: "must provide userId and enabled state" Added the missing enabled: false parameter to properly disable the user when banning. Co-authored-by: Matt Pruitt <41898282+guitsaru@users.noreply.github.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
const HIDE_MESSAGE_ENDPOINT = `/api/chat/messagevisibility`;
|
|
const BAN_USER_ENDPOINT = `/api/chat/users/setenabled`;
|
|
|
|
class ChatModerationService {
|
|
public static async removeMessage(id: string, accessToken: string): Promise<any> {
|
|
const url = new URL(HIDE_MESSAGE_ENDPOINT, window.location.toString());
|
|
url.searchParams.append('accessToken', accessToken);
|
|
const hideMessageUrl = url.toString();
|
|
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ idArray: [id], visible: false }),
|
|
};
|
|
|
|
await fetch(hideMessageUrl, options);
|
|
}
|
|
|
|
public static async banUser(id: string, accessToken: string): Promise<any> {
|
|
const url = new URL(BAN_USER_ENDPOINT, window.location.toString());
|
|
url.searchParams.append('accessToken', accessToken);
|
|
const hideMessageUrl = url.toString();
|
|
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({ userId: id, enabled: false }),
|
|
};
|
|
|
|
await fetch(hideMessageUrl, options);
|
|
}
|
|
}
|
|
|
|
export default ChatModerationService;
|