Skip to content

Commit

Permalink
feat(crew): add prpagation of event change to event reducer
Browse files Browse the repository at this point in the history
While the attendances, duties and events features are otherwise
separate, upstream changes to attendances and duties must be propagated
to the events list and therefore agenda feed. Events are:

 - A duty is created (CreateSuccess).
 - A duty is destroyed (DestroySuccess).
 - An attendance is updated (UpdateSuccess).

Changes:

- Modules
  - Add DurationModule
    - Encapsulate DurationComponent and DurationPipe. These are used
      together in duties and attendances
- Pipes
  - DurationPipe
    - Refactor. The original code threw an error when called as I used
      deprecated syntax. See linked GitHub issue for more information.
    - Update calling references.
- Builders
  - CalendarEventbuilder
    - Add ID getters for attendance and duty records. EventEffects use
      these getters.
    - Update internal refernces to use these.
- Effects/Reducers
  - Add EventEffects
    - Forward propagate appropriate attendance and duty changes to the
      events refucer.
- Add tests for all affected code.

See: moment/moment#1048 (comment)
Closes: d4h/decisions-project#4472
  • Loading branch information
bhalash committed Apr 15, 2020
1 parent 21ab297 commit d212767
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@d4h/angular",
"version": "8.1.2",
"version": "8.1.3",
"description": "Angular services and interfaces for the D4H API.",
"homepage": "https://d4htechnologies.com/",
"repository": {
Expand Down
23 changes: 18 additions & 5 deletions src/lib/builders/calendar-event.builder.ts
Expand Up @@ -31,15 +31,15 @@ export class CalendarEventBuilder {
return {
color: undefined,
end: attendance.enddate,
id: `${this.activityType(attendance)}-${attendance.id}`,
id: this.attendanceId(attendance),
start: attendance.date,
text: this.attendanceText(attendance),

entity: {
id: attendance.id,
member_id: attendance.member.id,
status: attendance.status,
type: this.activityType(attendance)
type: this.activityType(attendance.activity.type)
}
};
}
Expand All @@ -48,7 +48,7 @@ export class CalendarEventBuilder {
return {
color: undefined,
end: duty.enddate,
id: `${CalendarEventType.Duty}-${duty.id}`,
id: this.dutyId(duty),
start: duty.date,
text: this.dutyText(duty),

Expand All @@ -61,9 +61,22 @@ export class CalendarEventBuilder {
};
}

// Also used externally to get ID during change events.
attendanceId({
activity = { type: undefined },
id
}: { id: number, activity: { type: ActivityType } }): string {
return `${this.activityType(activity.type)}-${id}`;
}

// Also used externally to get ID during change events.
dutyId({ id }: { id: number }): string {
return `${CalendarEventType.Duty}-${id}`;
}

// CalendarEventType effectively extends ActivityType.
private activityType(attendance: Attendance): CalendarEventType {
switch (attendance.activity.type) {
private activityType(type: ActivityType): CalendarEventType {
switch (type) {
case ActivityType.Event:
return CalendarEventType.Event;
case ActivityType.Exercise:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/providers/config.provider.ts
Expand Up @@ -35,7 +35,7 @@ export interface Config {
*/

export const CLIENT_NAME = 'D4H API CLIENT';
export const CLIENT_VERSION = '8.1.2';
export const CLIENT_VERSION = '8.1.3';

export const CLIENT_CONFIG = new InjectionToken<Observable<Config>>(
'CLIENT_CONFIGURATION'
Expand Down
1 change: 1 addition & 0 deletions src/public-api.ts
@@ -1,4 +1,5 @@
export * from './lib/api';
export * from './lib/builders';
export * from './lib/models';
export * from './lib/permissions';
export * from './lib/providers';
Expand Down
46 changes: 46 additions & 0 deletions src/spec/builders/calendar-event.builder.spec.ts
Expand Up @@ -151,4 +151,50 @@ describe('CalendarEventBuilder', () => {
expect(builder.duty(duty).text).toBe(undefined);
});
});

describe('attendanceId', () => {
let attendance: Attendance;
let type: CalendarEventType;

beforeEach(() => {
attendance = Factory.build<Attendance>('Attendance');
type = (attendance.activity.type as any) as CalendarEventType;
});

it('should be a function', () => {
expect(typeof builder.attendance).toBe('function');
});

it('should return appropriate ID and type for an attendance', () => {
expect(builder.attendanceId(attendance)).toBe(
`${type}-${attendance.id}`
);
});

it('should default to CalendarEventType.Activity when no type is given', () => {
attendance.activity = undefined;

expect(builder.attendanceId(attendance)).toBe(
`${CalendarEventType.Activity}-${attendance.id}`
);
});
});

describe('dutyId', () => {
let duty: Duty;

beforeEach(() => {
duty = Factory.build<Duty>('Duty');
});

it('should be a function', () => {
expect(typeof builder.duty).toBe('function');
});

it('should return appropriate ID for an duty', () => {
expect(builder.dutyId(duty)).toBe(
`${CalendarEventType.Duty}-${duty.id}`
);
});
});
});

0 comments on commit d212767

Please sign in to comment.