From 6217f0cbcbb7bc0d1e001cb932df4001ee78983e Mon Sep 17 00:00:00 2001 From: Byran Date: Fri, 12 Jul 2024 07:30:42 +0000 Subject: [PATCH] =?UTF-8?q?[Bug]:=20=E5=88=A0=E9=99=A4=E5=8F=B0=E8=B4=A6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E5=BA=94=E5=90=8C=E6=97=B6=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=AE=B0=E5=BD=95=E9=99=84=E4=BB=B6=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=92=8C=E9=99=84=E4=BB=B6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20#6957=20[2.6]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/standard-objects/base.trigger.js | 63 +++++++++++++---------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/packages/standard-objects/base.trigger.js b/packages/standard-objects/base.trigger.js index 7b482adda3..a77a295190 100644 --- a/packages/standard-objects/base.trigger.js +++ b/packages/standard-objects/base.trigger.js @@ -52,18 +52,19 @@ const checkCompany = async (object_name, userId, doc) => { const beforeInsertBase = async function () { const { doc, userId } = this; - doc.created = new Date(); - doc.modified = new Date(); - if (userId) { - if (!doc.owner) { - doc.owner = userId; - } - if (doc.owner === '{userId}') { - doc.owner = userId; - } - doc.created_by = userId; - doc.modified_by = userId; - } + // 迁移到insert函数中提前执行了 + // doc.created = new Date(); + // doc.modified = new Date(); + // if (userId) { + // if (!doc.owner) { + // doc.owner = userId; + // } + // if (doc.owner === '{userId}') { + // doc.owner = userId; + // } + // doc.created_by = userId; + // doc.modified_by = userId; + // } var extras = ["spaces", "company", "organizations", "users", "space_users"]; if (extras.indexOf(this.object_name) < 0 && doc.space) { /* company_ids/company_id默认值逻辑*/ @@ -100,10 +101,11 @@ const beforeUpdateBase = async function () { if (!doc) { return; } - doc.modified = new Date(); - if (userId) { - doc.modified_by = userId; - } + // 迁移到update函数中提前执行了 + // doc.modified = new Date(); + // if (userId) { + // doc.modified_by = userId; + // } var extras = ["spaces", "company", "organizations", "users", "space_users"]; if (extras.indexOf(this.object_name) < 0) { /* company_ids/company_id级联修改逻辑*/ @@ -144,30 +146,37 @@ const afterDeleteBase = async function () { _.each(fieldsName, function (fieldName) { const fieldProps = fields[fieldName]; - const indexOfType = fieldProps && ['file','image'].indexOf(fieldProps.type); - if( indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length ){ - const collection = [cfs.files,cfs.images][indexOfType]; + const indexOfType = fieldProps && ['file', 'image'].indexOf(fieldProps.type); + if (indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length) { + const collection = [cfs.files, cfs.images][indexOfType]; let ids = previousDoc[fieldName] - if(typeof ids === 'string'){ + if (typeof ids === 'string') { ids = [ids] } - _.each(ids,function (id){ + _.each(ids, function (id) { collection.remove({ "_id": id }); }) } }); + if ("cms_files" != object_name) { + // 删除附件 + const cmsFilesObj = objectql.getObject('cms_files') + const cmsFiles = await cmsFilesObj.find({ + filters: [ + ["parent/o", "=", object_name], + ["parent/ids", "=", previousDoc._id] + ] + }) + for (const cmsFile of cmsFiles) { + await cmsFilesObj.delete(cmsFile._id) + } + } } module.exports = { listenTo: 'base', - beforeInsert: async function () { - return await beforeInsertBase.apply(this, arguments) - }, - beforeUpdate: async function () { - return await beforeUpdateBase.apply(this, arguments) - }, afterDelete: async function () { return await afterDeleteBase.apply(this, arguments) }