refactor(update-step): move connection authorization to model

This commit is contained in:
Ali BARIN
2024-09-19 09:27:51 +00:00
committed by Faruk AYDIN
parent cd16a3cc15
commit 8134b6db6a
2 changed files with 11 additions and 13 deletions

View File

@@ -5,18 +5,7 @@ export default async (request, response) => {
.findById(request.params.stepId)
.throwIfNotFound();
const stepData = stepParams(request);
if (stepData.connectionId && (stepData.appKey || step.appKey)) {
await request.currentUser.authorizedConnections
.findOne({
id: stepData.connectionId,
key: stepData.appKey || step.appKey,
})
.throwIfNotFound();
}
step = await step.update(stepData);
step = await step.updateFor(request.currentUser, stepParams(request));
renderObject(response, step);
};

View File

@@ -335,9 +335,18 @@ class Step extends Base {
await Promise.all(nextStepQueries);
}
async update(newStepData) {
async updateFor(user, newStepData) {
const { connectionId, appKey, key, parameters } = newStepData;
if (connectionId && (appKey || this.appKey)) {
await user.authorizedConnections
.findOne({
id: connectionId,
key: appKey || this.appKey,
})
.throwIfNotFound();
}
if (this.isTrigger && appKey && key) {
await App.checkAppAndTrigger(appKey, key);
}