refactor: Remove reintroduced non-null assertions in Db calls (#3162)
* 🔥 Remove reintroduced non-null assertions * 🔥 Remove duplicate cred references * 🔥 Remove unneeded `@ts-ignore` * 🔥 Remove another `@ts-ignore` * 🔥 Remove outdated suite version * 🔥 Remove leftover non-null assertion Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com> * 🔥 Remove more leftovers * 🔥 Remove unneeded optional chaining operators Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
@@ -756,7 +756,7 @@ class App {
|
||||
const { tags: tagIds } = req.body;
|
||||
|
||||
if (tagIds?.length && !config.getEnv('workflowTagsDisabled')) {
|
||||
newWorkflow.tags = await Db.collections.Tag!.findByIds(tagIds, {
|
||||
newWorkflow.tags = await Db.collections.Tag.findByIds(tagIds, {
|
||||
select: ['id', 'name'],
|
||||
});
|
||||
}
|
||||
@@ -768,7 +768,7 @@ class App {
|
||||
await getConnection().transaction(async (transactionManager) => {
|
||||
savedWorkflow = await transactionManager.save<WorkflowEntity>(newWorkflow);
|
||||
|
||||
const role = await Db.collections.Role!.findOneOrFail({
|
||||
const role = await Db.collections.Role.findOneOrFail({
|
||||
name: 'owner',
|
||||
scope: 'workflow',
|
||||
});
|
||||
@@ -878,13 +878,13 @@ class App {
|
||||
}
|
||||
|
||||
if (req.user.globalRole.name === 'owner') {
|
||||
workflows = await Db.collections.Workflow!.find(
|
||||
workflows = await Db.collections.Workflow.find(
|
||||
Object.assign(query, {
|
||||
where: filter,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
const shared = await Db.collections.SharedWorkflow!.find({
|
||||
const shared = await Db.collections.SharedWorkflow.find({
|
||||
relations: ['workflow'],
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
@@ -894,7 +894,7 @@ class App {
|
||||
|
||||
if (!shared.length) return [];
|
||||
|
||||
workflows = await Db.collections.Workflow!.find(
|
||||
workflows = await Db.collections.Workflow.find(
|
||||
Object.assign(query, {
|
||||
where: {
|
||||
id: In(shared.map(({ workflow }) => workflow.id)),
|
||||
@@ -937,7 +937,7 @@ class App {
|
||||
relations = relations.filter((relation) => relation !== 'workflow.tags');
|
||||
}
|
||||
|
||||
const shared = await Db.collections.SharedWorkflow!.findOne({
|
||||
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||
relations,
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
@@ -979,7 +979,7 @@ class App {
|
||||
const { tags, ...rest } = req.body;
|
||||
Object.assign(updateData, rest);
|
||||
|
||||
const shared = await Db.collections.SharedWorkflow!.findOne({
|
||||
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||
relations: ['workflow'],
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
@@ -1041,7 +1041,7 @@ class App {
|
||||
await validateEntity(updateData);
|
||||
}
|
||||
|
||||
await Db.collections.Workflow!.update(workflowId, updateData);
|
||||
await Db.collections.Workflow.update(workflowId, updateData);
|
||||
|
||||
if (tags && !config.getEnv('workflowTagsDisabled')) {
|
||||
const tablePrefix = config.getEnv('database.tablePrefix');
|
||||
@@ -1062,7 +1062,7 @@ class App {
|
||||
|
||||
// We sadly get nothing back from "update". Neither if it updated a record
|
||||
// nor the new value. So query now the hopefully updated entry.
|
||||
const updatedWorkflow = await Db.collections.Workflow!.findOne(workflowId, options);
|
||||
const updatedWorkflow = await Db.collections.Workflow.findOne(workflowId, options);
|
||||
|
||||
if (updatedWorkflow === undefined) {
|
||||
throw new ResponseHelper.ResponseError(
|
||||
@@ -1079,7 +1079,6 @@ class App {
|
||||
}
|
||||
|
||||
await this.externalHooks.run('workflow.afterUpdate', [updatedWorkflow]);
|
||||
// @ts-ignore
|
||||
void InternalHooksManager.getInstance().onWorkflowSaved(req.user.id, updatedWorkflow);
|
||||
|
||||
if (updatedWorkflow.active) {
|
||||
@@ -1093,8 +1092,7 @@ class App {
|
||||
} catch (error) {
|
||||
// If workflow could not be activated set it again to inactive
|
||||
updateData.active = false;
|
||||
// @ts-ignore
|
||||
await Db.collections.Workflow!.update(workflowId, updateData);
|
||||
await Db.collections.Workflow.update(workflowId, updateData);
|
||||
|
||||
// Also set it in the returned data
|
||||
updatedWorkflow.active = false;
|
||||
@@ -1121,7 +1119,7 @@ class App {
|
||||
|
||||
await this.externalHooks.run('workflow.delete', [workflowId]);
|
||||
|
||||
const shared = await Db.collections.SharedWorkflow!.findOne({
|
||||
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||
relations: ['workflow'],
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
@@ -1147,7 +1145,7 @@ class App {
|
||||
await this.activeWorkflowRunner.remove(workflowId);
|
||||
}
|
||||
|
||||
await Db.collections.Workflow!.delete(workflowId);
|
||||
await Db.collections.Workflow.delete(workflowId);
|
||||
|
||||
void InternalHooksManager.getInstance().onWorkflowDeleted(req.user.id, workflowId);
|
||||
await this.externalHooks.run('workflow.afterDelete', [workflowId]);
|
||||
@@ -1246,7 +1244,7 @@ class App {
|
||||
return TagHelpers.getTagsWithCountDb(tablePrefix);
|
||||
}
|
||||
|
||||
return Db.collections.Tag!.find({ select: ['id', 'name'] });
|
||||
return Db.collections.Tag.find({ select: ['id', 'name'] });
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -1265,7 +1263,7 @@ class App {
|
||||
await this.externalHooks.run('tag.beforeCreate', [newTag]);
|
||||
|
||||
await validateEntity(newTag);
|
||||
const tag = await Db.collections.Tag!.save(newTag);
|
||||
const tag = await Db.collections.Tag.save(newTag);
|
||||
|
||||
await this.externalHooks.run('tag.afterCreate', [tag]);
|
||||
|
||||
@@ -1294,7 +1292,7 @@ class App {
|
||||
await this.externalHooks.run('tag.beforeUpdate', [newTag]);
|
||||
|
||||
await validateEntity(newTag);
|
||||
const tag = await Db.collections.Tag!.save(newTag);
|
||||
const tag = await Db.collections.Tag.save(newTag);
|
||||
|
||||
await this.externalHooks.run('tag.afterUpdate', [tag]);
|
||||
|
||||
@@ -1326,7 +1324,7 @@ class App {
|
||||
|
||||
await this.externalHooks.run('tag.beforeDelete', [id]);
|
||||
|
||||
await Db.collections.Tag!.delete({ id });
|
||||
await Db.collections.Tag.delete({ id });
|
||||
|
||||
await this.externalHooks.run('tag.afterDelete', [id]);
|
||||
|
||||
@@ -1591,7 +1589,7 @@ class App {
|
||||
ResponseHelper.send(async (req: WorkflowRequest.GetAllActivationErrors) => {
|
||||
const { id: workflowId } = req.params;
|
||||
|
||||
const shared = await Db.collections.SharedWorkflow!.findOne({
|
||||
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||
relations: ['workflow'],
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
@@ -1794,7 +1792,7 @@ class App {
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
|
||||
// Update the credentials in DB
|
||||
await Db.collections.Credentials!.update(credentialId, newCredentialsData);
|
||||
await Db.collections.Credentials.update(credentialId, newCredentialsData);
|
||||
|
||||
LoggerProxy.verbose('OAuth1 authorization successful for new credential', {
|
||||
userId: req.user.id,
|
||||
@@ -1911,7 +1909,7 @@ class App {
|
||||
// Add special database related data
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
// Save the credentials in DB
|
||||
await Db.collections.Credentials!.update(credentialId, newCredentialsData);
|
||||
await Db.collections.Credentials.update(credentialId, newCredentialsData);
|
||||
|
||||
LoggerProxy.verbose('OAuth1 callback successful for new credential', {
|
||||
userId: req.user?.id,
|
||||
@@ -2026,7 +2024,7 @@ class App {
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
|
||||
// Update the credentials in DB
|
||||
await Db.collections.Credentials!.update(req.query.id as string, newCredentialsData);
|
||||
await Db.collections.Credentials.update(req.query.id as string, newCredentialsData);
|
||||
|
||||
const authQueryParameters = _.get(oauthCredentials, 'authQueryParameters', '') as string;
|
||||
let returnUri = oAuthObj.code.getUri();
|
||||
@@ -2213,7 +2211,7 @@ class App {
|
||||
// Add special database related data
|
||||
newCredentialsData.updatedAt = this.getCurrentDate();
|
||||
// Save the credentials in DB
|
||||
await Db.collections.Credentials!.update(state.cid, newCredentialsData);
|
||||
await Db.collections.Credentials.update(state.cid, newCredentialsData);
|
||||
LoggerProxy.verbose('OAuth2 callback successful for new credential', {
|
||||
userId: req.user?.id,
|
||||
credentialId: state.cid,
|
||||
@@ -2319,7 +2317,7 @@ class App {
|
||||
});
|
||||
}
|
||||
|
||||
const executions = await Db.collections.Execution!.find(findOptions);
|
||||
const executions = await Db.collections.Execution.find(findOptions);
|
||||
|
||||
const { count, estimated } = await getExecutionsCount(countFilter, req.user);
|
||||
|
||||
@@ -2360,7 +2358,7 @@ class App {
|
||||
|
||||
if (!sharedWorkflowIds.length) return undefined;
|
||||
|
||||
const execution = await Db.collections.Execution!.findOne({
|
||||
const execution = await Db.collections.Execution.findOne({
|
||||
where: {
|
||||
id: executionId,
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
@@ -2403,7 +2401,7 @@ class App {
|
||||
|
||||
if (!sharedWorkflowIds.length) return false;
|
||||
|
||||
const execution = await Db.collections.Execution!.findOne({
|
||||
const execution = await Db.collections.Execution.findOne({
|
||||
where: {
|
||||
id: executionId,
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
@@ -2465,9 +2463,7 @@ class App {
|
||||
// Loads the currently saved workflow to execute instead of the
|
||||
// one saved at the time of the execution.
|
||||
const workflowId = fullExecutionData.workflowData.id;
|
||||
const workflowData = (await Db.collections.Workflow!.findOne(
|
||||
workflowId,
|
||||
)) as IWorkflowBase;
|
||||
const workflowData = (await Db.collections.Workflow.findOne(workflowId)) as IWorkflowBase;
|
||||
|
||||
if (workflowData === undefined) {
|
||||
throw new Error(
|
||||
@@ -2549,7 +2545,7 @@ class App {
|
||||
Object.assign(filters, requestFilters);
|
||||
}
|
||||
|
||||
const executions = await Db.collections.Execution!.find({
|
||||
const executions = await Db.collections.Execution.find({
|
||||
where: {
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
...filters,
|
||||
@@ -2564,7 +2560,7 @@ class App {
|
||||
idsToDelete.map(async (id) => binaryDataManager.deleteBinaryDataByExecutionId(id)),
|
||||
);
|
||||
|
||||
await Db.collections.Execution!.delete({ id: In(idsToDelete) });
|
||||
await Db.collections.Execution.delete({ id: In(idsToDelete) });
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -2572,7 +2568,7 @@ class App {
|
||||
// delete executions by IDs, if user may access the underyling worfklows
|
||||
|
||||
if (ids) {
|
||||
const executions = await Db.collections.Execution!.find({
|
||||
const executions = await Db.collections.Execution.find({
|
||||
where: {
|
||||
id: In(ids),
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
@@ -2593,7 +2589,7 @@ class App {
|
||||
idsToDelete.map(async (id) => binaryDataManager.deleteBinaryDataByExecutionId(id)),
|
||||
);
|
||||
|
||||
await Db.collections.Execution!.delete(idsToDelete);
|
||||
await Db.collections.Execution.delete(idsToDelete);
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -2644,7 +2640,7 @@ class App {
|
||||
Object.assign(findOptions.where, { workflowId: In(sharedWorkflowIds) });
|
||||
}
|
||||
|
||||
const executions = await Db.collections.Execution!.find(findOptions);
|
||||
const executions = await Db.collections.Execution.find(findOptions);
|
||||
|
||||
if (!executions.length) return [];
|
||||
|
||||
@@ -2705,7 +2701,7 @@ class App {
|
||||
throw new ResponseHelper.ResponseError('Execution not found', undefined, 404);
|
||||
}
|
||||
|
||||
const execution = await Db.collections.Execution!.findOne({
|
||||
const execution = await Db.collections.Execution.findOne({
|
||||
where: {
|
||||
id: executionId,
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
@@ -2748,7 +2744,7 @@ class App {
|
||||
await Queue.getInstance().stopJob(job);
|
||||
}
|
||||
|
||||
const executionDb = (await Db.collections.Execution?.findOne(
|
||||
const executionDb = (await Db.collections.Execution.findOne(
|
||||
req.params.id,
|
||||
)) as IExecutionFlattedDb;
|
||||
const fullExecutionData = ResponseHelper.unflattenExecutionData(executionDb);
|
||||
@@ -3083,7 +3079,7 @@ async function getExecutionsCount(
|
||||
if (dbType !== 'postgresdb' || filteredFields.length > 0 || user.globalRole.name !== 'owner') {
|
||||
const sharedWorkflowIds = await getSharedWorkflowIds(user);
|
||||
|
||||
const count = await Db.collections.Execution!.count({
|
||||
const count = await Db.collections.Execution.count({
|
||||
where: {
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
...countFilter,
|
||||
@@ -3097,7 +3093,7 @@ async function getExecutionsCount(
|
||||
// Get an estimate of rows count.
|
||||
const estimateRowsNumberSql =
|
||||
"SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'execution_entity';";
|
||||
const rows: Array<{ n_live_tup: string }> = await Db.collections.Execution!.query(
|
||||
const rows: Array<{ n_live_tup: string }> = await Db.collections.Execution.query(
|
||||
estimateRowsNumberSql,
|
||||
);
|
||||
|
||||
@@ -3114,7 +3110,7 @@ async function getExecutionsCount(
|
||||
|
||||
const sharedWorkflowIds = await getSharedWorkflowIds(user);
|
||||
|
||||
const count = await Db.collections.Execution!.count({
|
||||
const count = await Db.collections.Execution.count({
|
||||
where: {
|
||||
workflowId: In(sharedWorkflowIds),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user