-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/iot 1530 datatarget log #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
32c582d
Merge branch 'stage'
AugustHA-Iterator 638ae3b
Added entity and some of the coding for new datatarget-logging. None …
Fritsen b480b79
Added most of the logic for making the new datatarget log-entries, an…
Fritsen 79b2d04
Fix issues with datatarget-log entity etc. and finish implementation …
Fritsen 04f4d90
Comment typo..
Fritsen c830e88
Added datatarget latest-message info..
Fritsen 24b8ce2
Log MQTT connection-errors..
Fritsen d6601d4
Added status-flag (based on recent log-events) to data-target queries…
Fritsen 9de1d5b
Add latest changes from stage into datatarget-log, and fixed trivial …
Fritsen 0bed69f
Fixed missing auth on new DatatargetLog-controller..
Fritsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/controllers/admin-controller/data-target-log.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { ComposeAuthGuard } from "@auth/compose-auth.guard"; | ||
| import { Read } from "@auth/roles.decorator"; | ||
| import { RolesGuard } from "@auth/roles.guard"; | ||
| import { ApiAuth } from "@auth/swagger-auth-decorator"; | ||
| import { DatatargetLog } from "@entities/datatarget-log.entity"; | ||
| import { Controller, Get, Param, ParseIntPipe, UseGuards } from "@nestjs/common"; | ||
| import { ApiForbiddenResponse, ApiTags, ApiUnauthorizedResponse } from "@nestjs/swagger"; | ||
| import { InjectRepository } from "@nestjs/typeorm"; | ||
| import { Repository } from "typeorm"; | ||
|
|
||
| @ApiTags("Data Target Logs") | ||
| @Controller("datatarget-log") | ||
| @UseGuards(ComposeAuthGuard, RolesGuard) | ||
| @ApiAuth() | ||
| @Read() | ||
| @ApiForbiddenResponse() | ||
| @ApiUnauthorizedResponse() | ||
| export class DatatargetLogController { | ||
Fritsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| constructor( | ||
| @InjectRepository(DatatargetLog) | ||
| private datatargetLogRepository: Repository<DatatargetLog> | ||
| ) {} | ||
|
|
||
| @Get(":datatargetId") | ||
| async getDatatargetLogs(@Param("datatargetId", new ParseIntPipe()) datatargetId: number): Promise<DatatargetLog[]> { | ||
Fritsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return await this.datatargetLogRepository.find({ | ||
| where: { | ||
| datatarget: { id: datatargetId }, | ||
| }, | ||
| relations: ["iotDevice"], | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { SendStatus } from "@enum/send-status.enum"; | ||
| import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm"; | ||
| import { DbBaseEntity } from "./base.entity"; | ||
| import { DataTarget } from "./data-target.entity"; | ||
| import { IoTDevice } from "./iot-device.entity"; | ||
| import { PayloadDecoder } from "./payload-decoder.entity"; | ||
|
|
||
| @Entity("datatarget-log") | ||
| @Index(["datatarget", "createdAt"]) | ||
| export class DatatargetLog extends DbBaseEntity { | ||
| @ManyToOne(() => DataTarget, { onDelete: "CASCADE" }) | ||
| @JoinColumn() | ||
| datatarget: DataTarget; | ||
|
|
||
| @Column() | ||
| type: SendStatus; | ||
|
|
||
| @Column({ nullable: true }) | ||
| statusCode?: number; | ||
|
|
||
| @Column({ nullable: true }) | ||
| message?: string; | ||
|
|
||
| @ManyToOne(() => IoTDevice, { onDelete: "SET NULL", nullable: true }) | ||
| @JoinColumn() | ||
| iotDevice?: IoTDevice; | ||
|
|
||
| @ManyToOne(() => PayloadDecoder, { onDelete: "SET NULL", nullable: true }) | ||
| @JoinColumn() | ||
| payloadDecoder?: PayloadDecoder; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import { ListAllEntitiesResponseDto } from "@dto/list-all-entities-response.dto"; | ||
| import { DataTarget } from "@entities/data-target.entity"; | ||
|
|
||
| export class ListAllDataTargetsResponseDto extends ListAllEntitiesResponseDto<DataTarget> {} | ||
| export type DataTargetDto = DataTarget & { | ||
| hasRecentErrors?: boolean; | ||
| }; | ||
|
|
||
| export class ListAllDataTargetsResponseDto extends ListAllEntitiesResponseDto<DataTargetDto> {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
|
||
| export class DatatargetLog1726653509863 implements MigrationInterface { | ||
| name = 'DatatargetLog1726653509863' | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "data_target" ADD "lastMessageDate" TIMESTAMP`); | ||
| await queryRunner.query(`CREATE TABLE "datatarget-log" ("id" SERIAL NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "type" character varying NOT NULL, "statusCode" integer, "message" character varying, "createdById" integer, "updatedById" integer, "datatargetId" integer, "iotDeviceId" integer, "payloadDecoderId" integer, CONSTRAINT "PK_f853c6517b8a428fa350221a0f2" PRIMARY KEY ("id"))`); | ||
| await queryRunner.query(`CREATE INDEX "IDX_1d333574ef086bee54ff78b2e0" ON "datatarget-log" ("datatargetId", "createdAt") `); | ||
| await queryRunner.query(`ALTER TABLE "datatarget-log" ADD CONSTRAINT "FK_2f62220b03e524c7a056890fb3b" FOREIGN KEY ("createdById") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
| await queryRunner.query(`ALTER TABLE "datatarget-log" ADD CONSTRAINT "FK_7bcebf642504f26aa8c03074cca" FOREIGN KEY ("updatedById") REFERENCES "user"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
| await queryRunner.query(`ALTER TABLE "datatarget-log" ADD CONSTRAINT "FK_0e1507ac15e7d6755273691345e" FOREIGN KEY ("datatargetId") REFERENCES "data_target"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
| await queryRunner.query(`ALTER TABLE "datatarget-log" ADD CONSTRAINT "FK_4fd74ac0a22db2f38e6b420a657" FOREIGN KEY ("iotDeviceId") REFERENCES "iot_device"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); | ||
| await queryRunner.query(`ALTER TABLE "datatarget-log" ADD CONSTRAINT "FK_28c126089e5dac0360926acf819" FOREIGN KEY ("payloadDecoderId") REFERENCES "payload_decoder"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "data_target" DROP COLUMN "lastMessageDate"`); | ||
| await queryRunner.query(`DROP TABLE "datatarget-log"`); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.