Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 9ea81a8

Browse files
authored
fix project&dataset mappings and duplicate issue (#366)
1 parent fb37289 commit 9ea81a8

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

annotation-service/services/dataSet-service.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,26 @@ async function updateDataset(req) {
290290

291291
}
292292

293-
async function updateDatasetProjectInfo(dataSetName, projectName, operation) {
293+
async function updateDatasetProjectInfo(dataSetName, projectName, operation, newProjectName) {
294294

295-
const condistion = {dataSetName: dataSetName};
295+
const condition = {dataSetName: dataSetName};
296296
const options = { new: true, upsert: true };
297297
let update = {};
298298

299299
if (OPERATION.ADD == operation) {
300-
update = { $push: { projects: projectName } }
300+
update = { $addToSet: { projects: projectName } }
301301
}else if (OPERATION.DELETE == operation) {
302302
update = { $pull: { projects: projectName } }
303+
}else if (OPERATION.UPDATE == operation) {
304+
condition['projects'] = projectName
305+
update = { $set: {"projects.$": newProjectName} }
306+
303307
}else{
304308
throw MESSAGE.VALIDATATION_OPERATION;
305309
}
306310

307311
console.log(`[ DATASET ] Service updateDatasetProjectInfo`);
308-
return mongoDb.findOneAndUpdate(DataSetModel, condistion, update, options);
312+
return mongoDb.findOneAndUpdate(DataSetModel, condition, update, options);
309313

310314
}
311315

annotation-service/services/project.service.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ async function updateProject(req) {
151151
const srsCondition = { projectName: req.body.previousPname };
152152
const srsDoc = { projectName: req.body.pname };
153153
await mongoDb.updateManyByConditions(mp.model, srsCondition, srsDoc);
154+
//update dataset maped projectName
155+
for (const dsName of _.union(mp.project.selectedDataset)) {
156+
await require('./dataSet-service').updateDatasetProjectInfo(dsName, req.body.previousPname, OPERATION.UPDATE, req.body.pname);
157+
}
158+
154159
}
155160

156161
const projectInfo = mp.project;
@@ -1054,20 +1059,20 @@ async function getProjectsTextTabular(email) {
10541059
}
10551060

10561061
async function updateProjectDatasetInfo(projectName, datasetName, operation) {
1057-
const condistion = {projectName: projectName};
1062+
const condition = {projectName: projectName};
10581063
const options = { new: true, upsert: true };
10591064
let update = {};
10601065

10611066
if (OPERATION.ADD == operation) {
1062-
update = { $push: { selectedDataset: datasetName } };
1067+
update = { $addToSet: { selectedDataset: datasetName } };
10631068
}else if (OPERATION.DELETE == operation) {
10641069
update = { $pull: { selectedDataset: datasetName } };
10651070
}else{
10661071
throw MESSAGE.VALIDATATION_OPERATION;
10671072
}
10681073

1069-
console.log(`[ DATASET ] Service updateProjectDatasetInfo`);
1070-
return mongoDb.findOneAndUpdate(ProjectModel, condistion, update, options);
1074+
console.log(`[ DATASET ] Service updateProjectDatasetInfo`, update);
1075+
return mongoDb.findOneAndUpdate(ProjectModel, condition, update, options);
10711076
}
10721077

10731078

annotation-service/services/srs-service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ async function appendSrsDataByCSVFile(req, originalHeaders, project) {
654654
const update = {
655655
$set: { appendSr: APPENDSR.DONE, updatedDate: Date.now() },
656656
$inc: { totalCase: caseNum },
657-
$push: { selectedDataset: req.body.selectedDataset }
657+
$addToSet: { selectedDataset: req.body.selectedDataset }
658658
};
659659
await mongoDb.findOneAndUpdate(ProjectModel, conditions, update);
660660
await updateDatasetProjectInfo(req.body.selectedDataset, req.body.pname, OPERATION.ADD);
@@ -690,7 +690,7 @@ async function appendSrsData(req) {
690690
if (req.body.isFile == true || req.body.isFile == 'true') {
691691
//file append
692692
await imgImporter.execute(req, false);
693-
update.$push = { selectedDataset: dataset };
693+
update.$addToSet = { selectedDataset: dataset };
694694
update.$inc = { totalCase: datasets[0].images.length };
695695

696696
} else {

annotation-service/utils/logImporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async function execute(req, sendEmail, annotators, append) {
131131
if (append) {
132132

133133
update.$set = { appendSr: APPENDSR.DONE };
134-
update.$push = { selectedDataset: selectedDataset };
134+
update.$addToSet = { selectedDataset: selectedDataset };
135135

136136
await projectService.updateAssinedCase(condition, totalCase, true);
137137
}

0 commit comments

Comments
 (0)