Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikskog committed May 10, 2024
1 parent 0109208 commit 71f8de3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 7 additions & 1 deletion packages/core/src/modules/asset/asset-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ import {
import type { ExpressionBuilder, Kysely } from "kysely"
import { jsonObjectFrom } from "kysely/helpers/postgres"
import { IllegalStateError } from "../../error"
import { type Cursor, fixJsonDatesStandardCols, type Keys, orderedQuery, withInsertJsonValue } from "../../utils/db-utils"
import {
type Cursor,
type Keys,
fixJsonDatesStandardCols,
orderedQuery,
withInsertJsonValue,
} from "../../utils/db-utils"

export interface AssetRepository {
getFileAsset(key: string): Promise<FileAsset>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/offline/offline-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { DB } from "@dotkomonline/db/src/db.generated"
import { type Offline, type OfflineId, OfflineSchema, type OfflineWrite } from "@dotkomonline/types"
import type { ExpressionBuilder, Kysely } from "kysely"
import { jsonObjectFrom } from "kysely/helpers/postgres"
import { type Cursor, fixJsonDatesStandardCols, type Keys, orderedQuery } from "../../utils/db-utils"
import { type Cursor, type Keys, fixJsonDatesStandardCols, orderedQuery } from "../../utils/db-utils"
import { fileAssetCols, imageAssetCols } from "../asset/asset-repository"

export interface OfflineRepository {
Expand Down
23 changes: 11 additions & 12 deletions packages/core/src/utils/db-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,38 @@ export function withInsertJsonValue<T extends object, K extends keyof T>(

// https://node-postgres.com/features/types#date--timestamp--timestamptz deserialized datetime fields automatically, but when using json_build_object, the createdAt field is returned as a string instead of being parsed as a Date.
// This function deserializes datetime fields to js Date objects if they are present in the result.
export const fixJsonDatesStandardCols = <T extends { createdAt?: string | Date, updatedAt?: string | Date }>(obj?: T | null | undefined) : T =>{
let final = {

}
if(obj?.createdAt instanceof Date) {
export const fixJsonDatesStandardCols = <T extends { createdAt?: string | Date; updatedAt?: string | Date }>(
obj?: T | null | undefined
): T => {
let final = {}
if (obj?.createdAt instanceof Date) {
final = {
createdAt: new Date(obj.createdAt)
createdAt: new Date(obj.createdAt),
}
}

if(obj?.updatedAt instanceof Date) {
if (obj?.updatedAt instanceof Date) {
final = {
...final,
updatedAt: new Date(obj.updatedAt)
updatedAt: new Date(obj.updatedAt),
}
}

if(!obj) return {} as T
if (!obj) return {} as T

return {
...obj,
...final
...final,
}
}

export const fixDate = <T>(obj: T, prop: keyof T) => {
return {
...obj,
[prop]: new Date(obj[prop] as string)
[prop]: new Date(obj[prop] as string),
}
}


export const CursorSchema = z.object({
id: z.string().ulid(),
})
Expand Down

0 comments on commit 71f8de3

Please sign in to comment.