Skip to content

Commit

Permalink
refactor: export interface ServicesInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsafur committed Dec 24, 2019
1 parent 72f3319 commit f5fa18d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/store/Services.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { RequestRegister } from "../types/Request";
import { RequestRegister } from "@/types/Request";
import { ServicesByNameInterface, ServicesInterface } from "@/types/Service";

import Service from "../entity/Service";

declare interface ServicesInterface {
[uuid: string]: Service;
}

export class Services {
/**
* List of service registered
Expand Down Expand Up @@ -91,14 +88,18 @@ export class Services {
* @param {string} messageType The message type
* @return ServicesInterface
*/
public getByMessageType(messageType: string): ServicesInterface {
const returned: ServicesInterface = {};
public getByMessageType(messageType: string): ServicesByNameInterface {
const returned: ServicesByNameInterface = {};

for (const uuid in this.services) {
if (this.services.hasOwnProperty(uuid)) {
const service = this.services[uuid];

if (service.getMessageAccepted().indexOf(messageType) >= 0) {
returned[uuid] = service;
if (returned[service.getName()] === undefined) {
returned[service.getName()] = {};
}
returned[service.getName()][uuid] = service;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/types/Service.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Service from "@/entity/Service";

export interface ServiceInterface {
"name": string;
"version": string;
Expand All @@ -7,3 +9,13 @@ export interface ServiceInterface {
"messageAccepted": string[];
"uuid"?: string
}

export interface ServicesInterface {
[uuid: string]: Service;
}

export interface ServicesByNameInterface {
[serviceName: string]: {
[uuid: string]: Service;
}
}

0 comments on commit f5fa18d

Please sign in to comment.