Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Apr 26, 2024
1 parent d3d0eb0 commit ee23b54
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion client/actions/events/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,11 @@ const post = (original, updates) => (
etag: original._etag,
pubstatus: get(updates, 'pubstatus', POST_STATE.USABLE),
update_method: get(updates, 'update_method.value', EVENTS.UPDATE_METHODS[0].value),
failed_planning_ids: get(updates, 'failed_planning_ids', []),
}).then(
(data) => Promise.all([
dispatch(self.fetchById(original._id, {force: true})),
{failedPlanningIds: data?._id?.failed_planning_ids}
{failedPlanningIds: data?.failed_planning_ids}
]),
(error) => Promise.reject(error)
)
Expand Down
4 changes: 1 addition & 3 deletions client/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,7 @@ const post = (original, updates = {}, withConfirmation = true) => (
failedPlanningIds?.map((failedItem) => notifyError(
notify,
failedItem,
gettext(
'Related item {{ itemId }} Post Validation Failed',
{itemId: failedItem?._id})));
gettext('Some related planning item post validation failed')));

return Promise.resolve(item);
},
Expand Down
12 changes: 3 additions & 9 deletions server/features/events_post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1242,18 +1242,12 @@ Feature: Events Post
"event": "#EVENT1._id#",
"etag": "#EVENT1._etag#",
"pubstatus": "usable",
"update_method": "single"
"update_method": "single",
"failed_planning_ids": []
}
"""
Then we get OK response
Then we get updated response
"""
{
"_id": {
"failed_planning_ids": [{
"_id": "123", "error": ["Related planning : SLUGLINE is a required field"]
}],
"item_id": "#EVENT1._id#"
}
}
{"failed_planning_ids": [{"_id": "123", "error": ["Related planning : SLUGLINE is a required field"]}]}
"""
10 changes: 7 additions & 3 deletions server/planning/events/events_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class EventsPostResource(EventsResource):
},
# used to only repost an item when data changes from backend (update_repetitions)
"repost_on_update": {"type": "boolean", "required": False, "default": False},
"failed_planning_ids": {
"type": "list",
"required": False,
"schema": {"type": "dict", "schema": {}},
},
}

url = "events/post"
Expand All @@ -48,7 +53,6 @@ class EventsPostResource(EventsResource):
class EventsPostService(EventsBaseService):
def create(self, docs):
ids = []
failed_planning_ids = []
events_service = get_resource_service("events")
for doc in docs:
event = events_service.find_one(req=None, _id=doc["event"])
Expand All @@ -65,9 +69,9 @@ def create(self, docs):

ids.append(event_id)
if planning_ids:
failed_planning_ids.extend(planning_ids)
doc["failed_planning_ids"].extend(planning_ids)

return [{"item_id": event_id, "failed_planning_ids": failed_planning_ids}] if failed_planning_ids else ids
return ids

@staticmethod
def validate_post_state(new_post_state):
Expand Down
5 changes: 5 additions & 0 deletions server/planning/events/events_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,9 @@
},
},
},
"failed_planning_ids": {
"type": "list",
"required": False,
"schema": {"type": "dict", "schema": {}},
},
} # end events_schema:

0 comments on commit ee23b54

Please sign in to comment.