Merge branch 'dev' into 1781-zoneHoliday
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2022-07-22 13:58:52 +00:00
commit b8183748ce
3 changed files with 23 additions and 5 deletions

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
const fs = require('fs-extra');
const path = require('path');
@ -15,7 +16,7 @@ module.exports = Self => {
}
});
Self.deleteTrashFiles = async(options) => {
Self.deleteTrashFiles = async options => {
const tx = await Self.beginTransaction({});
const myOptions = {};
@ -26,6 +27,9 @@ module.exports = Self => {
myOptions.transaction = tx;
try {
if (process.env.NODE_ENV == 'test')
throw new UserError(`Action not allowed on the test environment`);
const models = Self.app.models;
const DmsContainer = models.DmsContainer;
@ -33,9 +37,15 @@ module.exports = Self => {
where: {code: 'trash'}
}, myOptions);
const date = new Date();
date.setMonth(date.getMonth() - 4);
const dmsToDelete = await models.Dms.find({
where: {
dmsTypeFk: trashDmsType.id
and: [
{dmsTypeFk: trashDmsType.id},
{created: {lt: date}}
]
}
}, myOptions);
@ -43,14 +53,19 @@ module.exports = Self => {
const pathHash = DmsContainer.getHash(dms.id);
const dmsContainer = await DmsContainer.container(pathHash);
const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file);
const dstFolder = path.join(dmsContainer.client.root, pathHash);
await fs.unlink(dstFile);
await dms.destroy(myOptions);
try {
await fs.rmdir(dstFolder);
await dms.destroy(myOptions);
} catch (err) {
await dms.destroy(myOptions);
}
}
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn2008`.`albaran_gestdoc` DROP FOREIGN KEY fk_albaran_gestdoc_gestdoc1;
ALTER TABLE `vn2008`.`albaran_gestdoc` ADD CONSTRAINT albaran_gestdoc_FK FOREIGN KEY (gestdoc_id) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -23,6 +23,7 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `account` /*!40100 DEFAULT CHARACTER SE
USE `account`;
--
-- Table structure for table `account`
--