Skip to content

Commit

Permalink
PR changes and added prettier from backend so it can match with front…
Browse files Browse the repository at this point in the history
…end (both are nodejs, so shouldn't it be the same?)
  • Loading branch information
August Andersen committed Dec 14, 2023
1 parent 09a009f commit 4fdde47
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 101 deletions.
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

11 changes: 11 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
trailingComma: "es5",
tabWidth: 4,
printWidth: 120,
semi: true,
singleQuote: false,
useTabs: false,
bracketSpacing: true,
arrowParens: "avoid",
endOfLine: "auto",
};
4 changes: 1 addition & 3 deletions src/app/gateway/gateway-table/gateway-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChirpstackGatewayService } from 'src/app/shared/services/chirpstack-gat
import { TranslateService } from '@ngx-translate/core';
import { Gateway, GatewayResponseMany } from '../gateway.model';
import { faExclamationTriangle, faCheckCircle } from '@fortawesome/free-solid-svg-icons';
faExclamationTriangle,
import moment from 'moment';
import { Component, ViewChild, AfterViewInit, Input, OnDestroy } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
Expand All @@ -16,7 +15,6 @@ import { tableSorter } from '@shared/helpers/table-sorting.helper';
import { OrganizationAccessScope } from '@shared/enums/access-scopes';
import { DefaultPageSizeOptions } from '@shared/constants/page.constants';
import { TableColumn } from '@shared/types/table.type';
import { convertToDateFromTimestamp } from '@shared/helpers/time.helper';

