Class

InvestigationService

InvestigationService()

Investigation Service

Constructor

# new InvestigationService()

Constructor

View Source services/investigation.service.js, line 203

Classes

InvestigationService

Methods

# addContradictionInPlace(investigation, contradiction) → {Partial.<IInvestigation>}

Adds a contradiction to a specific field in an investigation.

Parameters:
Name Type Description
investigation Partial.<IInvestigation>

The investigation object to update.

contradiction IContradictionInput

The details of the contradiction to add.

View Source services/investigation.service.js, line 978

  • If the field is not found in the investigation.
Error
  • The investigation object with the updated contradiction.
Partial.<IInvestigation>

# async checkAndUnlockStaleLocks() → {Promise.<number>}

Check and unlock stale locks (investigations locked for more than 5 minutes).

View Source services/investigation.service.js, line 2611

Number of investigations unlocked.

Promise.<number>

# async cloneInvestigation(investigationId) → {Promise.<IInvestigation>}

Clones the current investigation by adding a "copy_N" postfix to its identifier.

Parameters:
Name Type Description
investigationId string

The ID of the current investigation to clone.

View Source services/investigation.service.js, line 1508

  • If an error occurs during the cloning process.
Error
  • The cloned investigation object.
Promise.<IInvestigation>

# async createInvestigation(createDto) → {Promise.<IInvestigation>}

Creates a new investigation.

Parameters:
Name Type Description
createDto ICreateInvestigationDto

The data required to create the investigation.

View Source services/investigation.service.js, line 252

  • The created investigation.
Promise.<IInvestigation>

# async deleteInvestigationById(investigationId) → {Promise.<IDeleteInvestigationByIdResponse>}

Permanently deletes an investigation and its related chat history.

Parameters:
Name Type Description
investigationId string

The ID of the investigation to delete.

View Source services/investigation.service.js, line 1630

  • If an error occurs during the deletion process.
Error
  • An object summarizing the deletion status of the investigation and related chats.
Promise.<IDeleteInvestigationByIdResponse>

# deleteInvestigationData(investigation) → {IInvestigation}

Deletes the data of a given investigation.

Parameters:
Name Type Description
investigation IInvestigation

The investigation to clear.

View Source services/investigation.service.js, line 1590

  • If an error occurs during the deletion process.
Error
  • The investigation object with its values emptied.
IInvestigation

# async ensureInvestigationAuthor(investigationId, authorId) → {Promise.<(IInvestigation|null)>}

Ensures that the author of a given investigation is set.

If the investigation exists and does not already have a valid author, this method sets the author to the provided authorId and updates the dateModified field.

Parameters:
Name Type Description
investigationId string

The ID of the investigation to check.

authorId Types.ObjectId

The ObjectId of the author to set.

View Source services/investigation.service.js, line 946

If there is an error during the process of fetching or saving the investigation.

Error
  • The updated investigation object, or null if the investigation does not exist or already has a valid author.
Promise.<(IInvestigation|null)>

# async generateInvestigation(message, history, investigationMetadata) → {Promise.<(IAssistantInvestigationFormat|null)>}

Generates an entire investigation based on the provided metadata. If the investigation is not found, it throws an error.

Parameters:
Name Type Description
message string

The user's message from which the lesson must be detected.

history FormattedHistory

The chat history between the user and the assistant.

investigationMetadata string

The metadata of the investigation.

View Source services/investigation.service.js, line 1466

  • If the investigation is not found.
Error
  • The generated investigation.
Promise.<(IAssistantInvestigationFormat|null)>

# async generateInvestigationObjects(message, history, investigationMetadata, investigation) → {Promise.<(IAssistantInvestigationFormat|null)>}

Generates objects of investigation based on the provided metadata and plain investigation. If the objects are not found, it throws an error.

Parameters:
Name Type Description
message string

The user's message from which the lesson must be detected.

history string

The chat history between the user and the assistant.

investigationMetadata string

The metadata of the investigation.

investigation string

The plain investigation without steps and objects with yaml format.

View Source services/investigation.service.js, line 1367

  • If the objects are not found.
Error
  • The generated objects of the provided investigation.
Promise.<(IAssistantInvestigationFormat|null)>

# async generateInvestigationSteps(message, history, investigationMetadata, investigation) → {Promise.<(IAssistantInvestigationFormat|null)>}

Generates steps of investigation based on the provided metadata and the provided investigation. If the steps are not found, it throws an error.

Parameters:
Name Type Description
message string

The user's message from which the lesson must be detected.

history string

The chat history between the user and the assistant.

investigationMetadata string

The metadata of the investigation.

investigation string

The provided investigation without steps with yaml format.

View Source services/investigation.service.js, line 1417

  • If the steps are not found.
Error
  • The generated steps of the provided investigation.
Promise.<(IAssistantInvestigationFormat|null)>

