0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00

refactor(core): reduce parameter

This commit is contained in:
Gao Sun 2023-10-14 20:17:07 +08:00
parent e6d3db6e80
commit 34ca8b9c6f
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
3 changed files with 11 additions and 12 deletions

View file

@ -3,7 +3,6 @@ import {
type OrganizationRole, type OrganizationRole,
type OrganizationRoleKeys, type OrganizationRoleKeys,
OrganizationRoles, OrganizationRoles,
OrganizationScopes,
} from '@logto/schemas'; } from '@logto/schemas';
import { UniqueIntegrityConstraintViolationError } from 'slonik'; import { UniqueIntegrityConstraintViolationError } from 'slonik';
import { z } from 'zod'; import { z } from 'zod';
@ -85,7 +84,7 @@ export default function organizationRoleRoutes<T extends AuthedRouter>(
} }
); );
router.addRelationRoutes(OrganizationScopes, rolesScopes, 'scopes'); router.addRelationRoutes(rolesScopes, 'scopes');
originalRouter.use(router.routes()); originalRouter.use(router.routes());
} }

View file

@ -1,4 +1,4 @@
import { Organizations, Users } from '@logto/schemas'; import { Organizations } from '@logto/schemas';
import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js'; import SchemaRouter, { SchemaActions } from '#src/utils/SchemaRouter.js';
@ -14,7 +14,7 @@ export default function organizationRoutes<T extends AuthedRouter>(
) { ) {
const router = new SchemaRouter(Organizations, new SchemaActions(organizations)); const router = new SchemaRouter(Organizations, new SchemaActions(organizations));
router.addRelationRoutes(Users, organizations.relations.users); router.addRelationRoutes(organizations.relations.users);
originalRouter.use(router.routes()); originalRouter.use(router.routes());
} }

View file

@ -268,21 +268,21 @@ export default class SchemaRouter<
* singular form with `Ids` suffix. For example, if the relation schema's table name is * singular form with `Ids` suffix. For example, if the relation schema's table name is
* `organization_roles`, the `[relationSchemaIds]` will be `organizationRoleIds`. * `organization_roles`, the `[relationSchemaIds]` will be `organizationRoleIds`.
* *
* @param relationSchema The schema of the relation to be added. * @param relationQueries The queries class for the relation.
* @param relationQueries The queries for the relation.
* @param pathname The pathname of the relation. If not provided, it will be * @param pathname The pathname of the relation. If not provided, it will be
* the camel case of the relation schema's table name. * the camel case of the relation schema's table name.
* @see {@link RelationQueries} for the `relationQueries` configuration. * @see {@link RelationQueries} for the `relationQueries` configuration.
*/ */
addRelationRoutes< addRelationRoutes<
RelationKey extends string, RelationCreateSchema extends Partial<SchemaLike<string> & { id: string }>,
RelationCreateSchema extends Partial<SchemaLike<RelationKey> & { id: string }>, RelationSchema extends SchemaLike<string> & { id: string },
RelationSchema extends SchemaLike<RelationKey> & { id: string },
>( >(
relationSchema: GeneratedSchema<RelationKey, RelationCreateSchema, RelationSchema>, relationQueries: RelationQueries<
relationQueries: RelationQueries<[typeof this.schema, typeof relationSchema]>, [typeof this.schema, GeneratedSchema<string, RelationCreateSchema, RelationSchema>]
pathname = tableToPathname(relationSchema.table) >,
pathname = tableToPathname(relationQueries.schemas[1].table)
) { ) {
const relationSchema = relationQueries.schemas[1];
const columns = { const columns = {
schemaId: camelCaseSchemaId(this.schema), schemaId: camelCaseSchemaId(this.schema),
relationSchemaId: camelCaseSchemaId(relationSchema), relationSchemaId: camelCaseSchemaId(relationSchema),