Skip to content

Commit

Permalink
add logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Dec 6, 2024
1 parent 60b5536 commit e279062
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/api/SharedWMAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export const addGoalsInSharedWM = async (goals: GoalItem[], relId: string) => {
};

export const getSharedWMGoal = async (goalId: string) => {
const goal: GoalItem[] = await db.sharedWMCollection.where("id").equals(goalId).sortBy("createdAt");
return goal[0];
return db.sharedWMCollection.get(goalId);
};

export const getSharedWMGoalById = (id: string) => {
Expand Down
17 changes: 16 additions & 1 deletion src/helpers/InboxProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,33 @@ export const handleIncomingChanges = async (payload: Payload, relId: string) =>
await restoreUserGoal(goalToBeRestored, true);
}
} else if (payload.changeType === "moved") {
console.log("[InboxProcessor] Processing move operation", { payload });

const changes = [
...payload.changes.map((ele: changesInGoal) => ({ ...ele, goal: fixDateVlauesInGoalObject(ele.goal) })),
];
console.log("[InboxProcessor] Processed changes", { changes });

const movedGoal = changes[0].goal;
console.log("[InboxProcessor] Extracted moved goal", { movedGoal });

const correspondingSharedWMGoal = await getSharedWMGoal(movedGoal.id);
console.log("[InboxProcessor] Found corresponding shared WM goal", {
found: !!correspondingSharedWMGoal,
goalId: movedGoal.id,
});

if (!correspondingSharedWMGoal) {
console.log("Goal to move not found");
console.error("[InboxProcessor] Goal to move not found", { goalId: movedGoal.id });
return;
}

console.log("[InboxProcessor] Starting move operation", {
movedGoal,
correspondingSharedWMGoal,
});
await handleMoveOperation(movedGoal, correspondingSharedWMGoal);
console.log("[InboxProcessor] Move operation completed successfully");
}
} else if (["sharer", "suggestion"].includes(payload.type)) {
const { changes, changeType, rootGoalId } = payload;
Expand Down
1 change: 0 additions & 1 deletion src/helpers/mergeSharedGoalItems.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getGoalById } from "@src/api/GoalsAPI";
import { GoalItem } from "@src/models/GoalItem";
import { changesInId } from "@src/models/InboxItem";

export async function isIncomingGoalLatest(localGoalId: string, incomingGoal: GoalItem): Promise<boolean> {
const localGoal = await getGoalById(localGoalId);
Expand Down

0 comments on commit e279062

Please sign in to comment.