New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push Changes #1763
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i want to push the data from watermelondb to sync the data with this code
front-end code
import { useEffect, useState } from "react";
import NetInfo from "@react-native-community/netinfo";
import { synchronize, hasUnsyncedChanges } from "@nozbe/watermelondb/sync";
import { database } from "../assets/Model/db";
import API from "../function/API";
import dayjs from "dayjs";
import { Q } from "@nozbe/watermelondb";
import useLoadingStore from "./useLoadingStore";
export const useAllSync = ({ isGetData }) => {
// const . cari connected atau tidak
// setelah itu useEffect untuk ambil data dari API jika connected, jika tidak ambil data dari WatermelonDB
const [connected, setConnected] = useState(undefined);
const { setIsLoading } = useLoadingStore();
async function fetching() {
const isFirstSync = response;
const response = await synchronize({
onWillApplyRemoteChanges: () => {
setIsLoading(false);
},
onDidPullChanges: async () => {
setIsLoading(false);
},
database,
pullChanges: async ({ schemaVersion, lastPulledAt, migration }) => {
setIsLoading(true);
// console.log("last pull All Sync", lastPulledAt);
const urlParams =
last_pulled_at=${ lastPulledAt ? lastPulledAt : "" }&schema_version=${schemaVersion}&migration=${encodeURIComponent( JSON.stringify(migration) )}
;const response = await API.get(
allSync?${urlParams}
);// console.log(JSON.stringify(response, null, 2));
}
useEffect(() => {
const checkInternetConnection = async () => {
try {
const netInfoState = await NetInfo.fetch();
setConnected(netInfoState.isConnected);
} catch (netInfoError) {
console.error("Error checking internet connection", netInfoError);
}
};
checkInternetConnection();
}, []);
return { connected, fetching };
};
back-end
function push_data(Request $request)
{
$validate = Validator::make($request->all(), [
'master_log_activities' => 'array',
'master_log_activities.created' => 'array',
'master_log_activities.updated' => 'array',
'master_machine' => 'array',
'master_machine.created' => 'array',
'master_machine.updated' => 'array',
'master_log_activities.created..master_company_id' => ['required', Rule::exists('master_companies', 'id')],
'master_log_activities.created..master_sector_id' => ['required', Rule::exists('master_sectors', 'id')],
'master_log_activities.created..master_machine_id' => ['required', Rule::exists('master_machines', 'id')],
'master_log_activities.created..master_machine_types_id' => ['required', Rule::exists('master_machine_types', 'id')],
'master_log_activities.created..master_main_activity_id' => ['required', Rule::exists('master_main_activities', 'id')],
'master_log_activities.created..compartement_id' => 'required',
'master_log_activities.created..current_hour_meter' => 'required',
'master_log_activities.created..last_hour_meter' => 'required',
'master_log_activities.created..keterangan' => 'nullable',
'master_log_activities.created..created_at' => 'required|numeric',
'master_log_activities.created.*.updated_at' => 'required|numeric',
if ($validate->fails()) {
return response()->json([
'status_code' => 422,
'status' => 0,
'message' => $validate->errors()->first(),
], 422);
}
DB::commit();
} catch (\Exception $e) {
// Log the exception for debugging
Log::error($e);
DB::rollBack();
}
this code is check by isSync = false then sync the data, but when the data has updated the data not sync updated
console.log data
{
"id": "zvpkGj7ges5VMEvT",
"_status": "synced",
"_changed": "",
"id_master_log_activity": 11,
"master_company_id": 20,
"master_sector_id": 1,
"master_machine_id": 77,
"master_machine_types_id": 3,
"master_main_activity_id": 19,
"compartement_id": "AB701",
"current_hour_meter": 20,
"last_hour_meter": 7,
"keterangan": "2",
"isSync": true,
"isConnected": false,
"created_at": 1710860013000,
"date": 1710860013000,
"deleted_at": 0,
"updated_at": 1711032813000
}
how i can push the data within get pushing by _changed. currently i cannot recieve when the data updated
when isSync = false then sync the data, but when the data has updated the data not sync updated
any idea?
The text was updated successfully, but these errors were encountered: