Skip to content

Commit

Permalink
fix: Generating message.id if not set
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 23, 2020
1 parent 5933e50 commit fabf5f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/daf-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"blakejs": "^1.1.0",
"debug": "^4.1.1",
"events": "^3.0.0",
"typeorm": "^0.2.24"
"typeorm": "^0.2.24",
"uuid": "^7.0.2"
},
"devDependencies": {
"@types/debug": "^4.1.5",
Expand Down
9 changes: 9 additions & 0 deletions packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
JoinTable,
CreateDateColumn,
UpdateDateColumn,
BeforeInsert,
} from 'typeorm'
import { Identity } from './identity'
import { Presentation } from './presentation'
import { Credential } from './credential'
import { v4 as uuidv4 } from 'uuid'

export interface MetaData {
type: string
Expand All @@ -30,6 +32,13 @@ export class Message extends BaseEntity {
}
}

@BeforeInsert()
generateId() {
if (!this.id) {
this.id = uuidv4()
}
}

@PrimaryColumn()
id: string

Expand Down

0 comments on commit fabf5f6

Please sign in to comment.