From 6545af24f299e539e8ce49d09564669a799280b7 Mon Sep 17 00:00:00 2001 From: sorenjohanson Date: Sat, 16 Nov 2024 12:58:08 +0000 Subject: [PATCH 1/3] add: updated types for map, node --- .../src/map/controllers/maps.gateway.spec.ts | 18 ++- .../src/map/entities/mmpMap.entity.ts | 39 +++---- .../src/map/entities/mmpNode.entity.ts | 104 +++++++++--------- .../src/map/services/maps.service.spec.ts | 2 +- teammapper-backend/src/map/types.ts | 32 +++--- 5 files changed, 101 insertions(+), 94 deletions(-) diff --git a/teammapper-backend/src/map/controllers/maps.gateway.spec.ts b/teammapper-backend/src/map/controllers/maps.gateway.spec.ts index 146c8b2f..2dedb6d6 100644 --- a/teammapper-backend/src/map/controllers/maps.gateway.spec.ts +++ b/teammapper-backend/src/map/controllers/maps.gateway.spec.ts @@ -31,7 +31,10 @@ describe('WebSocketGateway', () => { }), removeNode: (_clientNode: IMmpClientNode, _mapId: string) => new Promise((resolve, _reject) => { - resolve(new MmpNode()) + const node = new MmpNode(); + node.createdAt = new Date('2021-01-31T00:00:00.000Z'); + node.lastModified = new Date('2021-01-31T00:00:00.000Z'); + resolve(node); }), }) const testingModule = await Test.createTestingModule({ @@ -133,15 +136,24 @@ describe('WebSocketGateway', () => { it(`allows request when modification secret is set`, (done) => { socket = io('http://localhost:3000') + // Date objects are serialised to JSON in the result, so we'll need to be explicit in setting these here + const defaultNode = { + "createdAt": new Date('2021-01-31T00:00:00.000Z').toISOString(), + "detached": false, + "imageSize": 60, + "lastModified": new Date('2021-01-31T00:00:00.000Z').toISOString(), + "root": false + } + socket.emit( 'removeNode', { mapId: map.id, modificationSecret: map.modificationSecret, - node: {}, + node: defaultNode, }, (result: MmpNode | undefined) => { - expect(result).toEqual({}) + expect(result).toEqual(defaultNode) done() } ) diff --git a/teammapper-backend/src/map/entities/mmpMap.entity.ts b/teammapper-backend/src/map/entities/mmpMap.entity.ts index d538b617..8173174a 100644 --- a/teammapper-backend/src/map/entities/mmpMap.entity.ts +++ b/teammapper-backend/src/map/entities/mmpMap.entity.ts @@ -11,35 +11,36 @@ import { MmpNode } from './mmpNode.entity' @Entity() export class MmpMap { @PrimaryGeneratedColumn('uuid') - id: string + id: string; - @Column({ type: 'timestamptz', nullable: true, default: () => 'now()' }) - lastModified: Date + @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) + lastModified: Date | null = new Date(); @Column({ type: 'timestamptz', nullable: true }) - lastAccessed: Date + lastAccessed: Date | null; - @Column({ nullable: true }) + @Column({ type: 'uuid', nullable: true }) @Generated('uuid') - adminId: string + adminId: string | null; - @Column({ nullable: true, default: null }) + @Column({ type: 'uuid', nullable: true, default: null }) @Generated('uuid') - modificationSecret: string + modificationSecret: string | null = null; - @Column({ nullable: true }) - name: string + @Column({ type: 'varchar', nullable: true }) + name: string | null; - @Column('jsonb', { nullable: false, default: {} }) - options: MapOptions + @Column('jsonb', { + nullable: false, + default: {} + }) + options: MapOptions; - /* eslint-disable @typescript-eslint/no-unused-vars */ - @OneToMany((type) => MmpNode, (node) => node.nodeMap, { + @OneToMany(() => MmpNode, (node) => node.nodeMap, { cascade: true, }) - /* eslint-enable @typescript-eslint/no-unused-vars */ - nodes: MmpNode[] + nodes: MmpNode[]; - @Column({ type: 'timestamptz', default: () => 'now()', nullable: true }) - createdAt: Date -} + @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date | null = new Date(); +} \ No newline at end of file diff --git a/teammapper-backend/src/map/entities/mmpNode.entity.ts b/teammapper-backend/src/map/entities/mmpNode.entity.ts index e3655a0f..ab7e162a 100644 --- a/teammapper-backend/src/map/entities/mmpNode.entity.ts +++ b/teammapper-backend/src/map/entities/mmpNode.entity.ts @@ -17,21 +17,18 @@ import { validateOrReject, IsDefined } from 'class-validator'; @Entity() export class MmpNode { @PrimaryGeneratedColumn('uuid') - id: string + id: string; - @Column({ nullable: true }) - name: string + @Column({ type: 'varchar', nullable: true }) + name: string | null; - /* eslint-disable @typescript-eslint/no-unused-vars */ - @ManyToOne((type) => MmpMap, (map) => map.nodes, { + @ManyToOne(() => MmpMap, (map) => map.nodes, { onDelete: 'CASCADE', }) @JoinColumn() - nodeMap: MmpMap - /* eslint-enable @typescript-eslint/no-unused-vars */ + nodeMap: MmpMap; - /* eslint-disable @typescript-eslint/no-unused-vars */ - @ManyToOne((type) => MmpNode, (node) => node.children, { + @ManyToOne(() => MmpNode, (node) => node.children, { onDelete: 'CASCADE', }) @JoinColumn([ @@ -39,84 +36,81 @@ export class MmpNode { { name: 'nodeParentId', referencedColumnName: 'id' }, ]) @Index() - nodeParent: MmpNode - /* eslint-enable @typescript-eslint/no-unused-vars */ + nodeParent: MmpNode; - /* eslint-disable @typescript-eslint/no-unused-vars */ - @OneToMany((type) => MmpNode, (node) => node.nodeParent) - children: MmpNode[] - /* eslint-enable @typescript-eslint/no-unused-vars */ + @OneToMany(() => MmpNode, (node) => node.nodeParent) + children: MmpNode[]; - @Column({ default: false }) + @Column({ type: 'boolean', default: false }) @IsDefined() - root: boolean + root: boolean = false; - @Column({ type: 'float' }) + @Column({ type: 'float8' }) @IsDefined() - coordinatesX: number + coordinatesX: number; - @Column({ type: 'float' }) + @Column({ type: 'float8' }) @IsDefined() - coordinatesY: number + coordinatesY: number; - @Column({ nullable: true }) - colorsName: string + @Column({ type: 'varchar', nullable: true }) + colorsName: string | null; - @Column({ nullable: true }) - colorsBackground: string + @Column({ type: 'varchar', nullable: true }) + colorsBackground: string | null; - @Column({ nullable: true }) - colorsBranch: string + @Column({ type: 'varchar', nullable: true }) + colorsBranch: string | null; - @Column({ nullable: true }) - fontSize: number + @Column({ type: 'integer', nullable: true }) + fontSize: number | null; - @Column({ nullable: true }) - fontStyle: string + @Column({ type: 'varchar', nullable: true }) + fontStyle: string | null; - @Column({ nullable: true }) - fontWeight: string + @Column({ type: 'varchar', nullable: true }) + fontWeight: string | null; - @Column({ nullable: true }) - imageSrc: string + @Column({ type: 'varchar', nullable: true }) + imageSrc: string | null; - @Column({ nullable: true, default: 60 }) - imageSize: number + @Column({ type: 'integer', nullable: true, default: 60 }) + imageSize: number | null = 60; - @Column({ nullable: true }) - linkHref: string + @Column({ type: 'varchar', nullable: true }) + linkHref: string | null; - @Column({ nullable: true }) - locked: boolean + @Column({ type: 'boolean', nullable: true }) + locked: boolean | null; - @Column({ default: false }) + @Column({ type: 'boolean', default: false }) @IsDefined() - detached: boolean + detached: boolean = false; - @Column({ nullable: true, type: 'float' }) - k: number + @Column({ type: 'float8', nullable: true }) + k: number | null; @PrimaryColumn('uuid') @Index() @IsDefined() - nodeMapId: string + nodeMapId: string; - @Column({ nullable: true }) - nodeParentId: string + @Column({ type: 'uuid', nullable: true }) + nodeParentId: string | null; - @Column({ nullable: false }) + @Column({ type: 'integer' }) @Generated('increment') - orderNumber: number + orderNumber: number; - @Column({ type: 'timestamptz', nullable: true, default: () => 'now()' }) - lastModified: Date + @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) + lastModified: Date | null = new Date(); - @Column({ type: 'timestamptz', default: () => 'now()', nullable: true }) - createdAt: Date + @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) + createdAt: Date | null = new Date(); @BeforeInsert() @BeforeUpdate() async validate() { await validateOrReject(this); } -} +} \ No newline at end of file diff --git a/teammapper-backend/src/map/services/maps.service.spec.ts b/teammapper-backend/src/map/services/maps.service.spec.ts index 63d29c74..43a2ef0d 100644 --- a/teammapper-backend/src/map/services/maps.service.spec.ts +++ b/teammapper-backend/src/map/services/maps.service.spec.ts @@ -157,7 +157,7 @@ describe('MapsController', () => { }) expect(updatedNode?.lastModified).not.toEqual(oldDate) - expect(updatedNode?.lastModified.getTime()).toBeGreaterThan( + expect(updatedNode?.lastModified!.getTime()).toBeGreaterThan( timeBeforeUpdate.getTime() ) }) diff --git a/teammapper-backend/src/map/types.ts b/teammapper-backend/src/map/types.ts index 9dd902b0..ddc38f47 100644 --- a/teammapper-backend/src/map/types.ts +++ b/teammapper-backend/src/map/types.ts @@ -5,9 +5,9 @@ export interface MapOptions { } export interface IMmpClientColor { - name: string - background: string - branch: string + name: string | null + background: string | null + branch: string | null } export interface IMmpClientCoordinates { @@ -16,33 +16,33 @@ export interface IMmpClientCoordinates { } export interface IMmpClientFont { - style: string - size: number - weight: string + style: string | null + size: number | null + weight: string | null } export interface IMmpClientMap { uuid: string - lastModified: Date - lastAccessed: Date + lastModified: Date | null + lastAccessed: Date | null deleteAfterDays: number deletedAt: Date data: IMmpClientNode[] options: IMmpClientMapOptions, - createdAt: Date + createdAt: Date | null } export interface IMmpClientPrivateMap { map: IMmpClientMap - adminId: string - modificationSecret: string + adminId: string | null + modificationSecret: string | null } export interface IMmpClientNodeBasics { colors: IMmpClientColor font: IMmpClientFont - name: string - image: { src: string; size: number } + name: string | null + image: { src: string | null; size: number | null } } export interface IMmpClientNode extends IMmpClientNodeBasics { @@ -50,9 +50,9 @@ export interface IMmpClientNode extends IMmpClientNodeBasics { detached: boolean id: string k: number - link: { href: string } + link: { href: string | null } locked: boolean - parent: string + parent: string | null isRoot: boolean } @@ -119,6 +119,6 @@ export interface IMmpClientMapCreateRequest { } export interface IMmpClientDeleteRequest { - adminId: string + adminId: string | null mapId: string } From a98fae4494f0602a0ea6220597f356f37ae971b7 Mon Sep 17 00:00:00 2001 From: sorenjohanson Date: Mon, 18 Nov 2024 14:26:02 +0000 Subject: [PATCH 2/3] remove: new Date(), null --- teammapper-backend/src/map/entities/mmpMap.entity.ts | 6 +++--- teammapper-backend/src/map/entities/mmpNode.entity.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/teammapper-backend/src/map/entities/mmpMap.entity.ts b/teammapper-backend/src/map/entities/mmpMap.entity.ts index 8173174a..a29f711a 100644 --- a/teammapper-backend/src/map/entities/mmpMap.entity.ts +++ b/teammapper-backend/src/map/entities/mmpMap.entity.ts @@ -14,7 +14,7 @@ export class MmpMap { id: string; @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) - lastModified: Date | null = new Date(); + lastModified: Date | null; @Column({ type: 'timestamptz', nullable: true }) lastAccessed: Date | null; @@ -25,7 +25,7 @@ export class MmpMap { @Column({ type: 'uuid', nullable: true, default: null }) @Generated('uuid') - modificationSecret: string | null = null; + modificationSecret: string | null; @Column({ type: 'varchar', nullable: true }) name: string | null; @@ -42,5 +42,5 @@ export class MmpMap { nodes: MmpNode[]; @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) - createdAt: Date | null = new Date(); + createdAt: Date | null; } \ No newline at end of file diff --git a/teammapper-backend/src/map/entities/mmpNode.entity.ts b/teammapper-backend/src/map/entities/mmpNode.entity.ts index ab7e162a..9309a0b8 100644 --- a/teammapper-backend/src/map/entities/mmpNode.entity.ts +++ b/teammapper-backend/src/map/entities/mmpNode.entity.ts @@ -45,11 +45,11 @@ export class MmpNode { @IsDefined() root: boolean = false; - @Column({ type: 'float8' }) + @Column({ type: 'float' }) @IsDefined() coordinatesX: number; - @Column({ type: 'float8' }) + @Column({ type: 'float' }) @IsDefined() coordinatesY: number; @@ -103,10 +103,10 @@ export class MmpNode { orderNumber: number; @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) - lastModified: Date | null = new Date(); + lastModified: Date | null; @Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' }) - createdAt: Date | null = new Date(); + createdAt: Date | null; @BeforeInsert() @BeforeUpdate() From fb89e7c094da0645e07fcf87cc419b5ec9123b9f Mon Sep 17 00:00:00 2001 From: sorenjohanson Date: Wed, 20 Nov 2024 10:32:15 +0000 Subject: [PATCH 3/3] fix: defaults --- .../src/map/controllers/maps.gateway.spec.ts | 3 --- teammapper-backend/src/map/entities/mmpNode.entity.ts | 8 ++++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/teammapper-backend/src/map/controllers/maps.gateway.spec.ts b/teammapper-backend/src/map/controllers/maps.gateway.spec.ts index 2dedb6d6..fc356f2b 100644 --- a/teammapper-backend/src/map/controllers/maps.gateway.spec.ts +++ b/teammapper-backend/src/map/controllers/maps.gateway.spec.ts @@ -139,10 +139,7 @@ describe('WebSocketGateway', () => { // Date objects are serialised to JSON in the result, so we'll need to be explicit in setting these here const defaultNode = { "createdAt": new Date('2021-01-31T00:00:00.000Z').toISOString(), - "detached": false, - "imageSize": 60, "lastModified": new Date('2021-01-31T00:00:00.000Z').toISOString(), - "root": false } socket.emit( diff --git a/teammapper-backend/src/map/entities/mmpNode.entity.ts b/teammapper-backend/src/map/entities/mmpNode.entity.ts index 9309a0b8..ce0815c7 100644 --- a/teammapper-backend/src/map/entities/mmpNode.entity.ts +++ b/teammapper-backend/src/map/entities/mmpNode.entity.ts @@ -43,7 +43,7 @@ export class MmpNode { @Column({ type: 'boolean', default: false }) @IsDefined() - root: boolean = false; + root: boolean; @Column({ type: 'float' }) @IsDefined() @@ -75,7 +75,7 @@ export class MmpNode { imageSrc: string | null; @Column({ type: 'integer', nullable: true, default: 60 }) - imageSize: number | null = 60; + imageSize: number | null; @Column({ type: 'varchar', nullable: true }) linkHref: string | null; @@ -85,9 +85,9 @@ export class MmpNode { @Column({ type: 'boolean', default: false }) @IsDefined() - detached: boolean = false; + detached: boolean; - @Column({ type: 'float8', nullable: true }) + @Column({ type: 'float', nullable: true }) k: number | null; @PrimaryColumn('uuid')