Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
HYP-13: a few build errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3op2 committed Nov 16, 2023
1 parent 2546041 commit 2000069
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
1 change: 1 addition & 0 deletions .depcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ignores: [
"nodemon",
"multer",
"pg",
"undici",
]
7 changes: 3 additions & 4 deletions src/controllers/v1/attachment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,18 @@ export class attachment extends Controller {
const fileBlob = new Blob([Buffer.from(file?.buffer || JSON.stringify(req.body))])
const ipfsHash = await this.ipfs.addFile({ blob: fileBlob, filename })

const [{ id, createdAt }] = await this.db.insert('attachment', {
const [{ id, created_at }] = await this.db.insert('attachment', {
filename,
ipfs_hash: ipfsHash,
size: fileBlob.size,
})

const result: Attachment = {
return {
id,
filename,
size: fileBlob.size,
createdAt,
createdAt: created_at,
}
return result
}

@Get('/{id}')
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/v1/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class TransactionController extends Controller {
@Query() apiType?: TransactionApiType,
@Query() status?: TransactionState,
@Query() updated_since?: DATE
): Promise<TransactionResponse[]> {
): Promise<void> {
const query: { state?: TransactionState; apiType?: TransactionApiType; updatedSince?: Date } = {
state: status,
apiType,
Expand All @@ -41,7 +41,7 @@ export class TransactionController extends Controller {
query.updatedSince = parseDateParam(updated_since)
}

return await this.db.get('transaction', query)
return this.db.get('transaction', query)
}

/**
Expand All @@ -51,8 +51,7 @@ export class TransactionController extends Controller {
@Response<NotFound>(404, 'Item not found')
@Get('{id}')
public async getTransaction(@Path() id: UUID): Promise<TransactionResponse> {
const [transaction] = await this.db.get('transaction', { id })
if (!transaction) throw new NotFound('transaction')
const transaction = await this.db.get('transaction', { id }).then((transactions) => transactions[0])

return transaction
}
Expand Down
16 changes: 11 additions & 5 deletions src/lib/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import knex, { Knex } from 'knex'
import { pgConfig } from './knexfile'
import { HEX, UUID } from '../../models/strings'
import { TransactionApiType, TransactionState, TransactionType } from '../../models/transaction'
import { NotFound } from '../error-handler'

const tablesList = ['attachment', 'example', 'transaction', 'processed_blocks'] as const
type TABLES_TUPLE = typeof tablesList
Expand Down Expand Up @@ -64,15 +65,16 @@ export default class Database {
}

// generics methods
insert = async (model: keyof Models<() => QueryBuilder>, record: Record<string, string>): Promise<void> => {
insert = async (model: keyof Models<() => QueryBuilder>, record: Record<string, string | number>) => {
const query = this.db()[model]
await query().insert(record)

return query().insert(record).returning('*')
}

update = async (
model: keyof Models<() => QueryBuilder>,
where: Record<string, string>,
updates: Record<string, string>
updates: Record<string, string | number>
): Promise<Record<string, string>[]> => {
const query = this.db()[model]
return query()
Expand All @@ -84,9 +86,13 @@ export default class Database {
.returning('*')
}

get = async (model: keyof Models<() => QueryBuilder>, where: Record<string, string> = {}): Promise<void> => {
get = async (model: keyof Models<() => QueryBuilder>, where: Record<string, string | number | Date> = {}) => {
const query = this.db()[model]
await query().where(where)
const result = query().where(where)

if (!result) throw new NotFound(model)

return result
}

// for event processor indexer
Expand Down
4 changes: 2 additions & 2 deletions src/lib/indexer/eventProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { v4 as UUIDv4 } from 'uuid'

import { UUID } from '../../models/strings'
import { Transaction } from '../db'
import { TransactionRow } from '../db'
import { AttachmentRecord, ChangeSet, ExampleRecord } from './changeSet'

const processNames = ['example-create'] as const
Expand All @@ -15,7 +15,7 @@ export const ValidateProcessName = (name: string): name is PROCESSES => processN
export type EventProcessors = {
[key in PROCESSES]: (
version: number,
transaction: Transaction | null,
transaction: TransactionRow | null,
sender: string,
inputs: { id: number; localId: UUID }[],
outputs: { id: number; roles: Map<string, string>; metadata: Map<string, string> }[]
Expand Down
8 changes: 4 additions & 4 deletions src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export type TransactionState = 'submitted' | 'inBlock' | 'finalised' | 'failed'
export interface TransactionResponse {
id: UUID
state: TransactionState
apiType: TransactionApiType
transactionType: TransactionType
submittedAt: Date
updatedAt: Date
api_type: TransactionApiType
transaction_type: TransactionType
submitted_at: Date
updated_at: Date
}

/**
Expand Down

0 comments on commit 2000069

Please sign in to comment.