Update an existing medical specialty
validatorJWT - Validates JWT token (backend/middlewares/validatorJWT.ts)isAdmin - Verifies user has admin role (backend/middlewares/validatorAdmin.ts)check("name", "El nombre es obligatorio").not().isEmpty() - Name is requiredcheck("name").custom(existNameSpecialityById) - Name must be unique (excluding current record)check("state", "El estado es obligatorio").not().isEmpty() - State is requiredcollectionErrors - Handles validation errorsbackend/controllers/speciality.ts:102
1 - Updates specialty with ID 125 - Updates specialty with ID 25backend/controllers/speciality.ts:110-115existNameSpecialityById helper)"Cardiología""Pediatría Avanzada""Medicina General"backend/routes/speciality.ts:44-45"Activa" - Active specialty"Inactiva" - Inactive specialtybackend/routes/speciality.ts:46Use cases:"Inactiva" to soft-delete a specialty"Activa" to reactivate a specialty| Status Code | Description |
|---|---|
200 | Success - Specialty successfully updated |
400 | Bad Request - Invalid ID format or validation error |
401 | Unauthorized - Invalid or missing JWT token |
403 | Forbidden - User is not an administrator |
404 | Not Found - Specialty with the given ID does not exist |
500 | Server Error - Database or internal error |
update method:
backend/controllers/speciality.ts:102-139
backend/routes/speciality.ts:40-50
existNameSpecialityById helper validates uniqueness while excluding the current record:
backend/models/speciality.ts:27-31
Attempting to set an invalid state value will result in a database error.
name and state fields are required in the request body. Omitting either will result in a 400 validation error.name and state fields, even if only updating onestate to "Inactiva" is the recommended way to “delete” a specialtyupdatedAt field is automatically updated by SequelizeisAdmin middleware enforces that only administrators can update specialtiesstate to "Inactiva" (recommended)