Skip to content

Commit

Permalink
[#192] Implement case updated_by in IncomeDriverEntry/segment
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 5, 2024
1 parent 54e621d commit 5cc6a6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 11 additions & 4 deletions backend/routes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import db.crud_living_income_benchmark as crud_lib
import db.crud_case as crud_case

from fastapi import APIRouter, Request, Depends, Response
from fastapi import APIRouter, Request, Depends, Response, Query
from fastapi.security import HTTPBearer, HTTPBasicCredentials as credentials
from sqlalchemy.orm import Session
from typing import List
from typing import List, Optional
from http import HTTPStatus
from middleware import verify_case_editor, verify_case_viewer

Expand Down Expand Up @@ -53,14 +53,19 @@ def create_segment(
def update_segment(
req: Request,
payload: List[SegmentUpdateBase],
updated: Optional[bool] = Query(None),
session: Session = Depends(get_session),
credentials: credentials = Depends(security),
):
case_id = payload[0].case
verify_case_editor(
user = verify_case_editor(
session=session, authenticated=req.state.authenticated, case_id=case_id
)
segments = crud_segment.update_segment(session=session, payloads=payload)
if updated:
crud_case.case_updated_by(
session=session, case_id=case_id, user_id=user.id
)
return [s.serialize for s in segments]


Expand Down Expand Up @@ -104,7 +109,9 @@ def get_segments_by_case_id(
session=session, authenticated=req.state.authenticated, case_id=case_id
)
case = crud_case.get_case_by_id(session=session, id=case_id)
segments = crud_segment.get_segments_by_case_id(session=session, case_id=case_id)
segments = crud_segment.get_segments_by_case_id(
session=session, case_id=case_id
)
segments = [s.serialize_with_answers for s in segments]
for segment in segments:
benchmark = crud_lib.get_by_country_region_year(
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/cases/components/IncomeDriverDataEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const IncomeDriverDataEntry = ({
return !equal;
})
.filter((x) => x)?.length > 0;
console.info(isUpdated, "UPDATED");

if (postFormValues.length) {
const postPayloads = generateSegmentPayloads(
Expand All @@ -97,7 +96,7 @@ const IncomeDriverDataEntry = ({
currentCaseId,
commodityList
);
apiCalls.push(api.put("/segment", putPayloads));
apiCalls.push(api.put(`/segment?updated=${isUpdated}`, putPayloads));
}
// api call
Promise.all(apiCalls)
Expand Down

0 comments on commit 5cc6a6d

Please # to comment.