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 5ce04e5
Show file tree
Hide file tree
Showing 3 changed files with 16 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
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10854,6 +10854,11 @@ uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2, uuid@^3.3.3:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

uuid@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-7.0.2.tgz#7ff5c203467e91f5e0d85cfcbaaf7d2ebbca9be6"
integrity sha512-vy9V/+pKG+5ZTYKf+VcphF5Oc6EFiu3W8Nv3P3zIh0EqVI80ZxOzuPfe9EHjkFNvf8+xuTHVeei4Drydlx4zjw==

v8-to-istanbul@^4.0.1:
version "4.1.2"
resolved "https://registry.yarnpkg.com/v8-to-istanbul/-/v8-to-istanbul-4.1.2.tgz#387d173be5383dbec209d21af033dcb892e3ac82"
Expand Down

0 comments on commit 5ce04e5

Please sign in to comment.