Edit endpoint

This commit is contained in:
Adria Navarro 2025-03-17 13:17:49 +01:00
parent 2f8f6cae24
commit b262deb7cf
3 changed files with 42 additions and 0 deletions

View File

@ -36,3 +36,20 @@ export async function create(
ctx.status = 201
ctx.body = { config }
}
export async function edit(
ctx: Ctx<CreateOAuth2ConfigRequest, CreateOAuth2ConfigResponse>
) {
const { body } = ctx.request
const toUpdate: RequiredKeys<OAuth2Config> = {
id: ctx.params.id,
name: body.name,
url: body.url,
clientId: ctx.clientId,
clientSecret: ctx.clientSecret,
}
const config = await sdk.oauth2.update(toUpdate)
ctx.status = 201
ctx.body = { config }
}

View File

@ -12,5 +12,11 @@ router.post(
authorized(PermissionType.BUILDER),
controller.create
)
router.put(
"/api/oauth2/:id",
authorized(PermissionType.BUILDER),
createOAauth2ConfigValidator(),
controller.create
)
export default router

View File

@ -48,3 +48,22 @@ export async function get(id: string): Promise<OAuth2Config | undefined> {
const doc = await getDocument()
return doc?.configs?.[id]
}
export async function update(config: OAuth2Config): Promise<OAuth2Config> {
const db = context.getAppDB()
const doc: OAuth2Configs = (await getDocument(db)) ?? {
_id: DocumentType.OAUTH2_CONFIG,
configs: {},
}
if (!doc.configs[config.id]) {
throw new HTTPError(`OAuth2 config with id '${config.id}' not found`, 400)
}
doc.configs[config.id] = {
...config,
}
await db.put(doc)
return doc.configs[config.id]
}