|
|
@@ -255,51 +255,46 @@ ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId
|
|
|
data.updateData['deleteInfo'] = deleteInfo;
|
|
|
//Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
//update
|
|
|
- try {
|
|
|
- if (data.updateData.projType === projectType.project) {
|
|
|
- let tenders = await Projects.find({userID: userId, ParentID: data.updateData.ID});
|
|
|
- if (tenders.length > 0) {
|
|
|
- await UnitPriceFiles.update({
|
|
|
- user_id: userId,
|
|
|
- root_project_id: data.updateData.ID
|
|
|
- }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
- await FeeRateFiles.update({
|
|
|
- userID: userId,
|
|
|
- rootProjectID: data.updateData.ID
|
|
|
- }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
- await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
- } else {//true
|
|
|
- await UnitPriceFiles.remove({user_id: userId, root_project_id: data.updateData.ID});
|
|
|
- await FeeRateFiles.remove({userID: userId, rootProjectID: data.updateData.ID});
|
|
|
- //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
|
|
|
- await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
|
|
|
+ if (data.updateData.projType === projectType.project) {
|
|
|
+ let tenders = await Projects.find({ userID: userId, ParentID: data.updateData.ID });
|
|
|
+ if (tenders.length > 0) {
|
|
|
+ await UnitPriceFiles.update({
|
|
|
+ user_id: userId,
|
|
|
+ root_project_id: data.updateData.ID
|
|
|
+ }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
|
|
|
+ await FeeRateFiles.update({
|
|
|
+ userID: userId,
|
|
|
+ rootProjectID: data.updateData.ID
|
|
|
+ }, { $set: { deleteInfo: deleteInfo } }, { multi: true });
|
|
|
+ await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
|
|
|
+ } else {//true
|
|
|
+ await UnitPriceFiles.remove({ user_id: userId, root_project_id: data.updateData.ID });
|
|
|
+ await FeeRateFiles.remove({ userID: userId, rootProjectID: data.updateData.ID });
|
|
|
+ //await Projects.update({userID: userId, NextSiblingID: data.updateData.ID, deleteInfo: null}, {$set: {NextSiblingID: data.NextSiblingID}});
|
|
|
+ await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
|
|
|
+ }
|
|
|
+ } else if (data.updateData.projType === projectType.tender) {//fake
|
|
|
+ let delTender = await Projects.findOne({ userID: userId, ID: data.updateData.ID });
|
|
|
+ //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
|
|
|
+ if (delTender) {
|
|
|
+ let unitPriceFile = delTender.property.unitPriceFile;
|
|
|
+ let feeRateFile = delTender.property.feeFile;
|
|
|
+ let usedUFTenders = await Projects.find(
|
|
|
+ { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.unitPriceFile.id': unitPriceFile.id });
|
|
|
+ if (usedUFTenders.length === 1) {
|
|
|
+ await UnitPriceFiles.update({ id: unitPriceFile.id }, { $set: { deleteInfo: deleteInfo } });
|
|
|
}
|
|
|
- } else if (data.updateData.projType === projectType.tender) {//fake
|
|
|
- let delTender = await Projects.findOne({userID: userId, ID: data.updateData.ID});
|
|
|
- //如果这个单位工程用到的费率文件、单价文件,没有被其他的单位工程使用,则应该一起跟随删除
|
|
|
- if(delTender){
|
|
|
- let unitPriceFile = delTender.property.unitPriceFile;
|
|
|
- let feeRateFile = delTender.property.feeFile;
|
|
|
- let usedUFTenders = await Projects.find(
|
|
|
- {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.unitPriceFile.id': unitPriceFile.id});
|
|
|
- if(usedUFTenders.length === 1){
|
|
|
- await UnitPriceFiles.update({id: unitPriceFile.id}, {$set: {deleteInfo: deleteInfo}});
|
|
|
- }
|
|
|
- let usedFRTenders = await Projects.find(
|
|
|
- {userID: userId, $or: [{deleteInfo: null}, {'deleteInfo.deleted': false}], 'property.feeFile.id': feeRateFile.id});
|
|
|
- if(usedFRTenders.length === 1){
|
|
|
- await FeeRateFiles.update({ID: feeRateFile.id}, {$set: {deleteInfo: deleteInfo}});
|
|
|
- }
|
|
|
- await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
+ let usedFRTenders = await Projects.find(
|
|
|
+ { userID: userId, $or: [{ deleteInfo: null }, { 'deleteInfo.deleted': false }], 'property.feeFile.id': feeRateFile.id });
|
|
|
+ if (usedFRTenders.length === 1) {
|
|
|
+ await FeeRateFiles.update({ ID: feeRateFile.id }, { $set: { deleteInfo: deleteInfo } });
|
|
|
}
|
|
|
+ await Projects.update({ userID: userId, ID: data.updateData.ID }, data.updateData, updateAll);
|
|
|
+ }
|
|
|
|
|
|
- } else if (data.updateData.projType === projectType.folder) {//true
|
|
|
- await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
|
|
|
- } else throw '未知文件类型,删除失败!';
|
|
|
- }
|
|
|
- catch (error) {
|
|
|
- callback(1, error, null);
|
|
|
- }
|
|
|
+ } else if (data.updateData.projType === projectType.folder) {//true
|
|
|
+ await Projects.remove({ userID: userId, ID: data.updateData.ID }, updateAll);
|
|
|
+ } else throw '未知文件类型,删除失败!';
|
|
|
}
|
|
|
else {
|
|
|
hasError = true;
|