efficiency and exception change

This commit is contained in:
Julian Krauser 2024-09-06 10:08:19 +02:00
parent 4048c21c1f
commit 88212ff79b
32 changed files with 121 additions and 124 deletions

View file

@ -22,7 +22,7 @@ export default abstract class AwardCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating award");
throw new InternalException("Failed creating award", err);
});
}
@ -42,7 +42,7 @@ export default abstract class AwardCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating award");
throw new InternalException("Failed updating award", err);
});
}
@ -60,7 +60,7 @@ export default abstract class AwardCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting award");
throw new InternalException("Failed deleting award", err);
});
}
}

View file

@ -27,7 +27,7 @@ export default abstract class CommunicationTypeCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating communicationType");
throw new InternalException("Failed creating communicationType", err);
});
}
@ -48,7 +48,7 @@ export default abstract class CommunicationTypeCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating communicationType");
throw new InternalException("Failed updating communicationType", err);
});
}
@ -66,7 +66,7 @@ export default abstract class CommunicationTypeCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting communicationType");
throw new InternalException("Failed deleting communicationType", err);
});
}
}

View file

@ -26,7 +26,7 @@ export default abstract class ExecutivePositionCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating executivePosition");
throw new InternalException("Failed creating executivePosition", err);
});
}
@ -46,7 +46,7 @@ export default abstract class ExecutivePositionCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating executivePosition");
throw new InternalException("Failed updating executivePosition", err);
});
}
@ -64,7 +64,7 @@ export default abstract class ExecutivePositionCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting executivePosition");
throw new InternalException("Failed deleting executivePosition", err);
});
}
}

View file

@ -31,7 +31,7 @@ export default abstract class InviteCommandHandler {
return token;
})
.catch((err) => {
throw new InternalException("Failed saving invite");
throw new InternalException("Failed saving invite", err);
});
}
@ -50,7 +50,7 @@ export default abstract class InviteCommandHandler {
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed invite removal");
throw new InternalException("failed invite removal", err);
});
}
}

View file

@ -26,7 +26,7 @@ export default abstract class MembershipStatusCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating membershipStatus");
throw new InternalException("Failed creating membershipStatus", err);
});
}
@ -46,7 +46,7 @@ export default abstract class MembershipStatusCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating membershipStatus");
throw new InternalException("Failed updating membershipStatus", err);
});
}
@ -64,7 +64,7 @@ export default abstract class MembershipStatusCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting membershipStatus");
throw new InternalException("Failed deleting membershipStatus", err);
});
}
}

View file

@ -27,7 +27,7 @@ export default abstract class QualificationCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating qualification");
throw new InternalException("Failed creating qualification", err);
});
}
@ -48,7 +48,7 @@ export default abstract class QualificationCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating qualification");
throw new InternalException("Failed updating qualification", err);
});
}
@ -66,7 +66,7 @@ export default abstract class QualificationCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting qualification");
throw new InternalException("Failed deleting qualification", err);
});
}
}

View file

@ -36,7 +36,7 @@ export default abstract class RefreshCommandHandler {
return refreshToken;
})
.catch((err) => {
throw new InternalException("Failed saving refresh token");
throw new InternalException("Failed saving refresh token", err);
});
}
@ -55,7 +55,7 @@ export default abstract class RefreshCommandHandler {
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed refresh removal");
throw new InternalException("failed refresh removal", err);
});
}
@ -72,7 +72,7 @@ export default abstract class RefreshCommandHandler {
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed expired refresh removal");
throw new InternalException("failed expired refresh removal", err);
});
}
}

View file

@ -22,7 +22,7 @@ export default abstract class RoleCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating role");
throw new InternalException("Failed creating role", err);
});
}
@ -42,7 +42,7 @@ export default abstract class RoleCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating role");
throw new InternalException("Failed updating role", err);
});
}
@ -60,7 +60,7 @@ export default abstract class RoleCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting role");
throw new InternalException("Failed deleting role", err);
});
}
}

View file

