56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('unlock', {
|
||
|
description: 'Unlock an app for the user',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [
|
||
|
{
|
||
|
arg: 'appName',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
description: 'The app name',
|
||
|
http: {source: 'path'}
|
||
|
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: ['object'],
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:appName/unlock`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.unlock = async(appName, options) => {
|
||
|
const models = Self.app.models;
|
||
|
const myOptions = {};
|
||
|
|
||
|
let tx;
|
||
|
|
||
|
if (typeof options == 'object')
|
||
|
Object.assign(myOptions, options);
|
||
|
|
||
|
if (!myOptions.transaction) {
|
||
|
tx = await Self.beginTransaction({});
|
||
|
myOptions.transaction = tx;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
const mdbApp = await models.MdbApp.findById(appName, null, myOptions);
|
||
|
const updatedMdbApp = await mdbApp.updateAttributes({
|
||
|
userFk: null,
|
||
|
locked: null
|
||
|
}, myOptions);
|
||
|
|
||
|
if (tx) await tx.commit();
|
||
|
|
||
|
return updatedMdbApp;
|
||
|
} catch (e) {
|
||
|
if (tx) await tx.rollback();
|
||
|
|
||
|
throw e;
|
||
|
}
|
||
|
};
|
||
|
};
|