75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import {
|
|
API_SHARE_THING,
|
|
API_THING_POLICY,
|
|
API_THINGS_SEARCH,
|
|
} from '@/constants/api';
|
|
import { request } from '@umijs/max';
|
|
|
|
export async function apiSearchThings(
|
|
body: MasterModel.SearchPaginationBody,
|
|
domain: string = process.env.DOMAIN_ENV || 'gms',
|
|
) {
|
|
switch (domain) {
|
|
case 'sgw':
|
|
return request<SgwModel.SgwThingsResponse>(API_THINGS_SEARCH, {
|
|
method: 'POST',
|
|
data: body,
|
|
});
|
|
case 'gms':
|
|
return request<GmsModel.GmsThingsResponse>(API_THINGS_SEARCH, {
|
|
method: 'POST',
|
|
data: body,
|
|
});
|
|
case 'spole':
|
|
return request<SpoleModel.SpoleThingsResponse>(API_THINGS_SEARCH, {
|
|
method: 'POST',
|
|
data: body,
|
|
});
|
|
default:
|
|
return request<GmsModel.GmsThingsResponse>(API_THINGS_SEARCH, {
|
|
method: 'POST',
|
|
data: body,
|
|
});
|
|
}
|
|
}
|
|
|
|
export async function apiGetThingPolicyByUser(
|
|
params: Partial<MasterModel.SearchPaginationBody>,
|
|
userId: string,
|
|
) {
|
|
return request<MasterModel.ThingPolicyResponse>(
|
|
`${API_THING_POLICY}/${userId}`,
|
|
{
|
|
params: params,
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function apiDeleteUserThingPolicy(
|
|
thing_id: string,
|
|
user_id: string,
|
|
) {
|
|
return request(`${API_SHARE_THING}/${thing_id}/share`, {
|
|
method: 'DELETE',
|
|
data: {
|
|
policies: ['read', 'write', 'delete'],
|
|
user_ids: [user_id],
|
|
},
|
|
getResponse: true,
|
|
});
|
|
}
|
|
export async function apiShareThingToUser(
|
|
thing_id: string,
|
|
user_id: string,
|
|
policies: string[],
|
|
) {
|
|
return request(`${API_SHARE_THING}/${thing_id}/share`, {
|
|
method: 'POST',
|
|
data: {
|
|
policies: policies,
|
|
user_ids: [user_id],
|
|
},
|
|
getResponse: true,
|
|
});
|
|
}
|