@ -28,47 +28,45 @@ export default abstract class RolePermissionCommandHandler {
let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateRolePermissions.permissions);
let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateRolePermissions.permissions);
for (let permission of newPermissions) {
await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, permission);
}
for (let permission of removePermissions) {
await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, permission);
}
await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, newPermissions);
await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, removePermissions);
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed saving role permissions");
throw new InternalException("Failed saving role permissions", err);
});
}
private static async updatePermissionsAdd(
manager: EntityManager,
roleId: number,
permission: PermissionString
permissions: Array<PermissionString>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(rolePermission)
.values({
permission: permission,
roleId: roleId,
})
.values(
permissions.map((p) => ({
permission: p,
roleId: roleId,
}))
)
.orIgnore()
.execute();
}
private static async updatePermissionsRemove(
manager: EntityManager,
roleId: number,
permission: PermissionString
permissions: Array<PermissionString>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(rolePermission)
.where("userId = :id", { id: roleId })
.andWhere("permission = :permission", { permission: permission })
.where("roleId = :id", { id: roleId })
.andWhere("permission IN (:...permission)", { permission: permissions })
.execute();
}
@ -91,7 +89,7 @@ export default abstract class RolePermissionCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed saving role permission");
throw new InternalException("Failed saving role permission", err);
});
}
@ -110,7 +108,7 @@ export default abstract class RolePermissionCommandHandler {
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed role permission removal");
throw new InternalException("failed role permission removal", err);
});
}
}

View file

@ -28,7 +28,7 @@ export default abstract class UserCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed saving user");
throw new InternalException("Failed saving user", err);
});
}
@ -51,7 +51,7 @@ export default abstract class UserCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating user");
throw new InternalException("Failed updating user", err);
});
}
@ -77,7 +77,7 @@ export default abstract class UserCommandHandler {
})
.then(() => {})
.catch((err) => {
throw new InternalException("Failed saving user roles");
throw new InternalException("Failed saving user roles", err);
});
}
@ -103,7 +103,7 @@ export default abstract class UserCommandHandler {
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting user");
throw new InternalException("Failed deleting user", err);
});
}
}

View file

@ -27,48 +27,45 @@ export default abstract class UserPermissionCommandHandler {
let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateUserPermissions.permissions);
let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateUserPermissions.permissions);
for (let permission of newPermissions) {
await this.updatePermissionsAdd(manager, updateUserPermissions.userId, permission);
}
for (let permission of removePermissions) {
await this.updatePermissionsRemove(manager, updateUserPermissions.userId, permission);
}
await this.updatePermissionsAdd(manager, updateUserPermissions.userId, newPermissions);
await this.updatePermissionsRemove(manager, updateUserPermissions.userId, removePermissions);
})
.then(() => {})
.catch((err) => {
console.log(err);
throw new InternalException("Failed saving user permissions");
throw new InternalException("Failed saving user permissions", err);
});
}
private static async updatePermissionsAdd(
manager: EntityManager,
userId: number,
permission: PermissionString
permissions: Array<PermissionString>
): Promise<InsertResult> {
return await manager
.createQueryBuilder()
.insert()
.into(userPermission)
.values({
permission: permission,
userId: userId,
})
.values(
permissions.map((p) => ({
permission: p,
userId: userId,
}))
)
.orIgnore()
.execute();
}
private static async updatePermissionsRemove(
manager: EntityManager,
userId: number,
permission: PermissionString
permissions: Array<PermissionString>
): Promise<DeleteResult> {
return await manager
.createQueryBuilder()
.delete()
.from(userPermission)
.where("userId = :id", { id: userId })
.andWhere("permission = :permission", { permission: permission })
.andWhere("permission IN (:...permission)", { permission: permissions })
.execute();
}
@ -91,7 +88,7 @@ export default abstract class UserPermissionCommandHandler {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed saving user permission");
throw new InternalException("Failed saving user permission", err);
});
}
@ -110,7 +107,7 @@ export default abstract class UserPermissionCommandHandler {
.execute()
.then((res) => {})
.catch((err) => {
throw new InternalException("failed user permission removal");
throw new InternalException("failed user permission removal", err);
});
}
}