From 62e90129a45b852b5f8fece80e8ed3f3a363ac9c Mon Sep 17 00:00:00 2001 From: Martin <git@mail.de> Date: Mon, 14 Apr 2025 12:02:10 +0200 Subject: [PATCH] OZG-7872 add type; update es2018 -> ES2022 --- .../src/lib/command.util.spec.ts | 26 +++++++++---------- .../command-shared/src/lib/command.util.ts | 19 ++++++-------- .../libs/command-shared/tsconfig.lib.json | 4 +-- .../src/lib/+state/vorgang.reducer.spec.ts | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/alfa-client/libs/command-shared/src/lib/command.util.spec.ts b/alfa-client/libs/command-shared/src/lib/command.util.spec.ts index f3cd21cee6..7f819fe408 100644 --- a/alfa-client/libs/command-shared/src/lib/command.util.spec.ts +++ b/alfa-client/libs/command-shared/src/lib/command.util.spec.ts @@ -26,7 +26,7 @@ import { getUrl } from '@ngxp/rest'; import { createCommandErrorResource, createCommandListResource, createCommandResource } from 'libs/command-shared/test/command'; import { CommandLinkRel } from './command.linkrel'; import { CommandErrorMessage } from './command.message'; -import { CommandListResource, CommandResource, CommandStatus } from './command.model'; +import { CommandListResource, CommandOrder, CommandResource, CommandStatus, PendingCommandMap } from './command.model'; import { buildPendingCommandMap, getPendingCommandByOrder, @@ -42,12 +42,12 @@ import { describe('CommandUtil', () => { describe('isRevokeable', () => { it('should return true if Link exists', () => { - const result = isRevokeable(createCommandResource([CommandLinkRel.REVOKE])); + const result: boolean = isRevokeable(createCommandResource([CommandLinkRel.REVOKE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isRevokeable(createCommandResource()); + const result: boolean = isRevokeable(createCommandResource()); expect(result).toBe(false); }); @@ -55,12 +55,12 @@ describe('CommandUtil', () => { describe('isPending', () => { it('should return true if Link exists', () => { - const result = isPending(createCommandResource([CommandLinkRel.UPDATE])); + const result: boolean = isPending(createCommandResource([CommandLinkRel.UPDATE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isPending(createCommandResource()); + const result: boolean = isPending(createCommandResource()); expect(result).toBe(false); }); @@ -68,12 +68,12 @@ describe('CommandUtil', () => { describe('isDone', () => { it('should return true if Link exists', () => { - const result = isDone(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE])); + const result: boolean = isDone(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isDone(createCommandResource()); + const result: boolean = isDone(createCommandResource()); expect(result).toBe(false); }); @@ -81,27 +81,27 @@ describe('CommandUtil', () => { describe('hasError', () => { it('should be true if no update link is present and command has error message', () => { - const result = hasCommandError(createCommandErrorResource()); + const result: boolean = hasCommandError(createCommandErrorResource()); expect(result).toBeTruthy(); }); it('should be false if update link is present', () => { - const result = hasCommandError(createCommandResource([CommandLinkRel.UPDATE])); + const result: boolean = hasCommandError(createCommandResource([CommandLinkRel.UPDATE])); expect(result).toBeFalsy(); }); it('should be false if error message is not present', () => { - const result = hasCommandError(createCommandResource()); + const result: boolean = hasCommandError(createCommandResource()); expect(result).toBeFalsy(); }); }); describe('getPendingCommandByOrder', () => { - const order: string = 'dummyOrder'; - const anotherOrder: string = 'anotherOrder'; + const order: CommandOrder = <CommandOrder>'dummyOrder'; + const anotherOrder: CommandOrder = <CommandOrder>'anotherOrder'; it('should return null on non existing pending command', () => { const listResource: CommandListResource = createCommandListResource(); @@ -142,7 +142,7 @@ describe('CommandUtil', () => { }; const commandList: CommandListResource = createCommandListResource([pendingCommand1, pendingCommand2]); - const map = buildPendingCommandMap(commandList); + const map: PendingCommandMap = buildPendingCommandMap(commandList); expect(map[getUrl(pendingCommand1, CommandLinkRel.RELATED_RESOURCE)]).toEqual(createStateResource(pendingCommand1)); expect(map[getUrl(pendingCommand2, CommandLinkRel.RELATED_RESOURCE)]).toEqual(createStateResource(pendingCommand2)); diff --git a/alfa-client/libs/command-shared/src/lib/command.util.ts b/alfa-client/libs/command-shared/src/lib/command.util.ts index 820a223daa..d804d19ac3 100644 --- a/alfa-client/libs/command-shared/src/lib/command.util.ts +++ b/alfa-client/libs/command-shared/src/lib/command.util.ts @@ -26,7 +26,7 @@ import { getEmbeddedResource, getUrl, hasLink, ResourceUri } from '@ngxp/rest'; import { isEmpty, isNil, isObject } from 'lodash-es'; import { CommandLinkRel, CommandListLinkRel } from './command.linkrel'; import { CommandErrorMessage } from './command.message'; -import { CommandListResource, CommandResource } from './command.model'; +import { CommandListResource, CommandOrder, CommandResource, PendingCommandMap } from './command.model'; export function isRevokeable(commandResource: CommandResource): boolean { return hasLink(commandResource, CommandLinkRel.REVOKE); @@ -52,22 +52,19 @@ export function notHasCommandError(commandResource: CommandResource): boolean { return !hasCommandError(commandResource); } -export function getPendingCommandByOrder(pendingCommands: CommandListResource, commandOrder: any[]): CommandResource { +export function getPendingCommandByOrder(pendingCommands: CommandListResource, commandOrder: CommandOrder[]): CommandResource { const commands: CommandResource[] = getEmbeddedCommandResources(pendingCommands).filter((command: CommandResource) => commandOrder.includes(command.order), ); return commands.length > 0 ? commands[0] : null; } -export function buildPendingCommandMap(commandList: CommandListResource): any { - let map = {}; - const commands: CommandResource[] = getEmbeddedCommandResources(commandList); - commands.forEach((command: CommandResource) => { - if (hasLink(command, CommandLinkRel.RELATED_RESOURCE)) { - map[getUrl(command, CommandLinkRel.RELATED_RESOURCE)] = createStateResource(command); - } - }); - return map; +export function buildPendingCommandMap(commandList: CommandListResource): PendingCommandMap { + return Object.fromEntries( + getEmbeddedCommandResources(commandList) + .filter((command: CommandResource) => hasLink(command, CommandLinkRel.RELATED_RESOURCE)) + .map((command: CommandResource) => [getUrl(command, CommandLinkRel.RELATED_RESOURCE), createStateResource(command)]), + ); } function getEmbeddedCommandResources(commandListResource: CommandListResource): CommandResource[] { diff --git a/alfa-client/libs/command-shared/tsconfig.lib.json b/alfa-client/libs/command-shared/tsconfig.lib.json index 464f01e6b2..4eed46aa15 100644 --- a/alfa-client/libs/command-shared/tsconfig.lib.json +++ b/alfa-client/libs/command-shared/tsconfig.lib.json @@ -2,12 +2,12 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "target": "es2015", + "target": "ES2022", "declaration": true, "declarationMap": true, "inlineSources": true, "types": [], - "lib": ["dom", "es2018"] + "lib": ["dom", "ES2022"] }, "angularCompilerOptions": { "skipTemplateCodegen": true, diff --git a/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts b/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts index 70e6360f76..ae595493a6 100644 --- a/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts +++ b/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts @@ -536,7 +536,7 @@ describe('Vorgang Reducer', () => { it('should set pending commands map', () => { const pendingCommandMap: PendingCommandMap = createPendingCommandMap(); jest.spyOn(CommandUtil, 'buildPendingCommandMap').mockReturnValue(pendingCommandMap); - const action = VorgangActions.loadPendingCommandListSuccess({ commandList: createCommandListResource() }); + const action: Action<string> = VorgangActions.loadPendingCommandListSuccess({ commandList: createCommandListResource() }); const state: VorgangState = reducer(initialState, action); -- GitLab