Skip to content

Commit

Permalink
update authoring storage to prepare entity for client/server
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis committed Dec 23, 2024
1 parent 6b4bb76 commit 45d6be9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {superdeskApi} from '../../superdeskApi';
import {getProfile} from './profile';
import {omitFields} from './utils';
import {AutoSavePlanningItem, NoAutoSavePlanningItem} from './authoring-autosave';
import {planningUtils} from '../../utils';

const getAutosavedPlanningItem = (id: IPlanningItem['_id']): Promise<IPlanningItem | null> => {
return new Promise((resolve) => {
Expand All @@ -30,7 +31,10 @@ export const authoringStoragePlanningItemHttp: IAuthoringStorage<IPlanningItem>
path: `/planning/${id}`,
})
]).then(([autosaved, saved]) => {
return {autosaved, saved};
return {
autosaved: autosaved == null ? null : planningUtils.modifyForClient(autosaved),
saved: planningUtils.modifyForClient(saved),
};
});
},

Expand All @@ -47,7 +51,12 @@ export const authoringStoragePlanningItemHttp: IAuthoringStorage<IPlanningItem>
return httpRequestJsonLocal<IPlanningItem>({
method: 'PATCH',
path: `/planning/${original._id}`,
payload: omitFields(generatePatch(original, current)),
payload: omitFields(
generatePatch(
planningUtils.modifyForServer(original),
planningUtils.modifyForServer(current),
),
),
headers: {
'If-Match': original._etag,
},
Expand Down
2 changes: 1 addition & 1 deletion client/utils/planning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ function getPlanningActionsForUiFrameworkMenu(data: IGetPlanningActionArgs): Arr
return toUIFrameworkInterface(planningUtils.getPlanningActions(data));
}

export function modifyForClient(plan: Partial<IPlanningItem>): Partial<IPlanningItem> {
export function modifyForClient<T extends IPlanningItem | Partial<IPlanningItem>>(plan: T): T {
sanitizeItemFields(plan);

// The `_status` field is available when the item comes from a POST/PATCH request
Expand Down

0 comments on commit 45d6be9

Please sign in to comment.