mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
refactor: accept rest data while creating application
This commit is contained in:
parent
8902d66bde
commit
334cc5903a
1 changed files with 8 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
import Router from 'koa-router';
|
||||
import { nativeEnum, object, string } from 'zod';
|
||||
import { ApplicationType } from '@logto/schemas';
|
||||
import { object, string } from 'zod';
|
||||
import { Applications } from '@logto/schemas';
|
||||
import koaGuard from '@/middleware/koa-guard';
|
||||
import { deleteApplicationById, insertApplication } from '@/queries/application';
|
||||
import { buildIdGenerator } from '@/utils/id';
|
||||
|
@ -12,19 +12,20 @@ export default function applicationRoutes<StateT, ContextT>(router: Router<State
|
|||
router.post(
|
||||
'/application',
|
||||
koaGuard({
|
||||
body: object({
|
||||
name: string().min(1),
|
||||
type: nativeEnum(ApplicationType),
|
||||
}),
|
||||
body: Applications.guard
|
||||
.omit({ id: true, createdAt: true })
|
||||
.partial()
|
||||
.merge(Applications.guard.pick({ name: true, type: true })),
|
||||
}),
|
||||
async (ctx, next) => {
|
||||
const { name, type } = ctx.guard.body;
|
||||
const { name, type, ...rest } = ctx.guard.body;
|
||||
|
||||
ctx.body = await insertApplication({
|
||||
id: applicationId(),
|
||||
type,
|
||||
name,
|
||||
oidcClientMetadata: generateOidcClientMetadata(),
|
||||
...rest,
|
||||
});
|
||||
return next();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue