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. 35
      striker-ui-api/routes/files.js

@ -78,18 +78,13 @@ const accessDB = {
return execDatabaseModuleSubroutine('insert_or_update_jobs', subParams) return execDatabaseModuleSubroutine('insert_or_update_jobs', subParams)
.stdout; .stdout;
}, },
dbQuery: (query, accessMode, options) => { dbQuery: (query, options) =>
const args = ['--query', query]; execStrikerAccessDatabase(['--query', query], options),
if (accessMode) {
args.push('--mode', accessMode);
}
return execStrikerAccessDatabase(args, options);
},
dbSub: execDatabaseModuleSubroutine, dbSub: execDatabaseModuleSubroutine,
dbSubRefreshTimestamp: () => dbSubRefreshTimestamp: () =>
execDatabaseModuleSubroutine('refresh_timestamp').stdout, execDatabaseModuleSubroutine('refresh_timestamp').stdout,
dbWrite: (query, options) =>
execStrikerAccessDatabase(['--query', query, '--mode', 'write'], options),
}; };
module.exports = accessDB; module.exports = accessDB;

@ -4,6 +4,7 @@ const {
dbJobAnvilSyncShared, dbJobAnvilSyncShared,
dbQuery, dbQuery,
dbSubRefreshTimestamp, dbSubRefreshTimestamp,
dbWrite,
} = require('../lib/accessDB'); } = require('../lib/accessDB');
const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview'); const getFilesOverview = require('../lib/request_handlers/files/getFilesOverview');
const getFileDetail = require('../lib/request_handlers/files/getFileDetail'); const getFileDetail = require('../lib/request_handlers/files/getFileDetail');
@ -12,6 +13,28 @@ const uploadSharedFiles = require('../middlewares/uploadSharedFiles');
const router = express.Router(); const router = express.Router();
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('/', getFilesOverview)
.get('/:fileUUID', getFileDetail) .get('/:fileUUID', getFileDetail)
.post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => { .post('/', uploadSharedFiles.single('file'), ({ file, body }, response) => {
@ -44,11 +67,11 @@ router
if (fileName !== oldFileName) { if (fileName !== oldFileName) {
query += ` query += `
UPDATE files UPDATE files
SET SET
file_name = '${fileName}', file_name = '${fileName}',
modified_date = '${dbSubRefreshTimestamp()}' modified_date = '${dbSubRefreshTimestamp()}'
WHERE file_uuid = '${fileUUID}';`; WHERE file_uuid = '${fileUUID}';`;
anvilSyncSharedFunctions.push(() => anvilSyncSharedFunctions.push(() =>
dbJobAnvilSyncShared( dbJobAnvilSyncShared(
@ -132,7 +155,7 @@ router
let queryStdout; let queryStdout;
try { try {
({ stdout: queryStdout } = dbQuery(query, 'write')); ({ stdout: queryStdout } = dbWrite(query));
} catch (queryError) { } catch (queryError) {
console.log(`Query error: ${queryError}`); console.log(`Query error: ${queryError}`);

Loading…
Cancel
Save