Add updateDeviceMetadata method to api.ts
Add method to update device location and description via Legacy API device_form endpoint. Uses getLegacyWebViewCredentials for auth. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6046655c10
commit
c46af1ea1d
@ -1727,6 +1727,61 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update device metadata (location, description) in Legacy API
|
||||
* Uses device_form endpoint
|
||||
*/
|
||||
async updateDeviceMetadata(
|
||||
deviceId: string,
|
||||
updates: {
|
||||
location?: string;
|
||||
description?: string;
|
||||
}
|
||||
): Promise<ApiResponse<{ success: boolean }>> {
|
||||
try {
|
||||
const creds = await this.getLegacyWebViewCredentials();
|
||||
if (!creds) {
|
||||
return { ok: false, error: { message: 'Not authenticated with Legacy API', code: 'UNAUTHORIZED' } };
|
||||
}
|
||||
|
||||
const formData = new URLSearchParams({
|
||||
function: 'device_form',
|
||||
user_name: creds.userName,
|
||||
token: creds.token,
|
||||
device_id: deviceId,
|
||||
});
|
||||
|
||||
// Add optional fields if provided
|
||||
if (updates.location !== undefined) {
|
||||
formData.append('location', updates.location);
|
||||
}
|
||||
if (updates.description !== undefined) {
|
||||
formData.append('description', updates.description);
|
||||
}
|
||||
|
||||
const response = await fetch(API_BASE_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: formData.toString(),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return { ok: false, error: { message: 'Failed to update device' } };
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status !== '200 OK') {
|
||||
return { ok: false, error: { message: data.message || 'Failed to update device' } };
|
||||
}
|
||||
|
||||
return { ok: true, data: { success: true } };
|
||||
} catch (error: any) {
|
||||
console.error('[API] updateDeviceMetadata error:', error);
|
||||
return { ok: false, error: { message: error.message || 'Network error', code: 'NETWORK_ERROR' } };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detach device from beneficiary
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user