Skip to content

Commit

Permalink
adjust app sync flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Janderson Souza Matias authored and Janderson Souza Matias committed Sep 18, 2023
1 parent d71b08d commit 1f9de33
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/screens/SyncDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const SyncDetails: React.FC = () => {
useEffect(() => {
if (isConnected) {
setIsLoading(true);
SyncService.trySyncData().then(() => setIsLoading(false));
SyncService.trySyncData()
.then(() => setIsLoading(false))
.finally(() => setIsLoading(false));
}
}, [isConnected]);

Expand Down
5 changes: 3 additions & 2 deletions src/services/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const SyncService = {
pendingSessions: number;
}> => {
const db = await getDBConnection();

const results = await db.executeSql(`
SELECT
(SELECT COUNT(*) FROM teacher where _status != 'synced') AS pendingTeachers,
Expand All @@ -49,7 +50,7 @@ const SyncService = {
const lastSync = await StorageService.getLastSync();

const response = await axios.post<SyncData>(
'https://api-sl.coachdigital.org/sync',
'https://29b5-177-208-184-177.ngrok-free.app/sync',
{
changes,
lastSync,
Expand All @@ -58,7 +59,7 @@ const SyncService = {
deviceId: await DeviceInfo.getUniqueId(),
...(await GeolocationService.getLocation()),
},
{headers: {token: currentSchool?.key}},
{headers: {token: currentSchool?.schoolKey}},
);

if (response.status !== 200) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/school.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type School = {
name: string;
emis_number: string;

key?: string;
schoolKey?: string;
created_at: Date;
updated_at: Date;
teachersCount: number;
Expand Down

0 comments on commit 1f9de33

Please sign in to comment.