Skip to content
Snippets Groups Projects
Commit e0690ca0 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-5009_use_present_link' (#478) from OZG-5009_use_present_link into master

parents fd7d43cf 89dc3267
No related branches found
No related tags found
No related merge requests found
...@@ -37,19 +37,65 @@ describe('BescheidFacade', () => { ...@@ -37,19 +37,65 @@ describe('BescheidFacade', () => {
}); });
describe('createBescheid', () => { describe('createBescheid', () => {
it('should dispatch "createCommand"', () => {
const vorgangWithEingang: VorgangWithEingangResource = createVorgangWithEingangResource(); const vorgangWithEingang: VorgangWithEingangResource = createVorgangWithEingangResource();
const createCommand: CreateCommand = createCreateCommand(CommandOrder.CREATE_BESCHEID); const createCommand: CreateCommand = createCreateCommand(CommandOrder.CREATE_BESCHEID);
facade.createBescheid(vorgangWithEingang, createCommand); describe('with both Links', () => {
it('should dispatch "createCommand" to CREATE_BESCHEID', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.CREATE_BESCHEID,
VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT,
]);
facade.createBescheid(vorgang, createCommand);
expect(store.dispatch).toHaveBeenCalledWith( expect(store.dispatch).toHaveBeenCalledWith(
CommandActions.createCommand({ CommandActions.createCommand({
resource: vorgangWithEingang, resource: vorgang,
linkRel: VorgangWithEingangLinkRel.CREATE_BESCHEID, linkRel: VorgangWithEingangLinkRel.CREATE_BESCHEID,
command: createCommand, command: createCommand,
}), }),
); );
}); });
}); });
describe('with CREATE_BESCHEID_DRAFT link', () => {
it('should dispatch "createCommand" to CREATE_BESCHEID_DRAFT', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT,
]);
facade.createBescheid(vorgang, createCommand);
expect(store.dispatch).toHaveBeenCalledWith(
CommandActions.createCommand({
resource: vorgang,
linkRel: VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT,
command: createCommand,
}),
);
});
});
describe('with CREATE_BESCHEID link', () => {
it('should dispatch "createCommand" to CREATE_BESCHEID', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([
VorgangWithEingangLinkRel.CREATE_BESCHEID,
]);
facade.createBescheid(vorgang, createCommand);
expect(store.dispatch).toHaveBeenCalledWith(
CommandActions.createCommand({
resource: vorgang,
linkRel: VorgangWithEingangLinkRel.CREATE_BESCHEID,
command: createCommand,
}),
);
});
});
it('should emit error if link is missing()', () => {
const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource();
expect(() => facade.createBescheid(vorgang, createCommand)).toThrowError();
});
});
}); });
import { Injectable } from '@angular/core';
import { CommandResource, CreateCommand } from '@alfa-client/command-shared'; import { CommandResource, CreateCommand } from '@alfa-client/command-shared';
import { StateResource } from '@alfa-client/tech-shared'; import { StateResource } from '@alfa-client/tech-shared';
import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; import { VorgangWithEingangLinkRel, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Observable } from 'rxjs'; import { Observable, throwError } from 'rxjs';
import * as CommandActions from '../../../../command-shared/src/lib/+state/command.actions'; import * as CommandActions from '../../../../command-shared/src/lib/+state/command.actions';
import * as BescheidSelectors from './bescheid.selectors'; import * as BescheidSelectors from './bescheid.selectors';
import { hasLink } from '@ngxp/rest';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class BescheidFacade { export class BescheidFacade {
...@@ -18,6 +20,19 @@ export class BescheidFacade { ...@@ -18,6 +20,19 @@ export class BescheidFacade {
public createBescheid( public createBescheid(
vorgangWithEingang: VorgangWithEingangResource, vorgangWithEingang: VorgangWithEingangResource,
command: CreateCommand, command: CreateCommand,
): void {
if (hasLink(vorgangWithEingang, VorgangWithEingangLinkRel.CREATE_BESCHEID)) {
return this.createBescheidKiel(vorgangWithEingang, command);
}
if (hasLink(vorgangWithEingang, VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT)) {
return this.createBescheidDraft(vorgangWithEingang, command);
}
throw new Error('missing Link: CREATE_BESCHEID or CREATE_BESCHEID_DRAFT expected');
}
public createBescheidKiel(
vorgangWithEingang: VorgangWithEingangResource,
command: CreateCommand,
): void { ): void {
this.store.dispatch( this.store.dispatch(
CommandActions.createCommand({ CommandActions.createCommand({
...@@ -27,4 +42,17 @@ export class BescheidFacade { ...@@ -27,4 +42,17 @@ export class BescheidFacade {
}), }),
); );
} }
public createBescheidDraft(
vorgangWithEingang: VorgangWithEingangResource,
command: CreateCommand,
): void {
this.store.dispatch(
CommandActions.createCommand({
resource: vorgangWithEingang,
linkRel: VorgangWithEingangLinkRel.CREATE_BESCHEID_DRAFT,
command,
}),
);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment