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(API_THINGS_SEARCH, { method: 'POST', data: body, }); case 'gms': return request(API_THINGS_SEARCH, { method: 'POST', data: body, }); case 'spole': return request(API_THINGS_SEARCH, { method: 'POST', data: body, }); default: return request(API_THINGS_SEARCH, { method: 'POST', data: body, }); } } export async function apiGetThingPolicyByUser( params: Partial, userId: string, ) { return request( `${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, }); }