(body: any)
| 257 | |
| 258 | // Create new row in a given dataset |
| 259 | const addDatasetRow = async (body: any) => { |
| 260 | try { |
| 261 | const appServer = getRunningExpressApp() |
| 262 | const dataset = await appServer.AppDataSource.getRepository(Dataset).findOneBy({ |
| 263 | id: body.datasetId, |
| 264 | workspaceId: body.workspaceId |
| 265 | }) |
| 266 | if (!dataset) throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Dataset ${body.datasetId} not found`) |
| 267 | if (body.csvFile) { |
| 268 | await _csvToDatasetRows(body.datasetId, body.csvFile, body.firstRowHeaders) |
| 269 | await changeUpdateOnDataset(body.datasetId, body.workspaceId) |
| 270 | return { message: 'Dataset rows added successfully' } |
| 271 | } else { |
| 272 | // get the max value first |
| 273 | const maxValueEntity = await appServer.AppDataSource.getRepository(DatasetRow).find({ |
| 274 | where: { |
| 275 | datasetId: body.datasetId |
| 276 | }, |
| 277 | order: { |
| 278 | sequenceNo: 'DESC' |
| 279 | }, |
| 280 | take: 1 |
| 281 | }) |
| 282 | let sequenceNo = 0 |
| 283 | if (maxValueEntity && maxValueEntity.length > 0) { |
| 284 | sequenceNo = maxValueEntity[0].sequenceNo |
| 285 | } |
| 286 | const newDs = new DatasetRow() |
| 287 | newDs.input = body.input |
| 288 | newDs.output = body.output |
| 289 | newDs.datasetId = body.datasetId |
| 290 | newDs.sequenceNo = sequenceNo === 0 ? sequenceNo : sequenceNo + 1 |
| 291 | const row = appServer.AppDataSource.getRepository(DatasetRow).create(newDs) |
| 292 | const result = await appServer.AppDataSource.getRepository(DatasetRow).save(row) |
| 293 | await changeUpdateOnDataset(body.datasetId, body.workspaceId) |
| 294 | return result |
| 295 | } |
| 296 | } catch (error) { |
| 297 | throw new InternalFlowiseError( |
| 298 | StatusCodes.INTERNAL_SERVER_ERROR, |
| 299 | `Error: datasetService.createDatasetRow - ${getErrorMessage(error)}` |
| 300 | ) |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | const changeUpdateOnDataset = async (id: string, workspaceId: string, entityManager?: any) => { |
| 305 | const appServer = getRunningExpressApp() |
nothing calls this directly
no test coverage detected