Skip to content
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

Chore: Correct Typescript types in backend entities #565

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions teammapper-backend/src/map/controllers/maps.gateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -133,15 +136,21 @@ 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(),
"lastModified": new Date('2021-01-31T00:00:00.000Z').toISOString(),
}

socket.emit(
'removeNode',
{
mapId: map.id,
modificationSecret: map.modificationSecret,
node: {},
node: defaultNode,
},
(result: MmpNode | undefined) => {
expect(result).toEqual({})
expect(result).toEqual(defaultNode)
done()
}
)
Expand Down
39 changes: 20 additions & 19 deletions teammapper-backend/src/map/entities/mmpMap.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

@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;

@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;
}
100 changes: 47 additions & 53 deletions teammapper-backend/src/map/entities/mmpNode.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,106 +17,100 @@ 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([
{ name: 'nodeMapId', referencedColumnName: 'nodeMapId' },
{ 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;

@Column({ type: 'float' })
@IsDefined()
coordinatesX: number
coordinatesX: number;

@Column({ type: 'float' })
@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;

@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;

@Column({ nullable: true, type: 'float' })
k: number
@Column({ type: 'float', 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;

@Column({ type: 'timestamptz', default: () => 'now()', nullable: true })
createdAt: Date
@Column({ type: 'timestamptz', nullable: true, default: () => 'CURRENT_TIMESTAMP' })
createdAt: Date | null;

@BeforeInsert()
@BeforeUpdate()
async validate() {
await validateOrReject(this);
}
}
}
2 changes: 1 addition & 1 deletion teammapper-backend/src/map/services/maps.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('MapsController', () => {
})

expect(updatedNode?.lastModified).not.toEqual(oldDate)
expect(updatedNode?.lastModified.getTime()).toBeGreaterThan(
expect(updatedNode?.lastModified!.getTime()).toBeGreaterThan(
timeBeforeUpdate.getTime()
)
})
Expand Down
32 changes: 16 additions & 16 deletions teammapper-backend/src/map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,43 +16,43 @@ 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 {
coordinates: IMmpClientCoordinates
detached: boolean
id: string
k: number
link: { href: string }
link: { href: string | null }
locked: boolean
parent: string
parent: string | null
isRoot: boolean
}

Expand Down Expand Up @@ -119,6 +119,6 @@ export interface IMmpClientMapCreateRequest {
}

export interface IMmpClientDeleteRequest {
adminId: string
adminId: string | null
mapId: string
}
Loading