Skip to content

Commit

Permalink
Replace toISOString calls with io-ts codec (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukstv authored Apr 11, 2023
1 parent ccd6729 commit e78e8b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/__tests__/knex-timestamps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { test, expect, beforeAll, afterAll } from '@jest/globals'
import type { Knex } from 'knex'
import { createDbConnection } from '../db-connection.js'
import { isClose, randomStreamID, seconds } from './test-utils.js'
import * as te from '../ancillary/io-ts-extra.js'

let dbConnection: Knex

Expand Down Expand Up @@ -41,9 +42,9 @@ test('JS-to-PG conversion ignores timezone', async () => {
.insert({
streamId: randomStreamID().toString(),
metadata: {},
usedAt: withTimezone.toISOString(),
usedAt: te.date.encode(withTimezone),
})
.returning('usedAt')
.then((rows) => rows[0].usedAt as Date)
expect(pgTimestamp1.toISOString()).toEqual('2023-01-01T19:04:05.678Z')
expect(te.date.encode(pgTimestamp1)).toEqual('2023-01-01T19:04:05.678Z')
})
8 changes: 4 additions & 4 deletions src/models/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type IDBRequest = {
streamId: string
message: string
pinned: boolean
timestamp: string
timestamp?: string
createdAt?: string
updatedAt?: string
origin?: string
Expand Down Expand Up @@ -87,9 +87,9 @@ export class Request {
streamId: this.streamId.toString(),
message: this.message,
pinned: this.pinned,
createdAt: this.createdAt?.toISOString(),
updatedAt: this.updatedAt?.toISOString(),
timestamp: this.timestamp?.toISOString(),
createdAt: this.createdAt ? te.date.encode(this.createdAt) : undefined,
updatedAt: this.updatedAt ? te.date.encode(this.updatedAt) : undefined,
timestamp: this.timestamp ? te.date.encode(this.timestamp) : undefined,
origin: this.origin,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/request-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class RequestRepository {
message: fields.message,
status: fields.status,
pinned: fields.pinned,
updatedAt: updatedAt.toISOString(),
updatedAt: te.date.encode(updatedAt),
})
.whereIn('id', ids)

Expand Down

0 comments on commit e78e8b6

Please sign in to comment.