Fixed #18148 and #17451 - return int for user_count, fixed validation #18150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #18148 and #17451, correctly now returning the users count when viewing a specific department via API, casting it as an integer, and also fixes the validation. Previously, the validation wasn't working as expected, so you could have repeated department names. The validator now correctly checks for uniqueness across company and location ID (if they are provided.)
This is technically a breaking change, since we're also now using the transformers to format the create/update responses, however I don't think most folks use the departments API endpoint much, since the validation issue has been a bug forever and nobody mentioned it.
{ "status": "success", "messages": "Department updated successfully.", "payload": { "id": 30, "name": "Test from API", "phone": null, "fax": null, "image": null, "company": { "id": 2, "name": "Lowe LLC" }, "manager": null, "location": { "id": 5, "name": "East Chadrickstad" }, "users_count": 0, "notes": "TEST AGAIN", "created_at": { "datetime": "2025-11-04 15:30:24", "formatted": "Tue Nov 04, 2025 3:30PM" }, "updated_at": { "datetime": "2025-11-04 16:02:09", "formatted": "Tue Nov 04, 2025 4:02PM" }, "available_actions": { "update": true, "delete": true } } }I also think the custom validator is a little less horrible-looking now.