mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-30 14:51:17 +01:00
feat(backend): add PUT /api/sources/:sourceId
Add a PUT endpoint that inserts or fully replaces a user's source config. Unlike PATCH (which deep-merges and requires an existing row), PUT requires both `enabled` and `config`, performs an upsert via INSERT ... ON CONFLICT DO UPDATE, and replaces config entirely. - Add `upsertConfig` to user-sources data layer - Add `upsertSourceConfig` to UserSessionManager - Add `addSource` to UserSession for new source registration - 12 new tests covering insert, replace, validation, and session refresh Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -72,6 +72,29 @@ export function sources(db: Database, userId: string) {
|
||||
}
|
||||
},
|
||||
|
||||
/** Inserts a new user source row or fully replaces enabled/config on an existing one. */
|
||||
async upsertConfig(sourceId: string, data: { enabled: boolean; config: unknown }) {
|
||||
const now = new Date()
|
||||
await db
|
||||
.insert(userSources)
|
||||
.values({
|
||||
userId,
|
||||
sourceId,
|
||||
enabled: data.enabled,
|
||||
config: data.config,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
target: [userSources.userId, userSources.sourceId],
|
||||
set: {
|
||||
enabled: data.enabled,
|
||||
config: data.config,
|
||||
updatedAt: now,
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
/** Updates the encrypted credentials for a source. Throws if the source row doesn't exist. */
|
||||
async updateCredentials(sourceId: string, credentials: Buffer) {
|
||||
const rows = await db
|
||||
|
||||
Reference in New Issue
Block a user