Skip to content

Commit

Permalink
fix: Catching edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Dec 13, 2019
1 parent f73b435 commit 3c1a935
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions packages/daf-data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { DbDriver } from './types'
import { runMigrations } from './migrations'
import sql from 'sql-bricks-sqlite'
import blake from 'blakejs'
import Debug from 'debug'

const debug = Debug('daf:data-store')

export class DataStore {
private db: DbDriver
Expand Down Expand Up @@ -290,23 +293,26 @@ export class DataStore {
if (searchResult.length > 0) {
this.updateMetaData(message)
} else {
const query = sql
.insert('messages', {
id: messageId,
sender: message.sender,
receiver: message.receiver,
timestamp: message.timestamp,
type: message.type,
thread_id: message.threadId,
raw: message.raw,
data: message.data && JSON.stringify(message.data),
})
.toParams()

await this.db.run(query.text, query.values)
try {
const query = sql
.insert('messages', {
id: messageId,
sender: message.sender,
receiver: message.receiver,
timestamp: message.timestamp,
type: message.type,
thread_id: message.threadId,
raw: message.raw,
data: message.data && JSON.stringify(message.data),
})
.toParams()

await this.saveMetaData(message)
await this.saveVerifiableCredentials(message)
await this.db.run(query.text, query.values)
await this.saveMetaData(message)
await this.saveVerifiableCredentials(message)
} catch (e) {
debug(e.message)
}
}

return { hash: message.id, iss: { did: message.sender } }
Expand Down

0 comments on commit 3c1a935

Please sign in to comment.