Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
owl352 committed Dec 30, 2024
1 parent baceeea commit bd25ed0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/api/src/dao/DocumentsDAO.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Document = require('../models/Document')
const PaginatedResultSet = require('../models/PaginatedResultSet')
const DocumentTransaction = require('../models/DocumentTransaction')
const DocumentActionEnum = require('../enums/DocumentActionEnum')
const { decodeStateTransition } = require('../utils')

Expand Down Expand Up @@ -154,11 +155,14 @@ module.exports = class DocumentsDAO {

const rows = await this.knex(subquery)
.select('revision', 'gas_used', 'subquery.owner', 'hash', 'timestamp', 'transition_type', 'data')
.select(this.knex(subquery).count('*').as('total_count'))
.whereBetween('rank', [fromRank, toRank])
.orderBy('id', order)

console.log()
const [row] = rows

const totalCount = row?.total_count

return rows
return new PaginatedResultSet(rows.map(DocumentTransaction.fromRow), page, limit, Number(totalCount))
}
}
24 changes: 24 additions & 0 deletions packages/api/src/models/DocumentTransaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = class DocumentTransaction {
revision
gasUsed
owner
hash
timestamp
transitionType
data

constructor (revision, gasUsed, owner, hash, timestamp, transitionType, data) {
this.revision = revision ?? null
this.gasUsed = gasUsed ?? null
this.owner = owner ?? null
this.hash = hash ?? null
this.timestamp = timestamp ?? null
this.transitionType = transitionType ?? null
this.data = data ?? null
}

/* eslint-disable-next-line camelcase */
static fromRow ({ revision, gas_used, owner, hash, timestamp, transition_type, data, total_count }) {
return new DocumentTransaction(Number(revision), Number(gas_used), owner, hash, timestamp, Number(transition_type), data, Number(total_count))
}
}
22 changes: 22 additions & 0 deletions packages/api/test/integration/documents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ describe('Documents routes', () => {
})
})

describe('getDocumentTransactions()', async () => {
it('should return document transactions by identifier', async () => {
const [document] = documents.filter(e => !e.document.is_system)

const { body } = await client.get(`/document/${document.document.identifier}/transactions`)
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')

const expectedDocument = {
revision: document.document.revision,
gasUsed: document.transaction.gas_used,
owner: document.transaction.owner,
hash: document.transaction.hash,
timestamp: document.block.timestamp.toISOString(),
transitionType: document.document.transition_type,
data: {}
}

assert.deepEqual(body.resultSet, [expectedDocument])
})
})

describe('getDocumentsByDataContract()', async () => {
it('should return default set of documents', async () => {
const { body } = await client.get(`/dataContract/${dataContract.identifier}/documents`)
Expand Down

0 comments on commit bd25ed0

Please sign in to comment.