From 34ca8b9c6f61c4c3769d166f067e72689aa4df54 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Sat, 14 Oct 2023 20:17:07 +0800 Subject: [PATCH] refactor(core): reduce parameter --- packages/core/src/routes/organization-roles.ts | 3 +-- packages/core/src/routes/organizations.ts | 4 ++-- packages/core/src/utils/SchemaRouter.ts | 16 ++++++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/core/src/routes/organization-roles.ts b/packages/core/src/routes/organization-roles.ts index 8a33d0789..c5b2f4cc0 100644 --- a/packages/core/src/routes/organization-roles.ts +++ b/packages/core/src/routes/organization-roles.ts @@ -3,7 +3,6 @@ import { type OrganizationRole, type OrganizationRoleKeys, OrganizationRoles, - OrganizationScopes, } from '@logto/schemas'; import { UniqueIntegrityConstraintViolationError } from 'slonik'; import { z } from 'zod'; @@ -85,7 +84,7 @@ export default function organizationRoleRoutes( } ); - router.addRelationRoutes(OrganizationScopes, rolesScopes, 'scopes'); + router.addRelationRoutes(rolesScopes, 'scopes'); originalRouter.use(router.routes()); } diff --git a/packages/core/src/routes/organizations.ts b/packages/core/src/routes/organizations.ts index 862e9ffb0..4ac17f014 100644 --- a/packages/core/src/routes/organizations.ts +++ b/packages/core/src/routes/organizations.ts @@ -1,4 +1,4 @@ -import { Organizations, Users } from '@logto/schemas'; +import { Organizations } from '@logto/schemas'; import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js'; @@ -14,7 +14,7 @@ export default function organizationRoutes( ) { const router = new SchemaRouter(Organizations, new SchemaActions(organizations)); - router.addRelationRoutes(Users, organizations.relations.users); + router.addRelationRoutes(organizations.relations.users); originalRouter.use(router.routes()); } diff --git a/packages/core/src/utils/SchemaRouter.ts b/packages/core/src/utils/SchemaRouter.ts index a2c51017b..760d78cbf 100644 --- a/packages/core/src/utils/SchemaRouter.ts +++ b/packages/core/src/utils/SchemaRouter.ts @@ -268,21 +268,21 @@ export default class SchemaRouter< * singular form with `Ids` suffix. For example, if the relation schema's table name is * `organization_roles`, the `[relationSchemaIds]` will be `organizationRoleIds`. * - * @param relationSchema The schema of the relation to be added. - * @param relationQueries The queries for the relation. + * @param relationQueries The queries class for the relation. * @param pathname The pathname of the relation. If not provided, it will be * the camel case of the relation schema's table name. * @see {@link RelationQueries} for the `relationQueries` configuration. */ addRelationRoutes< - RelationKey extends string, - RelationCreateSchema extends Partial & { id: string }>, - RelationSchema extends SchemaLike & { id: string }, + RelationCreateSchema extends Partial & { id: string }>, + RelationSchema extends SchemaLike & { id: string }, >( - relationSchema: GeneratedSchema, - relationQueries: RelationQueries<[typeof this.schema, typeof relationSchema]>, - pathname = tableToPathname(relationSchema.table) + relationQueries: RelationQueries< + [typeof this.schema, GeneratedSchema] + >, + pathname = tableToPathname(relationQueries.schemas[1].table) ) { + const relationSchema = relationQueries.schemas[1]; const columns = { schemaId: camelCaseSchemaId(this.schema), relationSchemaId: camelCaseSchemaId(relationSchema),