Skip to content

Commit

Permalink
fix: deprecate posthouseholdRelation
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Oct 8, 2022
1 parent b620ef0 commit bd9cf54
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {

import {
postHousehold,
postHouseholdWithRelation
} from '../../../../modules/cached-resources';
import I18n from '../../../../modules/i18n';
import { layout, theme } from '../../../../modules/theme';
Expand Down Expand Up @@ -64,7 +63,7 @@ const HouseholdManager = (props) => {
}
};

postHouseholdWithRelation(postParams).then((household) => {
postHousehold(postParams).then((household) => {
const { objectId } = household;
setFieldValue(formikKey, objectId);
});
Expand Down
10 changes: 5 additions & 5 deletions modules/cached-resources/Post/__tests__/post.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import uuid from 'react-native-uuid';

import checkOnlineStatus from '../../../offline';
import {
postHousehold, postHouseholdWithRelation, postIdentificationForm, postSupplementaryForm
postHousehold, postIdentificationForm, postSupplementaryForm
} from '../post';

jest.mock('../../../offline', () => jest.fn());
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('test offline', () => {

const postedSupplementaryForm = await postSupplementaryForm(postParams);

expect(postedSupplementaryForm.parseParentClassID).toContain('PatientID'); // signifies it is an offline form
expect(postedSupplementaryForm[0].parseParentClassID).toContain('PatientID'); // signifies it is an offline form
});

test('postHousehold', async () => {
Expand Down Expand Up @@ -114,9 +114,9 @@ describe('test offline', () => {
}
};

const postedHouseholdWithRelation = await postHouseholdWithRelation(postParams);
const postedHouseholdWithRelation = await postHousehold(postParams);

expect(postedHouseholdWithRelation).toHaveProperty('objectId');
expect(postedHouseholdWithRelation.objectId).toContain('Household');
expect(postedHouseholdWithRelation[0].localObject).toHaveProperty('objectId');
expect(postedHouseholdWithRelation[0].localObject.objectId).toContain('Household');
});
});
26 changes: 0 additions & 26 deletions modules/cached-resources/Post/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,9 @@ const postHousehold = async (postParams) => {
});
};

const postHouseholdWithRelation = async (postParams) => {
const isConnected = await checkOnlineStatus();

if (isConnected) {
return postObjectsToClassWithRelation(postParams).then((result) => result.id).catch((er) => er);
}

return getData('offlineHouseholdsRelation').then(async (householdsRelation) => {
const allOfflineHouseholdsWithRelationships = householdsRelation;
const householdParams = postParams;
const { localObject } = householdParams;
localObject.objectId = `Household-${generateRandomID()}`;

if (allOfflineHouseholdsWithRelationships) {
const forms = allOfflineHouseholdsWithRelationships.concat(householdParams);
await storeData(forms, 'offlineHouseholdsRelation');
return localObject;
}

const householdData = [householdParams];
await storeData(householdData, 'offlineHouseholdsRelation');
return localObject;
});
};

export {
postAssetForm,
postHousehold,
postHouseholdWithRelation,
postIdentificationForm,
postSupplementaryAssetForm,
postSupplementaryForm
Expand Down

0 comments on commit bd9cf54

Please sign in to comment.