Skip to content

Commit

Permalink
fix: every serverdate structure based on version
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Jan 6, 2025
1 parent c1d2a7b commit 7f3de06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
// @flow
import { batchActions } from 'redux-batched-actions';
import { ofType } from 'redux-observable';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { switchMap } from 'rxjs/operators';
import uuid from 'd2-utilizr/lib/uuid';
import moment from 'moment';
import { actionTypes, batchActionTypes, startAddNoteForEnrollment, addEnrollmentNote }
from './WidgetEnrollmentNote.actions';

const createServerData = (eventId, note, useNewEndpoint) => {
if (useNewEndpoint) {
return { value: note };
}
return { notes: [{ value: note }] };
};

export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(actionTypes.REQUEST_ADD_NOTE_FOR_ENROLLMENT),
switchMap((action) => {
const state = store.value;
const { enrollmentId, note } = action.payload;
const useNewEndpoint = featureAvailable(FEATURES.newNoteEndpoint);
return querySingleResource({
resource: 'me',
params: {
Expand All @@ -22,9 +31,7 @@ export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxS
const { firstName, surname, userName } = user;
const clientId = uuid();

const serverData = {
value: note,
};
const serverData = createServerData(note, useNewEndpoint);

const clientNote = {
value: note,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { batchActions } from 'redux-batched-actions';
import { ofType } from 'redux-observable';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { map, switchMap } from 'rxjs/operators';
import uuid from 'd2-utilizr/lib/uuid';
import moment from 'moment';
Expand All @@ -18,13 +19,21 @@ import {
removeNote,
} from '../DataEntry/actions/dataEntry.actions';

const createServerData = (eventId, note, useNewEndpoint) => {
if (useNewEndpoint) {
return { event: eventId, value: note };
}
return { event: eventId, notes: [{ value: note }] };
};

export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(actionTypes.REQUEST_ADD_NOTE_FOR_EVENT),
switchMap((action) => {
const state = store.value;
const payload = action.payload;
const eventId = state.dataEntries[payload.dataEntryId].eventId;
const useNewEndpoint = featureAvailable(FEATURES.newNoteEndpoint);
return querySingleResource({
resource: 'me',
params: {
Expand All @@ -34,10 +43,7 @@ export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore,
const { firstName, surname, userName } = user;
const clientId = uuid();

const serverData = {
event: eventId,
value: payload.note,
};
const serverData = createServerData(eventId, payload.note, useNewEndpoint);

const clientNote = {
value: payload.note,
Expand Down

0 comments on commit 7f3de06

Please sign in to comment.