mirror of
https://github.com/kennethnym/freya
synced 2026-07-05 15:31:14 +01:00
feat: seed default user sources (#128)
This commit is contained in:
30
apps/freya-backend/src/sources/default-sources.ts
Normal file
30
apps/freya-backend/src/sources/default-sources.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { LocationSource } from "@freya/source-location"
|
||||
import { WebSearchSource } from "@freya/source-web-search"
|
||||
|
||||
import type { Database } from "../db/index.ts"
|
||||
|
||||
import { userSources } from "../db/schema.ts"
|
||||
|
||||
export const DEFAULT_ENABLED_SOURCE_IDS = [LocationSource.id, WebSearchSource.id] as const
|
||||
|
||||
export type DefaultEnabledSourceId = (typeof DEFAULT_ENABLED_SOURCE_IDS)[number]
|
||||
|
||||
export async function insertDefaultUserSources(db: Database, userId: string): Promise<void> {
|
||||
const now = new Date()
|
||||
|
||||
await db
|
||||
.insert(userSources)
|
||||
.values(
|
||||
DEFAULT_ENABLED_SOURCE_IDS.map((sourceId) => ({
|
||||
userId,
|
||||
sourceId,
|
||||
enabled: true,
|
||||
config: {},
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})),
|
||||
)
|
||||
.onConflictDoNothing({
|
||||
target: [userSources.userId, userSources.sourceId],
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user