# async generateInvestigationWithoutStepsAndObjects(message, history, investigationMetadata) → {Promise.<(IAssistantInvestigationFormat|null)>}

Generates an investigation without steps and objects based on the provided metadata. If the investigation is not found, it throws an error.

Parameters:
Name Type Description
message string

The user's message from which the lesson must be detected.

history string

The chat history between the user and the assistant.

investigationMetadata string

The metadata of the investigation.

View Source services/investigation.service.js, line 1299

  • If the investigation is not found.
Error
  • The generated investigation without steps and objects.
Promise.<(IAssistantInvestigationFormat|null)>

# async getFieldHistory(investigationId, fieldPath, limit) → {Promise.<{fieldPath: string, history: Array.<unknown>, totalCount: number}>}

Gets the history for a specific field in an investigation.

Parameters:
Name Type Default Description
investigationId string

The ID of the investigation.

fieldPath string

The path to the field (e.g., "title", "steps.0.title", "objects.0.name").

limit number 50

Maximum number of history entries to return (default: 50).

View Source services/investigation.service.js, line 756

If the investigation is not found.

Error

The field history.

Promise.<{fieldPath: string, history: Array.<unknown>, totalCount: number}>

# async getInvestigationById(investigationId) → {Promise.<IInvestigation>}

Retrieves a single investigation by its ID.

Parameters:
Name Type Description
investigationId string

The ID of the investigation to retrieve.

View Source services/investigation.service.js, line 323

If the investigation is not found.

Error
  • The investigation data.
Promise.<IInvestigation>

# async getInvestigationVersions(investigationId, limit) → {Promise.<IInvestigationVersionListResponse>}

Gets the versions of an investigation.

Parameters:
Name Type Default Description
investigationId string

The ID of the investigation.

limit number 20

The number of versions to return (default: 20).

View Source services/investigation.service.js, line 806

If the investigation is not found.

Error
  • The investigation versions.
Promise.<IInvestigationVersionListResponse>

# async getInvestigations(searchDto) → {Promise.<IInvestigationListResponseDto>}

Retrieves investigations with filtering, sorting, and grouping.

Parameters:
Name Type Description
searchDto IInvestigationSearchDto

The search and pagination parameters.

View Source services/investigation.service.js, line 1119

  • The investigations with sections/items.
Promise.<IInvestigationListResponseDto>

# async lockInvestigation(investigationId, userId) → {Promise.<IInvestigation>}

Lock an investigation for editing by a specific user.

Parameters:
Name Type Description
investigationId string

The investigation ID to lock.

userId string

The user ID who is locking the investigation.

View Source services/investigation.service.js, line 2559

The updated investigation.

Promise.<IInvestigation>

# async redoInvestigation(investigationId) → {Promise.<IInvestigation>}

Redo investigation - increment currentVersionIndex and return investigation at that version

Parameters:
Name Type Description
investigationId string

The ID of the investigation.

View Source services/investigation.service.js, line 892

If the investigation is not found or if the index is out of bounds.

Error
  • The investigation at the new index.
Promise.<IInvestigation>

# async regenerateOtherFields(investigationId, fieldName, updatedBy, historyopt) → {Promise.<IInvestigation>}

Regenerates other fields in an investigation based on a specific field. This operation uses a 3-step process: text fields → objects → steps.

Parameters:
Name Type Attributes Default Description
investigationId string

The ID of the investigation to update.

fieldName string

The name of the field to base regeneration on (e.g., "title", "curriculum", "objectives").

updatedBy Types.ObjectId | null null

The user making the change (optional).

history string <optional>
-

Chat history in YAML format (optional, defaults to "-").

View Source services/investigation.service.js, line 2034

If the investigation is not found or the field is invalid.

Error
  • The updated investigation.
Promise.<IInvestigation>

# async regenerateOtherFieldsObjects(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}

Regenerates objects based on regenerated text fields. This is Step 2 of the 3-step regeneration process.

Parameters:
Name Type Attributes Default Description
fieldName string

The name of the field to base regeneration on.

fieldValue string

The value of the field to base regeneration on.

investigation string

The regenerated investigation from Step 1 (YAML format).

investigationMetadata string

The metadata/guide in YAML format.

history string <optional>
-

Chat history in YAML format (optional, defaults to "-").

contradictionInfo object <optional>

Optional contradiction information.

contradictionReason string | null <optional>

Reason for contradiction.

targetFieldName string | null <optional>

Target field name for contradiction.

isContradicting boolean <optional>

Whether the field is contradicting.

View Source services/investigation.service.js, line 1845

If the prompt is not found or regeneration fails.

Error
  • The regenerated objects only.
Promise.<(IAssistantInvestigationFormat|null)>

# async regenerateOtherFieldsSteps(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}

