This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { | ||
CamelCasedPropertiesDeep, | ||
SetOptional, | ||
} from "type-fest"; | ||
import { | ||
queryEventLogEntriesCreate, | ||
queryEventLogEntriesGetAll, | ||
queryEventLogEntriesGetByEvent, | ||
} from "../../db/helpers/eventLogEntries"; | ||
import type { | ||
EventLogEntry as DbEventLogEntry, | ||
} from "../../db/helpers/eventLogEntries"; | ||
import { | ||
Client, | ||
} from "../../db/methods"; | ||
import { | ||
keysFromSnakeToCamelCase, | ||
} from "../../helpers/object"; | ||
|
||
export type EventLogEntry = SetOptional<CamelCasedPropertiesDeep<DbEventLogEntry>, "scannedAt">; | ||
|
||
export default class EntryLogService { | ||
public static async create(entry: EventLogEntry): Promise<EventLogEntry | null> { | ||
const data = await Client.queryOneOnce<DbEventLogEntry>(queryEventLogEntriesCreate(entry)); | ||
|
||
return keysFromSnakeToCamelCase(data); | ||
} | ||
|
||
public static async list(): Promise<EventLogEntry[]> { | ||
const list = await Client.queryOnce<DbEventLogEntry>(queryEventLogEntriesGetAll()); | ||
|
||
if (!list) { | ||
return []; | ||
} | ||
|
||
return keysFromSnakeToCamelCase(list); | ||
} | ||
|
||
public static async forEvent(eventId: EventLogEntry["eventId"], eventType: EventLogEntry["eventType"]): Promise<EventLogEntry[]> { | ||
const list = await Client.queryOnce<DbEventLogEntry>(queryEventLogEntriesGetByEvent({ | ||
eventId, | ||
eventType, | ||
})); | ||
|
||
if (!list) { | ||
return []; | ||
} | ||
|
||
return keysFromSnakeToCamelCase(list); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters