All files / src/services/web-socket web-socket.service.ts

100% Statements 18/18
100% Branches 0/0
100% Functions 4/4
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38              1x     2x 2x 2x 2x   2x 2x       1x   1x 1x   1x       1x   1x 1x   1x      
import { EventEmitter, Injectable } from '@angular/core';
 
import { WebSocket } from '../../models/web-socket';
import { ApiService, RestParameters } from '../api/api.service';
import { EnvironmentService } from '../environment/environment.service';
 
@Injectable({ providedIn: 'root' })
export class WebSocketService {
  public basePath: string;
 
  public onCreate = new EventEmitter<WebSocket>();
  public onDelete = new EventEmitter<WebSocket>();
  public onRead = new EventEmitter<WebSocket[]>();
  public onUpdate = new EventEmitter<WebSocket>();
 
  constructor(private apiService: ApiService, private environmentService: EnvironmentService) {
    this.basePath = this.environmentService.webSocketApiBaseUrl;
  }
 
  public async find(parameters: RestParameters): Promise<WebSocket[]> {
    const response = await this.apiService.request('get', `${this.basePath}`, parameters);
 
    const records = response.records.map(record => new WebSocket(record));
    this.onRead.emit(records);
 
    return records;
  }
 
  public async findOne(_id: string): Promise<WebSocket> {
    const response = await this.apiService.request('get', `${this.basePath}/${_id}`);
 
    const record = new WebSocket(response.record);
    this.onRead.emit([record]);
 
    return record;
  }
}