2019-06-06 11:59:11 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('removeFile', {
|
|
|
|
description: 'Makes a logical delete moving a file to a trash folder',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'id',
|
|
|
|
type: 'Number',
|
|
|
|
description: 'The document id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'Object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/removeFile`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.removeFile = async(ctx, id) => {
|
|
|
|
const models = Self.app.models;
|
2019-06-20 05:46:30 +00:00
|
|
|
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}});
|
2019-06-06 11:59:11 +00:00
|
|
|
const dms = await models.Dms.findById(id);
|
|
|
|
|
|
|
|
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk);
|
|
|
|
if (!hasWriteRole)
|
|
|
|
throw new UserError(`You don't have enough privileges`);
|
|
|
|
|
|
|
|
return dms.updateAttribute('dmsTypeFk', trashDmsType.id);
|
|
|
|
};
|
|
|
|
};
|