Skip to main content

Function: addCultivation()

addCultivation(fdm, principal_id, b_lu_catalogue, b_id, b_lu_start, b_lu_end?): Promise<any>

Defined in: fdm-core/src/cultivation.ts:152

Alpha

Adds a new cultivation to a specific field.

The function validates that the sowing and (if provided) termination dates are valid Date objects and that the termination date is after the sowing date. It ensures the target field and cultivation catalogue entry exist and that no duplicate cultivation is recorded. A permission check is performed before any database operations. If a termination date is provided for a cultivation that is harvestable only once, a harvest record is automatically scheduled for the termination date.

Parameters

fdm

any

The FDM instance providing the connection to the database. The instance can be created with createFdmServer.

principal_id

any

The identifier of the principal performing the operation.

b_lu_catalogue

any

The catalogue ID corresponding to the cultivation entry.

b_id

any

The identifier of the field to which the cultivation is added.

b_lu_start

any

The sowing date of the cultivation.

b_lu_end?

any

The optional termination date of the cultivation.

Returns

Promise<any>

A promise that resolves with the unique ID of the newly added cultivation.

Throws

If the sowing date is invalid, the termination date is invalid or not after the sowing date, the field or catalogue entry does not exist, or a duplicate cultivation is detected.