Skip to content

feat(core): add management APIs for custom profile fields #7446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

charIeszhao
Copy link
Member

Summary

Add management APIs for custom profile fields.

Testing

Locally tested. Unit tests and API tests will be added in the follow-up PR.

Checklist

- [ ] .changeset
- [ ] unit tests
- [ ] integration tests
- [ ] necessary TSDoc comments

@charIeszhao charIeszhao requested a review from Copilot June 11, 2025 04:43
@charIeszhao charIeszhao self-assigned this Jun 11, 2025
Copy link

github-actions bot commented Jun 11, 2025

COMPARE TO master

Total Size Diff ⚠️ 📈 +14.69 KB

Diff by File
Name Diff
packages/core/src/libraries/custom-profile-fields.ts 📈 +3.65 KB
packages/core/src/middleware/koa-slonik-error-handler.ts 📈 +220 Bytes
packages/core/src/queries/custom-profile-fields.ts 📈 +2.34 KB
packages/core/src/routes/custom-profile-fields.openapi.json 📈 +4.62 KB
packages/core/src/routes/custom-profile-fields.ts 📈 +3.15 KB
packages/core/src/routes/init.ts 📈 +173 Bytes
packages/core/src/routes/swagger/utils/documents.ts 📈 +26 Bytes
packages/core/src/routes/swagger/utils/general.ts 📈 +109 Bytes
packages/core/src/routes/swagger/utils/operation-id.ts 📈 +80 Bytes
packages/core/src/tenants/Libraries.ts 📈 +164 Bytes
packages/core/src/tenants/Queries.ts 📈 +159 Bytes
packages/schemas/alterations/next-1749724664-drop-sie-order-constraint-from-custom-profile-fields.ts 📈 +533 Bytes
packages/schemas/tables/custom_profile_fields.sql 📈 +81 Bytes

Copilot

This comment was marked as outdated.

@charIeszhao charIeszhao changed the base branch from master to charles-log-11676-error-messages June 11, 2025 04:43
@charIeszhao charIeszhao requested a review from Copilot June 11, 2025 04:44
@charIeszhao charIeszhao changed the title Charles log 11674 api implementation feat(core): add management APIs for custom profile fields Jun 11, 2025
@github-actions github-actions bot added the feature Cool stuff label Jun 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces management APIs for custom profile fields, including database queries, libraries, route handlers, and Swagger/OpenAPI integration.

  • Added custom profile fields queries and integrated them into the tenant Queries class.
  • Implemented business logic in a new library and exposed CRUD + ordering operations via Koa routes.
  • Updated Swagger utilities and added a standalone OpenAPI spec for the new endpoints.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/core/src/tenants/Queries.ts Imported and exposed customProfileFields queries
packages/core/src/tenants/Libraries.ts Imported and exposed customProfileFields library
packages/core/src/routes/swagger/utils/operation-id.ts Registered a dev feature operation ID for post /custom-profile-fields
packages/core/src/routes/swagger/utils/general.ts Added custom-profile-fields tag when dev features are enabled
packages/core/src/routes/swagger/utils/documents.ts Included “Custom profile fields” in additional Swagger tags
packages/core/src/routes/init.ts Mounted customProfileFieldsRoutes under the dev features flag
packages/core/src/routes/custom-profile-fields.ts Defined GET/POST/PATCH/DELETE/PUT routes for custom profile fields
packages/core/src/routes/custom-profile-fields.openapi.json Added OpenAPI definitions for the new endpoints
packages/core/src/queries/custom-profile-fields.ts Implemented SQL queries for custom profile fields management
packages/core/src/libraries/custom-profile-fields.ts Created library functions with validation and ordering logic
Comments suppressed due to low confidence (6)

packages/core/src/tenants/Libraries.ts:24

  • This import uses a relative path while other libraries in this module use the '#src/libraries/...' alias. Consider using a consistent import alias for clarity and maintainability.
import { createCustomProfileFieldsLibrary } from '../libraries/custom-profile-fields.js';

packages/core/src/routes/custom-profile-fields.openapi.json:40

  • The GET /api/custom-profile-fields/{id} spec only lists a 200 response but the implementation may return 400 or 404. Please update the OpenAPI responses to match possible status codes (400, 404).
"get": {

packages/core/src/routes/custom-profile-fields.openapi.json:50

  • The PATCH spec only documents a 200 response. The route guard allows 400 and 404—please include those in the OpenAPI response definitions for accuracy.
"patch": {

packages/core/src/routes/custom-profile-fields.openapi.json:69

  • The DELETE spec only documents a 204 response. The implementation may return 400 or 404—add those responses in the spec to stay in sync.
"delete": {

packages/core/src/routes/custom-profile-fields.ts:13

  • These new routes lack accompanying unit or integration tests. Please add tests for each endpoint, including error conditions, to meet coverage requirements.
export default function customProfileFieldsRoutes<T extends ManagementApiRouter>(

packages/core/src/routes/swagger/utils/operation-id.ts:31

  • Only the POST operation for custom-profile-fields is registered in devFeatureCustomRoutes. You may need to register the other CRUD routes (GET, PATCH, DELETE, PUT) to ensure consistent operation IDs in development mode.
'post /custom-profile-fields': 'CreateCustomProfileField',


// eslint-disable-next-line complexity
const validateCustomProfileField = (data: CreateCustomProfileFieldData) => {
switch (data.type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we define multiple classes or objects with key guard mapping to avoid complicated switching logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific? I'm afraid creating classes will complicate the situation even more

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe just an object? using data.type as key

);

router.patch(
'/custom-profile-fields/:id',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if the name or type is unique, it feels like using the field name or type is more handy than the ID.

Copy link
Member Author

@charIeszhao charIeszhao Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel using name instead of id is anti-pattern, since the name is user specified value and could be anything we allow to input into the DB. For example it might be CJK characters or other unicode values. Currently I don't check the input values of the name, or perhaps I should have?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline

@charIeszhao charIeszhao force-pushed the charles-log-11674-api-implementation branch from 61ee680 to 2b6f4da Compare June 11, 2025 11:13
@charIeszhao charIeszhao force-pushed the charles-log-11676-error-messages branch from 53ab629 to a584e27 Compare June 11, 2025 11:14
@charIeszhao charIeszhao force-pushed the charles-log-11674-api-implementation branch from 2b6f4da to 7a453ea Compare June 11, 2025 11:14
Base automatically changed from charles-log-11676-error-messages to master June 12, 2025 06:36
@charIeszhao charIeszhao force-pushed the charles-log-11674-api-implementation branch 2 times, most recently from b0acf71 to b07ec4d Compare June 12, 2025 07:05
@charIeszhao charIeszhao force-pushed the charles-log-11674-api-implementation branch from b07ec4d to 8a2a35e Compare June 12, 2025 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants