Skip to content

Commit

Permalink
Merge pull request #198 from amosproj/feat/xd-65
Browse files Browse the repository at this point in the history
feat: Function implementation: manage and update pump state (XD-65)
  • Loading branch information
KonsumGandalf authored Jun 26, 2024
2 parents 945b1e3 + eb29f65 commit 0905eeb
Show file tree
Hide file tree
Showing 85 changed files with 16,507 additions and 20,344 deletions.
3 changes: 2 additions & 1 deletion .lintstagedrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'*.{ts}':
- nx run-many --target lint
'*.{json,md,yml}':
- nx format:write --uncommitted
'*.{scss,css}':
- nx affected --target stylelint --fix
- nx format:write --uncommitted
6 changes: 3 additions & 3 deletions apps/backend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { validateConfig } from './config/validation';
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ['.env'],
envFilePath: [ '.env' ],
validate: validateConfig,
}),
XdInsightHubModule.registerAsync({
imports: [ConfigModule],
imports: [ ConfigModule ],
useFactory: (configService: ConfigService<BackendConfig>) =>
configService.get('insightHub'),
inject: [ConfigService],
inject: [ ConfigService ],
}),
XdTimeseriesModule,
XdCaseManagementModule,
Expand Down
14 changes: 7 additions & 7 deletions apps/backend/src/app/config/classes/environment.class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsDefined, IsNumber, IsString, IsUrl, MinLength } from 'class-validator';
import { IsDefined, IsNumber, IsOptional, IsString, MinLength } from 'class-validator';

/* Interfaces */
import { IEnvironmentVariables } from '../interfaces/environment.interface';
Expand Down Expand Up @@ -95,10 +95,10 @@ export class EnvironmentVariables implements IEnvironmentVariables {
@MinLength(1)
INSIGHT_HUB_API_KEY?: string;

/**
* The URL of the Swagger UI
*/
@IsDefined()
@IsString()
SWAGGER_URL_PATH: string;
/**
* The URL of the Swagger UI
*/
@IsOptional()
@IsString()
SWAGGER_URL_PATH?: string;
}
6 changes: 3 additions & 3 deletions apps/backend/src/app/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const generateConfig = (config: IEnvironmentVariables): BackendConfig =>
apiUrl: config.INSIGHT_HUB_API_URL,
apiKey: config.INSIGHT_HUB_API_KEY,
},
swagger: {
urlPath: config.SWAGGER_URL_PATH,
}
swagger: {
urlPath: config.SWAGGER_URL_PATH || 'swagger',
},
} as BackendConfig);
12 changes: 6 additions & 6 deletions apps/frontend/src/app/pages/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe('HomeComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ HomeComponent ],
providers: [
{
provide: ActivatedRoute,
useValue: {}
}
],
providers: [
{
provide: ActivatedRoute,
useValue: { snapshot: { params: { id: '1' } } },
},
],
}).compileComponents();

