From e7fe20d32fa59c40ba854f4e69efae2195133b19 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Mon, 15 Jan 2024 08:26:25 +0800 Subject: [PATCH 1/2] feat(core): get and delete org invitation by id --- .../organization/invitations.openapi.json | 42 +++++++++++++++++++ .../src/routes/organization/invitations.ts | 29 ++++--------- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/packages/core/src/routes/organization/invitations.openapi.json b/packages/core/src/routes/organization/invitations.openapi.json index fd03467a6..12000d2a4 100644 --- a/packages/core/src/routes/organization/invitations.openapi.json +++ b/packages/core/src/routes/organization/invitations.openapi.json @@ -17,6 +17,48 @@ } } } + }, + "/api/organization-invitations/{id}": { + "get": { + "summary": "Get organization invitation", + "description": "Get an organization invitation by ID.", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The organization invitation ID.", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The organization invitation, also contains the organization roles to be assigned to the user when they accept the invitation, and the corresponding magic link data." + } + } + }, + "delete": { + "summary": "Delete organization invitation", + "description": "Delete an organization invitation by ID.", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The organization invitation ID.", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "204": { + "description": "The organization invitation was deleted successfully." + } + } + } } } } diff --git a/packages/core/src/routes/organization/invitations.ts b/packages/core/src/routes/organization/invitations.ts index fa134f94d..70be05bfa 100644 --- a/packages/core/src/routes/organization/invitations.ts +++ b/packages/core/src/routes/organization/invitations.ts @@ -1,9 +1,6 @@ -import { OrganizationInvitations, organizationInvitationEntityGuard } from '@logto/schemas'; -import Router, { type IRouterParamContext } from 'koa-router'; +import { OrganizationInvitations } from '@logto/schemas'; -import koaGuard from '#src/middleware/koa-guard.js'; -import koaPagination from '#src/middleware/koa-pagination.js'; -import { tableToPathname } from '#src/utils/SchemaRouter.js'; +import SchemaRouter from '#src/utils/SchemaRouter.js'; import { type AuthedRouter, type RouterInitArgs } from '../types.js'; @@ -17,24 +14,12 @@ export default function organizationInvitationRoutes( }, ]: RouterInitArgs ) { - const router = new Router({ - prefix: '/' + tableToPathname(OrganizationInvitations.table), + const router = new SchemaRouter(OrganizationInvitations, invitations, { + disabled: { + post: true, + patchById: true, + }, }); - router.get( - '/', - koaPagination(), - koaGuard({ response: organizationInvitationEntityGuard.array(), status: [200] }), - async (ctx, next) => { - const { limit, offset } = ctx.pagination; - const [count, entities] = await invitations.findAll(limit, offset); - - ctx.pagination.totalCount = count; - ctx.body = entities; - ctx.status = 200; - return next(); - } - ); - originalRouter.use(router.routes()); } From 44d8717bd7d93e5453faa56915f6fa9abd005106 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Mon, 15 Jan 2024 11:13:24 +0800 Subject: [PATCH 2/2] refactor: fix swagger --- packages/core/src/routes/swagger/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/routes/swagger/index.ts b/packages/core/src/routes/swagger/index.ts index e6aa7974d..97b5a1099 100644 --- a/packages/core/src/routes/swagger/index.ts +++ b/packages/core/src/routes/swagger/index.ts @@ -128,6 +128,7 @@ const identifiableEntityNames = [ 'organization', 'organization-role', 'organization-scope', + 'organization-invitation', ]; /**