Edit endpoint
This commit is contained in:
parent
2f8f6cae24
commit
b262deb7cf
|
@ -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 }
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue