diff --git a/striker-ui-api/lib/accessDB.js b/striker-ui-api/lib/accessDB.js index 2f2f5a0b..47727236 100644 --- a/striker-ui-api/lib/accessDB.js +++ b/striker-ui-api/lib/accessDB.js @@ -78,18 +78,13 @@ const accessDB = { return execDatabaseModuleSubroutine('insert_or_update_jobs', subParams) .stdout; }, - dbQuery: (query, accessMode, options) => { - const args = ['--query', query]; - - if (accessMode) { - args.push('--mode', accessMode); - } - - return execStrikerAccessDatabase(args, options); - }, + dbQuery: (query, options) => + execStrikerAccessDatabase(['--query', query], options), dbSub: execDatabaseModuleSubroutine, dbSubRefreshTimestamp: () => execDatabaseModuleSubroutine('refresh_timestamp').stdout, + dbWrite: (query, options) => + execStrikerAccessDatabase(['--query', query, '--mode', 'write'], options), }; module.exports = accessDB; diff --git a/striker-ui-api/routes/files.js b/striker-ui-api/routes/files.js index c93ee9d6..cf40766f 100644 --- a/striker-ui-api/routes/files.js +++ b/striker-ui-api/routes/files.js @@ -4,6 +4,7 @@ const { dbJobAnvilSyncShared, dbQuery, dbSubRefreshTimestamp, + dbWrite, } = require('../lib/accessDB'); const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview'); const getFileDetail = require('../lib/request_handlers/files/getFileDetail'); @@ -12,6 +13,28 @@ const uploadSharedFiles = require('../middlewares/uploadSharedFiles'); const router = express.Router(); router + .delete('/:fileUUID', (request, response) => { + const { fileUUID } = request.params; + const FILE_TYPE_DELETED = 'DELETED'; + + const [[oldFileType]] = dbQuery( + `SELECT file_type FROM files WHERE file_uuid = '${fileUUID}';`, + ).stdout; + + if (oldFileType !== FILE_TYPE_DELETED) { + dbWrite( + `UPDATE files + SET + file_type = '${FILE_TYPE_DELETED}', + modified_date = '${dbSubRefreshTimestamp()}' + WHERE file_uuid = '${fileUUID}';`, + ).stdout; + + dbJobAnvilSyncShared('purge', `file_uuid=${fileUUID}`, '0136', '0137'); + } + + response.status(204).send(); + }) .get('/', getFilesOverview) .get('/:fileUUID', getFileDetail) .post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => { @@ -44,11 +67,11 @@ router if (fileName !== oldFileName) { query += ` - UPDATE files - SET - file_name = '${fileName}', - modified_date = '${dbSubRefreshTimestamp()}' - WHERE file_uuid = '${fileUUID}';`; + UPDATE files + SET + file_name = '${fileName}', + modified_date = '${dbSubRefreshTimestamp()}' + WHERE file_uuid = '${fileUUID}';`; anvilSyncSharedFunctions.push(() => dbJobAnvilSyncShared( @@ -132,7 +155,7 @@ router let queryStdout; try { - ({ stdout: queryStdout } = dbQuery(query, 'write')); + ({ stdout: queryStdout } = dbWrite(query)); } catch (queryError) { console.log(`Query error: ${queryError}`);