feat: users management

This commit is contained in:
swve 2024-01-22 20:37:11 +01:00
parent a552300e15
commit 689625b0d5
22 changed files with 621 additions and 36 deletions

View file

@ -1,5 +1,5 @@
import { getAPIUrl } from "@services/config/config";
import { RequestBody, errorHandling } from "@services/utils/ts/requests";
import { RequestBody, errorHandling, getResponseMetadata } from "@services/utils/ts/requests";
/*
This file includes only POST, PUT, DELETE requests
@ -49,3 +49,15 @@ export function getOrganizationContextInfoNoAsync(org_slug: any, next: any) {
const result = fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null, next));
return result;
}
export async function updateUserRole(org_id: any, user_id: any, role_uuid: any) {
const result = await fetch(`${getAPIUrl()}orgs/${org_id}/users/${user_id}/role/${role_uuid}`, RequestBody("PUT", null, null));
const res = await getResponseMetadata(result);
return res;
}
export async function removeUserFromOrg(org_id: any, user_id: any) {
const result = await fetch(`${getAPIUrl()}orgs/${org_id}/users/${user_id}`, RequestBody("DELETE", null, null));
const res = await getResponseMetadata(result);
return res;
}

View file

@ -75,7 +75,15 @@ export const errorHandling = (res: any) => {
return res.json();
};
export const getResponseMetadata = async (fetch_result: any) => {
type CustomResponseTyping = {
success: boolean;
data: any;
status: number;
HTTPmessage: string;
};
export const getResponseMetadata = async (fetch_result: any): Promise<CustomResponseTyping> => {
const json = await fetch_result.json();
if (fetch_result.status === 200) {
return { success: true, data: json, status: fetch_result.status, HTTPmessage: fetch_result.statusText };