refs #2051 feat: restore dms methods
This commit is contained in:
parent
a5ecec9603
commit
bdf5dd6e3c
|
@ -34,25 +34,20 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
let modelDms = null;
|
||||
if (myOptions.model) {
|
||||
modelDms = await models[myOptions.model].findById(id, null, myOptions);
|
||||
id = modelDms.dmsFk;
|
||||
}
|
||||
const targetDms = await models.Dms.findById(id, null, myOptions);
|
||||
const dms = await models.Dms.findById(id, null, myOptions);
|
||||
const trashDmsType = await models.DmsType.findOne({
|
||||
where: {code: 'trash'}
|
||||
}, myOptions);
|
||||
|
||||
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, targetDms.dmsTypeFk, myOptions);
|
||||
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk, myOptions);
|
||||
if (!hasWriteRole)
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
||||
await dms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
if (modelDms) modelDms.destroy(myOptions);
|
||||
return targetDms;
|
||||
|
||||
return dms;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -96,21 +96,8 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
const promises = [];
|
||||
const {model, create} = myOptions;
|
||||
addedDms.forEach(dms => {
|
||||
const newDms = models[model].create({
|
||||
...create,
|
||||
dmsFk: dms.id
|
||||
}, myOptions);
|
||||
|
||||
promises.push(newDms);
|
||||
});
|
||||
const resolvedPromises = await Promise.all(promises);
|
||||
|
||||
// if (tx) await tx.commit();
|
||||
|
||||
return resolvedPromises;
|
||||
return addedDms;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
||||
|
|
Loading…
Reference in New Issue