42 lines
1008 B
TypeScript
42 lines
1008 B
TypeScript
|
|
import * as plugins from '../plugins.js';
|
||
|
|
import type { AppConnectionManager } from './classes.appconnectionmanager.js';
|
||
|
|
|
||
|
|
@plugins.smartdata.Manager()
|
||
|
|
export class AppConnection extends plugins.smartdata.SmartDataDbDoc<
|
||
|
|
AppConnection,
|
||
|
|
plugins.idpInterfaces.data.IAppConnection,
|
||
|
|
AppConnectionManager
|
||
|
|
> {
|
||
|
|
// INSTANCE
|
||
|
|
@plugins.smartdata.unI()
|
||
|
|
id: plugins.idpInterfaces.data.IAppConnection['id'];
|
||
|
|
|
||
|
|
@plugins.smartdata.svDb()
|
||
|
|
data: plugins.idpInterfaces.data.IAppConnection['data'];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Check if the connection is active
|
||
|
|
*/
|
||
|
|
public isActive(): boolean {
|
||
|
|
return this.data.status === 'active';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Disconnect the app
|
||
|
|
*/
|
||
|
|
public async disconnect(): Promise<void> {
|
||
|
|
this.data.status = 'disconnected';
|
||
|
|
await this.save();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reconnect the app
|
||
|
|
*/
|
||
|
|
public async reconnect(userId: string): Promise<void> {
|
||
|
|
this.data.status = 'active';
|
||
|
|
this.data.connectedAt = Date.now();
|
||
|
|
this.data.connectedByUserId = userId;
|
||
|
|
await this.save();
|
||
|
|
}
|
||
|
|
}
|