diff --git a/.prettierrc b/.prettierrc index 05c968c0..8a5f33c0 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,6 @@ { "semi": false, "trailingComma": "all", - "singleQuote": true + "singleQuote": true, + "printWidth": 100 } diff --git a/packages/http/src/index.ts b/packages/http/src/index.ts index d513c039..b5aa24fa 100644 --- a/packages/http/src/index.ts +++ b/packages/http/src/index.ts @@ -2,5 +2,4 @@ export { default as Client } from './Client' export { default } from './Client' export { default as Network } from './Network' export { default as ResourceList } from './ResourceList' -export { HTTPHotspotObject as Hotspot } from './models/Hotspot' -export { HTTPAccountObject as Account } from './models/Account' +export { HotspotData as Hotspot } from './models/Hotspot' diff --git a/packages/http/src/models/DataModel.ts b/packages/http/src/models/DataModel.ts new file mode 100644 index 00000000..214ca4d1 --- /dev/null +++ b/packages/http/src/models/DataModel.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import type Client from '../Client' + +export default abstract class DataModel { + protected client: Client + + constructor(client: Client) { + this.client = client + } + + get data(): Omit { + const { client, ...rest } = this + return { ...rest } + } +} diff --git a/packages/http/src/models/Hotspot.ts b/packages/http/src/models/Hotspot.ts index 2dd78765..ac4c3037 100644 --- a/packages/http/src/models/Hotspot.ts +++ b/packages/http/src/models/Hotspot.ts @@ -1,7 +1,10 @@ import camelcaseKeys from 'camelcase-keys' import type Client from '../Client' import Transactions from '../resources/Transactions' -import Hotspots from "../resources/Hotspots" +import Hotspots from '../resources/Hotspots' +import DataModel from './DataModel' + +export type HotspotData = Omit export interface HTTPHotspotObject { score_update_height?: number @@ -48,25 +51,38 @@ interface Status { online: string } -export default class Hotspot { - private client: Client +export default class Hotspot extends DataModel { public scoreUpdateHeight?: number + public score?: number + public owner?: string + public name?: string + public location?: string + public lng?: number + public lat?: number + public block?: number + public geocode?: Geocode + public address: string + public status?: Status + public nonce?: number + public blockAdded?: number + public timestampAdded?: string constructor(client: Client, hotspot: HTTPHotspotObject) { - this.client = client + super(client) + this.scoreUpdateHeight = hotspot.score_update_height this.score = hotspot.score this.owner = hotspot.owner diff --git a/packages/http/src/resources/Hotspots.ts b/packages/http/src/resources/Hotspots.ts index 76312040..a9767fac 100644 --- a/packages/http/src/resources/Hotspots.ts +++ b/packages/http/src/resources/Hotspots.ts @@ -1,5 +1,5 @@ import type Client from '../Client' -import Hotspot, { HTTPHotspotObject } from '../models/Hotspot' +import Hotspot, { HTTPHotspotObject, HotspotData } from '../models/Hotspot' import ResourceList from '../ResourceList' import Account from '../models/Account' import City from '../models/City' @@ -26,17 +26,14 @@ export default class Hotspots { async list(params: ListParams = {}): Promise> { const { hotspots, cursor } = await this.fetchList(params) - const data = hotspots.map( - (d: HTTPHotspotObject) => new Hotspot(this.client, d), - ) + const data = hotspots.map((d: HTTPHotspotObject) => new Hotspot(this.client, d)) return new ResourceList(data, this.list.bind(this), cursor) } - async listJson( - params: ListParams = {}, - ): Promise> { + async listData(params: ListParams = {}): Promise> { const { hotspots, cursor } = await this.fetchList(params) - return new ResourceList(hotspots, this.list.bind(this), cursor) + const data = hotspots.map((d: HTTPHotspotObject) => new Hotspot(this.client, d).data) + return new ResourceList(data, this.list.bind(this), cursor) } private async fetchList(