@xompass/sdk-cloud-api
Version:
Xompass Client for cloud-api
189 lines (183 loc) • 4.37 kB
text/typescript
import {ModelDefinition} from './BaseModels';
import {Customer} from './Customer';
import {DeviceEvent} from './DeviceEvent';
import {DeviceToken} from './DeviceToken';
import {EdgeAgent} from './EdgeAgent';
import {Log} from './Log';
import {TelegramChat} from './TelegramChat';
declare var Object: any;
export interface DeviceInterface {
id?: string;
name: string;
enabled: boolean;
description?: string;
requested?: Date;
created?: Date;
modified?: Date;
deleted?: Date;
customerId?: any;
_config?: any;
customer?: Customer;
config?: any[];
events?: DeviceEvent[];
token?: DeviceToken;
edgeAgents?: EdgeAgent[];
trackingLogs?: Log[];
telegramChats?: TelegramChat[];
}
export class Device implements DeviceInterface {
id: string;
name: string;
enabled: boolean;
description: string;
requested: Date;
created: Date;
modified: Date;
deleted: Date;
customerId: any;
_config: any;
customer?: Customer;
config?: any[];
events?: DeviceEvent[];
token?: DeviceToken;
edgeAgents?: EdgeAgent[];
trackingLogs?: Log[];
telegramChats?: TelegramChat[];
constructor(data?: DeviceInterface) {
Object.assign(this, data);
}
/**
* The name of the model represented by this $resource,
* i.e. `Device`.
*/
public static getModelName(): string {
return 'Device';
}
/**
* @method factory
* @author Jonathan Casarrubias
* @license MIT
* This method creates an instance of Device for dynamic purposes.
*/
public static factory(data: DeviceInterface): Device{
return new Device(data);
}
/**
* @method getModelDefinition
* @author Julien Ledun
* @license MIT
* This method returns an object that represents some of the model
* definitions.
*/
public static getModelDefinition(): ModelDefinition {
return {
name: 'Device',
plural: 'Devices',
path: 'Devices',
idName: 'id',
properties: {
id: {
name: 'id',
type: 'string'
},
name: {
name: 'name',
type: 'string'
},
enabled: {
name: 'enabled',
type: 'boolean'
},
description: {
name: 'description',
type: 'string'
},
requested: {
name: 'requested',
type: 'Date'
},
created: {
name: 'created',
type: 'Date'
},
modified: {
name: 'modified',
type: 'Date'
},
deleted: {
name: 'deleted',
type: 'Date',
default: undefined
},
customerId: {
name: 'customerId',
type: 'any'
},
_config: {
name: '_config',
type: 'any'
},
},
relations: {
customer: {
name: 'customer',
type: 'Customer',
model: 'Customer',
relationType: 'belongsTo',
keyFrom: 'customerId',
keyTo: 'id'
},
config: {
name: 'config',
type: 'any[]',
model: '',
relationType: 'embedsOne',
keyFrom: '_config',
keyTo: 'id'
},
events: {
name: 'events',
type: 'DeviceEvent[]',
model: 'DeviceEvent',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'deviceId'
},
token: {
name: 'token',
type: 'DeviceToken',
model: 'DeviceToken',
relationType: 'hasOne',
keyFrom: 'id',
keyTo: 'deviceId'
},
edgeAgents: {
name: 'edgeAgents',
type: 'EdgeAgent[]',
model: 'EdgeAgent',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'deviceId'
},
trackingLogs: {
name: 'trackingLogs',
type: 'Log[]',
model: 'Log',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'trackingModelId'
},
telegramChats: {
name: 'telegramChats',
type: 'TelegramChat[]',
model: 'TelegramChat',
relationType: 'hasMany',
modelThrough: 'TelegramChatDevice',
keyThrough: 'telegramChatId',
keyFrom: 'id',
keyTo: 'deviceId'
},
}
};
}
}