const columnDefinitions: TableColumn[] = [
{
Expand Down Expand Up @@ -187,7 +185,7 @@ export class GatewayTableComponent implements AfterViewInit, OnDestroy {

lastActive(gateway: Gateway): string {
if (gateway?.lastSeenAt) {
const date = gateway.lastSeenAt ?? convertToDateFromTimestamp(gateway.lastSeenAt);
const date = gateway.lastSeenAt ?? gateway.lastSeenAt

const lastSeenAtUnixTimestamp = moment(date).valueOf();
const now = moment(new Date()).valueOf();
Expand Down
103 changes: 53 additions & 50 deletions src/app/gateway/gateway.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,88 @@ import { CommonLocation } from '../shared/models/common-location.model';
import { GatewayStatusInterval } from './enums/gateway-status-interval.enum';

export class Gateway extends EditPermission {
id: number;
gatewayId: string;
name: string;
description?: string;
location: CommonLocation = new CommonLocation();
rxPacketsReceived: number;
txPacketsEmitted: number;
discoveryEnabled = false;
gatewayProfileID: string = null;
tagsString = '{}';
tags?: JSON;
lastSeenAt: Date;
organizationId: number;
organizationName: string;
createdAt: Date;
updatedAt: Date;
createdBy: number;
updatedBy: number;
createdByName: string;
updatedByName: string;
id: number;
gatewayId: string;
name: string;
description?: string;
location: CommonLocation = new CommonLocation();
rxPacketsReceived: number;
txPacketsEmitted: number;
discoveryEnabled = false;
gatewayProfileID: string = null;
tagsString = '{}';
tags?: JSON;
lastSeenAt: Date;
organizationId: number;
organizationName: string;
createdAt: Date;
updatedAt: Date;
createdBy: number;
updatedBy: number;
createdByName: string;
updatedByName: string;
}
export interface GrpcTime {
seconds: number;
nanos: number;
}

export class GatewayData {
data: Gateway[];
ok?: boolean;
count?: number;
data: Gateway[];
ok?: boolean;
count?: number;
}

export class GatewayRequest {
gateway: Gateway;
organizationId: number;
gateway: Gateway;
organizationId: number;
}

export class GatewayResponseMany {
resultList: Gateway[];
totalCount: number;
resultList: Gateway[];
totalCount: number;
}

export class GatewayResponse {
createdAt: string;
updatedAt: string;
firstSeenAt: string;
lastSeenAt: string;
gateway: Gateway;
stats: GatewayStats[];
createdAt: string;
updatedAt: string;
firstSeenAt: string;
lastSeenAt: string;
gateway: Gateway;
stats: GatewayStats[];
}

export interface GatewayStats {
timestamp: Date;
rxPacketsReceived: number;
rxPacketsReceivedOK: number;
txPacketsReceived: number;
txPacketsEmitted: number;
timestamp: Date;
rxPacketsReceived: number;
rxPacketsReceivedOK: number;
txPacketsReceived: number;
txPacketsEmitted: number;
}

export interface GetAllGatewayStatusParameters {
limit?: number;
offset?: number;
organizationId?: number;
timeInterval?: GatewayStatusInterval;
limit?: number;
offset?: number;
organizationId?: number;
timeInterval?: GatewayStatusInterval;
}

export interface StatusTimestamp {
timestamp: Date;
wasOnline: boolean;
timestamp: Date;
wasOnline: boolean;
}

export interface GetGatewayStatusParameters {
timeInterval?: GatewayStatusInterval;
timeInterval?: GatewayStatusInterval;
}

export interface GatewayStatus {
id: string;
name: string;
statusTimestamps: StatusTimestamp[];
id: string;
name: string;
statusTimestamps: StatusTimestamp[];
}

export interface AllGatewayStatusResponse {
data: GatewayStatus[];
count: number;
data: GatewayStatus[];
count: number;
}
7 changes: 0 additions & 7 deletions src/app/shared/helpers/time.helper.ts

This file was deleted.

61 changes: 25 additions & 36 deletions src/app/shared/services/chirpstack-gateway.service.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,37 @@
import { Injectable } from '@angular/core';
import { RestService } from './rest.service';
import { Observable } from 'rxjs';
import {
GatewayResponse,
Gateway,
GatewayData,
GatewayRequest,
GatewayResponseMany,
} from '@app/gateway/gateway.model';
import moment from 'moment';
import { SharedVariableService } from '@shared/shared-variable/shared-variable.service';
import { map } from 'rxjs/operators';
import { UserMinimalService } from '@app/admin/users/user-minimal.service';
import { convertToDateFromTimestamp } from '@shared/helpers/time.helper';
import { Injectable } from "@angular/core";
import { RestService } from "./rest.service";
import { Observable } from "rxjs";
import { GatewayResponse, Gateway, GatewayData, GatewayRequest, GatewayResponseMany } from "@app/gateway/gateway.model";
import moment from "moment";
import { SharedVariableService } from "@shared/shared-variable/shared-variable.service";
import { map } from "rxjs/operators";
import { UserMinimalService } from "@app/admin/users/user-minimal.service";

@Injectable({
providedIn: 'root',
providedIn: "root",
})
export class ChirpstackGatewayService {
private chripstackGatewayUrl = 'chirpstack/gateway';
private chripstackGatewayUrl = "chirpstack/gateway";

constructor(
private restService: RestService,
private sharedVariableService: SharedVariableService,
private userMinimalService: UserMinimalService
) {
moment.locale('da');
moment.locale("da");
}

public get(id: string, params = {}): Observable<GatewayResponse> {
return this.restService.get(this.chripstackGatewayUrl, params, id).pipe(
map((response: GatewayResponse) => {
response.gateway.organizationName = this.sharedVariableService
.getOrganizationInfo()
.find((org) => org.id === response.gateway.organizationId)?.name;
return this.restService.get(this.chripstackGatewayUrl, params, id).pipe(
map((response: GatewayResponse) => {
response.gateway.organizationName = this.sharedVariableService
.getOrganizationInfo()
.find(org => org.id === response.gateway.organizationId)?.name;

// Move createdat and updatedat to next level ease the use.
response.gateway.tagsString = JSON.stringify(response.gateway.tags)
response.gateway.createdByName = this.userMinimalService.getUserNameFrom(
response.gateway.createdBy
);
response.gateway.updatedByName = this.userMinimalService.getUserNameFrom(
response.gateway.updatedBy
);
response.gateway.tagsString = JSON.stringify(response.gateway.tags);
response.gateway.createdByName = this.userMinimalService.getUserNameFrom(response.gateway.createdBy);
response.gateway.updatedByName = this.userMinimalService.getUserNameFrom(response.gateway.updatedBy);
return response;
})
);
Expand All @@ -51,10 +40,10 @@ export class ChirpstackGatewayService {
public getMultiple(params = {}): Observable<GatewayResponseMany> {
return this.restService.get(this.chripstackGatewayUrl, params).pipe(
map((response: GatewayResponseMany) => {
response.resultList.map((gateway) => {
response.resultList.map(gateway => {
gateway.organizationName = this.sharedVariableService
.getOrganizationInfo()
.find((org) => org.id === gateway.organizationId)?.name;
.find(org => org.id === gateway.organizationId)?.name;
});
return response;
})
Expand All @@ -66,7 +55,7 @@ export class ChirpstackGatewayService {
gatewayRequest.gateway = gateway;
gatewayRequest.organizationId = this.sharedVariableService.getSelectedOrganisationId();
return this.restService.post(this.chripstackGatewayUrl, gatewayRequest, {
observe: 'response',
observe: "response",
});
}

Expand All @@ -76,15 +65,15 @@ export class ChirpstackGatewayService {
return this.restService.put(this.chripstackGatewayUrl, gatewayRequest, id);
}

public delete(gatewayId: string): Observable<any> {
return this.restService.delete(this.chripstackGatewayUrl, gatewayId);
public delete(gatewayId: string): Observable<any> {
return this.restService.delete(this.chripstackGatewayUrl, gatewayId);
}

public isGatewayActive(gateway: Gateway): boolean {
const errorTime = new Date();
errorTime.setSeconds(errorTime.getSeconds() - 150);
if (gateway?.lastSeenAt) {
const date = gateway.lastSeenAt ?? convertToDateFromTimestamp(gateway.lastSeenAt);
const date = gateway.lastSeenAt ?? gateway.lastSeenAt;
const lastSeenAtUnixTimestamp = moment(date).unix();
const errorTimeUnixTimestamp = moment(errorTime).unix();
return errorTimeUnixTimestamp < lastSeenAtUnixTimestamp;
Expand Down

0 comments on commit 4fdde47

Please sign in to comment.