@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
24 lines (21 loc) • 986 B
JavaScript
;
/**
* Extracts the primary key column and its value from an entity's metadata.
* Used for CRUD operations that need to identify records by primary key.
* @param {DeepPartial<E> | Partial<E>} parameters - The request parameters containing the primary key value
* @param {IApiEntity<E>} entityMetadata - The entity metadata containing column information
* @returns {IApiControllerPrimaryColumn<E> | undefined} The primary key information or undefined if no primary key is found
* @template E - The entity type
*/
function ApiControllerGetPrimaryColumn(parameters, entityMetadata) {
const primaryKeyColumn = entityMetadata.columns.find((column) => column.isPrimary);
if (!primaryKeyColumn) {
return undefined;
}
return {
key: primaryKeyColumn.name,
value: parameters[primaryKeyColumn.name],
};
}
exports.ApiControllerGetPrimaryColumn = ApiControllerGetPrimaryColumn;
//# sourceMappingURL=get-primary-column.utility.js.map