fixture = TestBed.createComponent(HomeComponent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { faker } from '@faker-js/faker';
import { ECasePriority, ECaseStatus, ECaseType, ICaseResponse, ICreateCaseBody } from '@frontend/cases/shared/models';
import {
ECasePriority,
ECaseStatus,
ECaseType,
ICaseResponse,
ICreateCaseBody,
} from '@frontend/cases/shared/models';
import { Test, TestingModule } from '@nestjs/testing';
import { firstValueFrom, of } from 'rxjs';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { faker } from '@faker-js/faker';
import { ECasePriority, ECaseStatus, ECaseType, ICreateCaseBody } from '@frontend/cases/shared/models';
import {
ECasePriority,
ECaseStatus,
ECaseType,
ICreateCaseBody,
} from '@frontend/cases/shared/models';
import { Test, TestingModule } from '@nestjs/testing';
import { PrismaService } from 'common-backend-prisma';
import { firstValueFrom } from 'rxjs';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './case-browse.component';
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import DeleteModalComponent from './delete-modal/deleteModal.component';
@Component({
selector: 'lib-detail-case',
standalone: true,
imports: [CommonModule, FormsModule, IxModule, RouterLink],
imports: [ CommonModule, FormsModule, IxModule, RouterLink ],
templateUrl: './detail-case.component.html',
styleUrls: ['./detail-case.component.scss'],
styleUrls: [ './detail-case.component.scss' ],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SwaggerDocumentBuilder {
'JWTAuthorization',
);

Object.entries(SWAGGER_TAG_INFORMATION).forEach(([ tag, tagInformation ]) => {
Object.entries(SWAGGER_TAG_INFORMATION).forEach(([tag, tagInformation]) => {
docBuilder.addTag(tag, tagInformation.description);
});

Expand Down
8 changes: 8 additions & 0 deletions libs/common/shared/models/src/lib/enums/color-variant.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Enum reflecting the color variants available for the color component.
*/
export enum EColorVariant {
SUCCESS = 'success',
CRITICAL = 'critical',
WARNING = 'warning',
}
1 change: 1 addition & 0 deletions libs/common/shared/models/src/lib/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './color-variant.enum';
1 change: 1 addition & 0 deletions libs/common/shared/models/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// directories
export * from './enums';
export * from './interfaces';
export * from './types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { faker } from '@faker-js/faker';
import { IFacilitiesResponse } from '@frontend/facilities/shared/models';
import { EPumpStatus, IFacilitiesResponse, IPumpMetrics } from '@frontend/facilities/shared/models';
import { Test, TestingModule } from '@nestjs/testing';
import { firstValueFrom, of } from 'rxjs';

Expand All @@ -11,13 +11,16 @@ describe('FacilitiesController ', () => {
let service: XdFacilitiesService;

const facilitiesResponse: IFacilitiesResponse = {
assetId: faker.string.uuid(),
indicatorMsg: faker.string.sample(),
metrics: [ { standardDeviation: faker.number.int() } as IPumpMetrics ],
assetId: faker.string.uuid(),
createdAt: faker.date.recent(),
description: faker.string.sample(),
name: faker.string.sample(),
typeId: faker.string.uuid(),
updatedAt: faker.date.recent(),
variables: faker.string.sample(),
status: faker.helpers.enumValue(EPumpStatus),
location: {
country: faker.location.country(),
latitude: faker.location.latitude(),
Expand All @@ -26,8 +29,8 @@ describe('FacilitiesController ', () => {
postalCode: faker.location.zipCode(),
region: faker.location.state(),
streetAddress: faker.location.streetAddress(),
},
};
}
};

beforeAll(async () => {
const serviceMock = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { faker } from '@faker-js/faker';
import { HttpService } from '@nestjs/axios';
import { Logger } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { XdAssetsService, XdTokenManagerService } from 'common-backend-insight-hub';
import { PrismaService } from 'common-backend-prisma';
import { create } from 'lodash';
import { EPumpStatus } from 'facilities-shared-models';
import { lastValueFrom, of } from 'rxjs';

import { XdFacilitiesService } from './facilities.service';
Expand Down Expand Up @@ -89,6 +90,8 @@ describe('FacilitiesService ', () => {
description: 'test',
typeId: 'test',
variables: {},
indicatorMsg: faker.string.sample(),
status: EPumpStatus.REGULAR,
createdAt: new Date(),
updatedAt: new Date(),
location: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IFacilitiesResponse, IFacilityLocation } from '@frontend/facilities/shared/models';
import { EPumpStatus, IFacilitiesResponse, IFacilityLocation, IPumpMetrics } from '@frontend/facilities/shared/models';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { Aspect, XdAssetsService } from 'common-backend-insight-hub';
import { Asset } from 'common-backend-insight-hub';
import { Aspect, Asset, XdAssetsService } from 'common-backend-insight-hub';
import { PrismaService } from 'common-backend-prisma';
import { filter, forkJoin, from, map, mergeMap, Observable, of, switchMap, toArray } from 'rxjs';

Expand Down Expand Up @@ -109,7 +108,6 @@ export class XdFacilitiesService {
/**
* This method filters the existing assets from the assets. An asset is considered existing if it is already present in the database.
*
*
* @param assets the assets to be filtered
* @returns The assets that are not present in the database.
*/
Expand Down Expand Up @@ -165,13 +163,24 @@ export class XdFacilitiesService {
this.prismaService.asset.findMany({
include: {
location: true,
metrics: true,
},
}),
).pipe(
map((assets) => {
return assets.map((asset) => {
const { assetId, name, typeId, description, createdAt, updatedAt, variables } =
asset;
const {
assetId,
name,
typeId,
description,
createdAt,
updatedAt,
variables,
status,
indicatorMsg,
metrics
} = asset;

const location: IFacilityLocation | undefined = asset.location
? {
Expand All @@ -189,7 +198,10 @@ export class XdFacilitiesService {
assetId,
name,
typeId,
location: location,
status: status as EPumpStatus,
location,
indicatorMsg,
metrics: metrics as IPumpMetrics[],
variables: variables || undefined,
description: description || '',
createdAt: createdAt,
Expand All @@ -211,6 +223,7 @@ export class XdFacilitiesService {
},
include: {
location: true,
metrics: true,
},
}),
).pipe(
Expand All @@ -219,8 +232,18 @@ export class XdFacilitiesService {
throw new HttpException('Facility not Found', HttpStatus.NOT_FOUND);
}

const { assetId, name, typeId, description, variables, createdAt, updatedAt } =
asset;
const {
assetId,
name,
typeId,
description,
variables,
createdAt,
updatedAt,
status,
indicatorMsg,
metrics
} = asset;

const location: IFacilityLocation | undefined = asset.location
? {
Expand All @@ -238,6 +261,9 @@ export class XdFacilitiesService {
assetId,
name,
typeId,
status: status as EPumpStatus,
indicatorMsg: indicatorMsg,
metrics: metrics as IPumpMetrics[],
description: description || '',
variables: variables || undefined,
location: location,
Expand Down
18 changes: 18 additions & 0 deletions libs/facilities/backend/models/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/facilities/backend/models/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# facilities-backend-models

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test facilities-backend-models` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/facilities/backend/models/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'facilities-backend-models',
preset: '../../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../../coverage/libs/facilities/backend/models',
};
16 changes: 16 additions & 0 deletions libs/facilities/backend/models/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "facilities-backend-models",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/facilities/backend/models/src",
"projectType": "library",
"tags": ["domain:facilities", "kind:backend", "type:models"],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/facilities/backend/models/jest.config.ts"
}
}
}
}
1 change: 1 addition & 0 deletions libs/facilities/backend/models/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions libs/facilities/backend/models/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

22 changes: 22 additions & 0 deletions libs/facilities/backend/models/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
16 changes: 16 additions & 0 deletions libs/facilities/backend/models/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../../dist/out-tsc",
"declaration": true,
"types": ["node"],
"target": "es2021",
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
Loading

0 comments on commit 0905eeb

Please sign in to comment.