fix(striker-ui-api): complete delete file endpoint

main
Tsu-ba-me 3 years ago
parent eb840b3d9c
commit 462ec6d903
  1. 13
      striker-ui-api/lib/accessDB.js
  2. 25
      striker-ui-api/routes/files.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;

@ -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) => {
@ -132,7 +155,7 @@ router
let queryStdout;
try {
({ stdout: queryStdout } = dbQuery(query, 'write'));
({ stdout: queryStdout } = dbWrite(query));
} catch (queryError) {
console.log(`Query error: ${queryError}`);

Loading…
Cancel
Save