-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Geofences and GeofenceToNodes (#609)
* implement api [wip] * implement api [wip] * add postbatch, update types and methods * update README.md --------- Co-authored-by: kaveh.taher <[email protected]>
- Loading branch information
1 parent
2e39491
commit a73d0a9
Showing
8 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import BaseApi from '../baseApi'; | ||
import { RequestParams } from '../utils/params/requestParams'; | ||
import { Entity, LibraryReturn, Resources } from '../utils/response/apiResponse'; | ||
import { list, required, Required, requiredSingle } from '../utils/response/responseHandlers'; | ||
import { GeofenceCreate, GeofenceUpdate } from './types'; | ||
|
||
const resourceName = 'geofences'; | ||
type ResourceName = typeof resourceName; | ||
|
||
export class GeofenceEndpoint extends BaseApi<ResourceName> { | ||
public readonly resourceName = resourceName; | ||
public read( | ||
params?: RequestParams<Entity<typeof resourceName>> | string, | ||
): Promise<LibraryReturn<typeof resourceName, Entity<typeof resourceName>[]>> { | ||
const response = this._get<typeof resourceName>('read', { params }); | ||
return list(response); | ||
} | ||
|
||
public create(data: GeofenceCreate, params?: RequestParams<Entity<ResourceName>>): Required<ResourceName> { | ||
const response = this._post<ResourceName>('create', data, params); | ||
return requiredSingle(response); | ||
} | ||
|
||
public update( | ||
data: GeofenceUpdate, | ||
params?: RequestParams<Entity<ResourceName>>, | ||
): Required<typeof resourceName, Resources[typeof resourceName][]> { | ||
const response = this._put<ResourceName>('update', data, params); | ||
return required(response); | ||
} | ||
|
||
public delete(id: number): Promise<LibraryReturn<typeof resourceName>> { | ||
const response = this._delete<typeof resourceName>(`delete`, { params: { id } }); | ||
return requiredSingle(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type Geofence = { | ||
id: number; | ||
name: string; | ||
geo_lat: number; | ||
geo_long: number; | ||
radius: number; | ||
is_demo_data: boolean; | ||
updated: string; | ||
}; | ||
|
||
export type GeofenceRead = Geofence; | ||
|
||
export type GeofenceCreate = Pick<Geofence, 'name' | 'geo_lat' | 'geo_long' | 'radius'> & Partial<Pick<Geofence, 'updated'>>; | ||
|
||
export type GeofenceUpdate = Pick<Geofence, 'id'> & Pick<Partial<Geofence>, 'name' | 'geo_lat' | 'geo_long' | 'radius' | 'updated'>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import BaseApi from '../baseApi'; | ||
import { Entity, LibraryReturn, Resources } from '../utils/response/apiResponse'; | ||
import { RequestParams } from '../utils/params/requestParams'; | ||
import { list, ParsedErrorMesage, required, Required, requiredBatch, requiredSingle } from '../utils/response/responseHandlers'; | ||
import { GeofenceToNodes, GeofenceToNodesCreate, GeofenceToNodesUpdate } from './types'; | ||
|
||
const resourceName = 'geofenceToNodes'; | ||
type ResourceName = typeof resourceName; | ||
|
||
export class GeofenceToNodesEndpoint extends BaseApi<ResourceName> { | ||
public readonly resourceName = resourceName; | ||
|
||
public read( | ||
params?: RequestParams<Entity<typeof resourceName>> | string, | ||
): Promise<LibraryReturn<typeof resourceName, Entity<typeof resourceName>[]>> { | ||
const response = this._get<typeof resourceName>('read', { params }); | ||
return list(response); | ||
} | ||
|
||
public create( | ||
data: GeofenceToNodesCreate | GeofenceToNodesCreate[], | ||
params?: RequestParams<Entity<ResourceName>>, | ||
): Promise<LibraryReturn<'geofenceToNodes'>> | Required<'geofenceToNodes', (GeofenceToNodes | ParsedErrorMesage)[]> { | ||
if (Array.isArray(data)) { | ||
const response = this._postBatch<ResourceName>('create', data, params); | ||
return requiredBatch(response); | ||
} | ||
const response = this._post<ResourceName>('create', data, params); | ||
return requiredSingle(response); | ||
} | ||
|
||
public update( | ||
data: GeofenceToNodesUpdate, | ||
params?: RequestParams<Entity<ResourceName>>, | ||
): Required<typeof resourceName, Resources[typeof resourceName][]> { | ||
const response = this._put<ResourceName>('update', data, params); | ||
return required(response); | ||
} | ||
|
||
public delete(id: number): Promise<LibraryReturn<typeof resourceName>> { | ||
const response = this._delete<typeof resourceName>(`delete`, { params: { id } }); | ||
return requiredSingle(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type GeofenceToNodes = { | ||
id: number; | ||
geofence_id: number; | ||
node_id: number; | ||
updated: string; | ||
}; | ||
|
||
export type GeofenceToNodesRead = GeofenceToNodes; | ||
|
||
export type GeofenceToNodesUpdate = Pick<GeofenceToNodes, 'id' | 'node_id' | 'updated'>; | ||
|
||
export type GeofenceToNodesCreate = Pick<GeofenceToNodes, 'geofence_id' | 'node_id'> & Partial<Pick<GeofenceToNodes, 'updated'>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters