more package declarations
This commit is contained in:
47
packages/mobile-api-client/src/api/device.service.ts
Normal file
47
packages/mobile-api-client/src/api/device.service.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Device API service
|
||||
*/
|
||||
|
||||
import { getApiClient } from './api-client';
|
||||
import type { Device, DeviceRegistration, DeviceListResponse } from '../types';
|
||||
|
||||
export class DeviceService {
|
||||
private api = getApiClient();
|
||||
|
||||
async registerDevice(data: DeviceRegistration): Promise<Device> {
|
||||
const response = await this.api.post<Device>('/api/v1/devices/register', data);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async updatePushToken(pushToken: string): Promise<Device> {
|
||||
const response = await this.api.patch<Device>('/api/v1/devices/push-token', {
|
||||
pushToken,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async getDevices(): Promise<DeviceListResponse> {
|
||||
const response = await this.api.get<DeviceListResponse>('/api/v1/devices');
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async getDevice(deviceId: string): Promise<Device> {
|
||||
const response = await this.api.get<Device>(`/api/v1/devices/${deviceId}`);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async deleteDevice(deviceId: string): Promise<void> {
|
||||
await this.api.delete(`/api/v1/devices/${deviceId}`);
|
||||
}
|
||||
|
||||
async getCurrentDevice(): Promise<Device | null> {
|
||||
try {
|
||||
const response = await this.api.get<Device>('/api/v1/devices/current');
|
||||
return response.data;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const deviceService = new DeviceService();
|
||||
Reference in New Issue
Block a user