Skip to main content
Version: 🚧 Canary

⚙️ Profile handlers

Profile handlers are route-pipeline functions, not Express middleware. They read RouteHandlerPayload values from params and context, merge successful values into context.data, or terminate a successful Result with an HTTP response descriptor. Several exports are deprecated; migrate to blocks in new custom compositions.

Inventory

HandlerPipeline roleInputs / contextResult / behavior / errorsUsed by routes
createProfileHandlerrequestBody, db.profilesCreates a base entity and writes profileId; 400 for empty or failed body, 500 for database failure.createProfileRoute
getProfileByIdHandlercontext.data.profileId or path ID, db.profilesWrites profile; 400 for missing ID, 404 when absent, 500 for database failure.createProfileRoute, getProfileRoute, updateProfileRoute, deleteProfileRoute
findProfilesHandlerrequestQuery, db.profilesWrites profiles; 500 on query failure.findProfilesRoute
updateProfileHandlerPath/context ID, requestBody, db.profilesWrites updateProfile; 400 for absent ID or body or no modification, 404 when absent.updateProfileRoute
deleteProfileHandlerPath/context ID, db.profilesWrites deleteProfile; 400 for missing ID, 404 when absent, 500 on failure.deleteProfileRoute
normalizeProfileTerminatorDeprecated terminatorcontext.data.profileRemoves _id and returns the profile; throws on error or missing data.Custom composition only
normalizeProfilesListTerminatorDeprecated terminatorcontext.data.profilesRemoves _id from every profile; throws on error.Custom composition only
deleteProfileTerminatorDeprecated terminatorcontext.data.deleteProfileReturns { statusCode: 204 }; throws on error or missing data.deleteProfileRoute

Details

createProfile

Implementation

Deprecated: migrate to a block. It reads params.requestBody and context.db.profiles. A missing or empty body returns NodeblocksError(400, 'Request body is required', 'createProfile'). On success it calls createBaseEntity with empty organizationFollows, productLikes, and profileFollows before spreading the body, inserts that entity, and writes { profileId: baseEntity.id } through mergeData. A result without insertedId returns 400; an insertion exception returns 500. It is first in createProfileRoute.

getProfileById

Implementation

Deprecated: migrate to a block. It reads context.data?.profileId before params.requestParams?.profileId, string-coerces the chosen ID, and calls context.db.profiles.findOne({ id }). It writes { profile } through mergeData. It returns 400 for no ID, 404 when no profile exists, and 500 for a database exception. It is used by createProfileRoute, getProfileRoute, updateProfileRoute, and deleteProfileRoute.

findProfiles

Implementation

Deprecated: migrate to a block. It reads params.requestQuery and context.db.profiles, uses requestQuery || {} as the MongoDB filter, materializes the cursor with toArray(), and writes { profiles } through mergeData. A query exception returns NodeblocksError(500, 'Failed to find profiles', 'findProfiles'). It is wrapped with pagination in findProfilesRoute.

updateProfile

Implementation

Deprecated: migrate to a block. It reads the data ID before the path ID, params.requestBody, and context.db.profiles. It calls updateOne({ id: String(profileId) }, { $set: updateBaseEntity(requestBody) }) and writes { updateProfile: result }. It returns 400 for a missing ID, empty body, or modifiedCount === 0; 404 for matchedCount === 0; and 500 for an exception. It is used by updateProfileRoute.

deleteProfile

Implementation

Deprecated: migrate to a block. It reads the data ID before the path ID and deletes context.db.profiles by public string ID. It writes { deleteProfile: result }; returns 400 for no ID, 404 for deletedCount === 0, and 500 for a falsy driver result or an exception. It is used by deleteProfileRoute.

normalizeProfileTerminator

Implementation

Deprecated: use a normalizer and orThrow. It accepts Result<RouteHandlerPayload, Error>, rethrows an error result, requires context.data.profile (otherwise throws NodeblocksError(500, 'Unknown error normalizing profile', 'normalizeProfileTerminator')), and returns that object without _id. Custom composition only: no exported Profile route uses it.

normalizeProfilesListTerminator

Implementation

Deprecated: use a normalizer and orThrow. It accepts Result<RouteHandlerPayload, Error>, rethrows an error result, maps context.data.profiles, and returns every profile without _id. It does not guard against absent data.profiles. Custom composition only: no exported Profile route uses it.

deleteProfileTerminator

Implementation

Deprecated: use a normalizer and orThrow. It accepts Result<RouteHandlerPayload, Error>, rethrows an error result, requires context.data.deleteProfile (otherwise throws NodeblocksError(500, 'Unknown error deleting profile', 'deleteProfileTerminator')), and returns exactly { statusCode: 204 }. It is the final terminator of deleteProfileRoute.