# all files / api/ delete-item.js

100% Statements 19/19
100% Branches 4/4
100% Functions 5/5
100% Lines 3/3

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21

    1

    4

     'use strict';

    // Dependencies:
    import fileStructure from '../file-structure';
    import getFileStructure from './get-file-structure';

    // Errors:
    import errorHandler from '../errors/error-handler';
    import TractorError from '../errors/TractorError';

    export default { handler };

    function handler (request, response) {
        let { path } = request.query;

        return fileStructure.deleteItem(path)
        .then(() => getFileStructure.handler(request, response))
        .catch(TractorError, error => errorHandler.handler(response, error))
        .catch(() => errorHandler.handler(response, new TractorError(`Could not delete "${path}"`)));
    }