Regenerates steps based on regenerated text fields and objects. This is Step 3 of the 3-step regeneration process.

Parameters:
Name Type Attributes Default Description
fieldName string

The name of the field to base regeneration on.

fieldValue string

The value of the field to base regeneration on.

investigation string

The regenerated investigation from Step 1 + Step 2 (YAML format).

investigationMetadata string

The metadata/guide in YAML format.

history string <optional>
-

Chat history in YAML format (optional, defaults to "-").

contradictionInfo object <optional>

Optional contradiction information.

contradictionReason string | null <optional>

Reason for contradiction.

targetFieldName string | null <optional>

Target field name for contradiction.

isContradicting boolean <optional>

Whether the field is contradicting.

View Source services/investigation.service.js, line 1942

If the prompt is not found or regeneration fails.

Error
  • The regenerated steps only.
Promise.<(IAssistantInvestigationFormat|null)>

# async regenerateOtherFieldsWithoutStepsAndObjects(fieldName, fieldValue, investigation, investigationMetadata, historyopt, contradictionInfoopt) → {Promise.<(IAssistantInvestigationFormat|null)>}

Regenerates text fields (without steps and objects) based on a specific field value. This is Step 1 of the 3-step regeneration process.

Parameters:
Name Type Attributes Default Description
fieldName string

The name of the field to base regeneration on.

fieldValue string

The value of the field to base regeneration on.

investigation string

The current investigation in YAML format.

investigationMetadata string

The metadata/guide in YAML format.

history string <optional>
-

Chat history in YAML format (optional, defaults to "-").

contradictionInfo object <optional>

Optional contradiction information.

contradictionReason string | null <optional>

Reason for contradiction.

targetFieldName string | null <optional>

Target field name for contradiction.

isContradicting boolean <optional>

Whether the field is contradicting.

View Source services/investigation.service.js, line 1744

If the prompt is not found or regeneration fails.

Error
  • The regenerated text fields only.
Promise.<(IAssistantInvestigationFormat|null)>

# removeAiGeneratedValues(obj)

Recursively sets all aiGeneratedValue fields to null.

This method is schema-agnostic and works regardless of changes to the investigation structure.

Parameters:
Name Type Description
obj Record.<string, unknown>

The object whose aiGeneratedValue fields should be cleared.

View Source services/investigation.service.js, line 219

# async toggleInvestigationDevelopment(investigationId) → {Promise.<IInvestigation>}

Sends/return investigation to/from InDevelopment.

Parameters:
Name Type Description
investigationId string

The ID of the investigation.

View Source services/investigation.service.js, line 2532

If the investigation is not found.

Error
  • The modified investigation.
Promise.<IInvestigation>

# async undoInvestigation(investigationId) → {Promise.<IInvestigation>}

Undo investigation - decrement currentVersionIndex and return investigation at that version

Parameters:
Name Type Description
investigationId string

The ID of the investigation.

View Source services/investigation.service.js, line 840

If the investigation is not found or if the index is out of bounds.

Error
  • The investigation at the new index.
Promise.<IInvestigation>

# async unlockInvestigation(investigationId, userId) → {Promise.<IInvestigation>}

Unlock an investigation. Only the user who locked it can unlock it.

Parameters:
Name Type Description
investigationId string

The investigation ID to unlock.

userId string

The user ID attempting to unlock (must be the lock owner).

View Source services/investigation.service.js, line 2584

The updated investigation.

Promise.<IInvestigation>

# async updateInvestigation(investigationId, updateData, obj) → {Promise.<IUpdateInvestigationResponse>}

Updates an investigation using the new API format.

Parameters:
Name Type Description
investigationId string

The ID of the investigation to update.

updateData IUpdateInvestigationDto

The update data in the new format, including string/number fields and step updates.

obj object

Optional object used to determine if the update data should be built from scratch.

needsBuildUpdate boolean

Whether the update data should be built from scratch.

updatedBy Types.ObjectId | null

The user making the change (optional).

isAiGenerated boolean

Whether this update is AI-generated (default: false).

skipVersioning boolean

Whether to skip versioning (default: false).

View Source services/investigation.service.js, line 607

If the investigation is not found or is locked.

Error
  • The result of the update operation.
Promise.<IUpdateInvestigationResponse>

# async updateInvestigationByVersion(oldInvestigation, investigation, userId, isUserChangeExist) → {Promise.<IInvestigation>}

Updates investigation by adding new version.

Parameters:
Name Type Default Description
oldInvestigation IInvestigation

The latest investigation version.

investigation IInvestigation

The entire investigation model.

userId ObjectId | null

The ID of the user.

isUserChangeExist boolean false

Whether the change was made by the user (true) or AI (false). Defaults to false.

View Source services/investigation.service.js, line 1669

  • If an error occurs during the update process.
Error
  • An investigation updated with new version.
Promise.<IInvestigation>