Remove non-null assertions for Db collections (#3111)

* 📘 Remove unions to `null`

*  Track `Db` initialization state

* 🔥 Remove non-null assertions

* 👕 Remove lint exceptions

* 🔥 Remove leftover assertion
This commit is contained in:
Iván Ovejero
2022-04-14 09:02:12 +02:00
committed by GitHub
parent e45ac7eb6a
commit 3e5d981f3f
31 changed files with 130 additions and 152 deletions

View File

@@ -107,9 +107,9 @@ export async function executeErrorWorkflow(
const user = await getWorkflowOwner(workflowErrorData.workflow.id!);
if (user.globalRole.name === 'owner') {
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
workflowData = await Db.collections.Workflow.findOne({ id: Number(workflowId) });
} else {
const sharedWorkflowData = await Db.collections.SharedWorkflow!.findOne({
const sharedWorkflowData = await Db.collections.SharedWorkflow.findOne({
where: {
workflow: { id: workflowId },
user,
@@ -121,7 +121,7 @@ export async function executeErrorWorkflow(
}
}
} else {
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
workflowData = await Db.collections.Workflow.findOne({ id: Number(workflowId) });
}
if (workflowData === undefined) {
@@ -426,7 +426,7 @@ export async function saveStaticDataById(
workflowId: string | number,
newStaticData: IDataObject,
): Promise<void> {
await Db.collections.Workflow!.update(workflowId, {
await Db.collections.Workflow.update(workflowId, {
staticData: newStaticData,
});
}
@@ -440,7 +440,7 @@ export async function saveStaticDataById(
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function getStaticDataById(workflowId: string | number) {
const workflowData = await Db.collections.Workflow!.findOne(workflowId, {
const workflowData = await Db.collections.Workflow.findOne(workflowId, {
select: ['staticData'],
});
@@ -586,7 +586,7 @@ export function whereClause({
* Get the IDs of the workflows that have been shared with the user.
*/
export async function getSharedWorkflowIds(user: User): Promise<number[]> {
const sharedWorkflows = await Db.collections.SharedWorkflow!.find({
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
relations: ['workflow'],
where: whereClause({
user,