@@ -18,6 +18,7 @@ const fs = require('fs');
1818const mongoDb = require ( '../db/mongo.db' ) ;
1919const { ProjectModel, DataSetModel } = require ( '../db/db-connect' ) ;
2020const MESSAGE = require ( '../config/code_msg' ) ;
21+ const { updateProjectDatasetInfo} = require ( './project.service' ) ;
2122
2223async function saveDataSetInfo ( req ) {
2324
@@ -38,7 +39,9 @@ async function saveDataSetInfo(req) {
3839 format : req . body . format ,
3940 createTime : Date . now ( ) ,
4041 updateTime : Date . now ( ) ,
41- dataSynchronize : dataSynchronize
42+ dataSynchronize : dataSynchronize ,
43+ totalRows : req . body . totalRows ,
44+ totalColumns : req . body . totalColumns ? req . body . totalColumns : 0 ,
4245 } ;
4346
4447 if ( config . useLocalFileSys ) {
@@ -86,7 +89,6 @@ async function saveDataSetInfo(req) {
8689
8790 } else if ( req . body . format == DATASETTYPE . LOG ) {
8891 dataSet . topReview = req . body . topReview ;
89- dataSet . totalRows = req . body . totalRows ;
9092 }
9193
9294 let conditions = { dataSetName : req . body . dsname } ;
@@ -219,7 +221,9 @@ async function deleteDataSet(req) {
219221 }
220222
221223 }
222-
224+ for ( const projectName of ds [ 0 ] . projects ) {
225+ await updateProjectDatasetInfo ( projectName , ds [ 0 ] . dataSetName , OPERATION . DELETE ) ;
226+ }
223227 console . log ( `[ DATASET ] Service deleteDataSet.removeDataSet` ) ;
224228 await mongoDb . removeByConditions ( DataSetModel , { dataSetName : ds [ 0 ] . dataSetName } ) ;
225229
@@ -271,6 +275,25 @@ async function updateDataset(req) {
271275
272276}
273277
278+ async function updateDatasetProjectInfo ( datasetName , projectName , operation ) {
279+
280+ const condistion = { datasetName : datasetName } ;
281+ const options = { new : true , upsert : true } ;
282+ let update = { } ;
283+
284+ if ( OPERATION . ADD == operation ) {
285+ update [ "$push.projects" ] = projectName ;
286+ } else if ( OPERATION . DELETE == operation ) {
287+ update [ "$pull.projects" ] = projectName ;
288+ } else {
289+ throw MESSAGE . VALIDATATION_OPERATION ;
290+ }
291+
292+ console . log ( `[ DATASET ] Service updateDatasetProjectInfo` ) ;
293+ return mongoDb . findOneAndUpdate ( DataSetModel , condistion , update , options ) ;
294+
295+ }
296+
274297module . exports = {
275298 saveDataSetInfo,
276299 queryDataSetByUser,
@@ -279,4 +302,5 @@ module.exports = {
279302 signS3Url,
280303 imageTopPreview,
281304 updateDataset,
305+ updateDatasetProjectInfo,
282306}
0 commit comments