Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/web/lib/conflict-detection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function checkInternalConflicts(
where: {
userId,
allDay: false,
deletedAt: null,
...(excludeEventId && { id: { not: excludeEventId } }),
start: { lt: effectiveEnd },
end: { gt: effectiveStart },
Expand Down Expand Up @@ -715,8 +716,8 @@ export async function checkEventConflictsBeforeUpdate(

// Look up existing event to get its current synced time range
// This is used to exclude the event's external copy from conflict detection
const existingEvent = await prisma.event.findUnique({
where: { id: eventId },
const existingEvent = await prisma.event.findFirst({
where: { id: eventId, userId, deletedAt: null },
select: { start: true, end: true },
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function createCalendarSyncRetryService(
destinationId: destination.id,
syncStatus: { in: RETRYABLE_STATUSES },
syncStatusReason: { not: SYNC_RETRY_SKIP_REASON_EVENT_MISSING },
deletedAt: null,
...(limitedEventIds ? { eventId: { in: limitedEventIds } } : {}),
},
...(limitedEventIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function createCalendarSyncStatusService(
eventId: { in: input.eventIds },
destinationId: input.destinationId,
provider: input.provider,
deletedAt: null,
},
orderBy: { lastSyncAttemptAt: "desc" },
});
Expand Down Expand Up @@ -134,6 +135,7 @@ export function createCalendarSyncStatusService(
eventId: input.eventId,
destinationId: input.destinationId,
provider: input.provider,
deletedAt: null,
},
orderBy: { lastSyncAttemptAt: "desc" },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export function createTaskReferenceRepository(

async disableByDestination(destinationId) {
await prisma.taskReference.updateMany({
where: { destinationId },
where: { destinationId, deletedAt: null },
data: {
syncStatus: "DISABLED",
syncStatusReason: "DESTINATION_DISABLED",
Expand All @@ -283,7 +283,7 @@ export function createTaskReferenceRepository(

async resetForRebuild(destinationId, newExternalTaskListId) {
await prisma.taskReference.updateMany({
where: { destinationId },
where: { destinationId, deletedAt: null },
data: {
externalTaskId: null,
externalTaskListId: newExternalTaskListId,
Expand All @@ -301,6 +301,7 @@ export function createTaskReferenceRepository(
credentialId,
provider,
syncStatus: { in: ["FAILED", "PENDING_RETRY"] },
deletedAt: null,
},
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ describe("CredentialRepairService", () => {
"TASK_SYNC_CREDENTIAL_REFRESH_FAILED",
],
},
deletedAt: null,
},
data: {
syncStatus: "PENDING",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("DestinationChangeService", () => {
await service.handleDisable("dest-1", "user-1");

expect(mockPrisma.taskReference.updateMany).toHaveBeenCalledWith({
where: { destinationId: "dest-1" },
where: { destinationId: "dest-1", deletedAt: null },
data: {
syncStatus: "DISABLED",
syncStatusReason: "DESTINATION_DISABLED",
Expand Down Expand Up @@ -192,7 +192,7 @@ describe("DestinationChangeService", () => {
);

expect(mockPrisma.taskReference.updateMany).toHaveBeenCalledWith({
where: { destinationId: "dest-1" },
where: { destinationId: "dest-1", deletedAt: null },
data: {
externalTaskId: null,
externalTaskListId: "new-list-id",
Expand Down Expand Up @@ -255,7 +255,7 @@ describe("DestinationChangeService", () => {
await service.handleCredentialChange("dest-1", "user-1", "new-list-id");

expect(mockPrisma.taskReference.updateMany).toHaveBeenCalledWith({
where: { destinationId: "dest-1" },
where: { destinationId: "dest-1", deletedAt: null },
data: {
externalTaskId: null,
externalTaskListId: "new-list-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe("TaskConnectionService", () => {

expect(result).toEqual({ disconnectedCredentials: 2 });
expect(mockPrisma.taskReference.updateMany).toHaveBeenCalledWith({
where: { credentialId: { in: ["cred-1", "cred-2"] } },
where: { credentialId: { in: ["cred-1", "cred-2"] }, deletedAt: null },
data: {
syncStatusReason: null,
lastSyncAttemptAt: null,
Expand Down Expand Up @@ -425,6 +425,7 @@ describe("TaskConnectionService", () => {
where: {
credentialId: "cred-9",
provider: "GOOGLE_TASKS",
deletedAt: null,
},
data: {
syncStatusReason: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function createCredentialRepairService(
credentialId,
syncStatus: "FAILED",
syncStatusReason: { in: [...CREDENTIAL_ERROR_REASONS] },
deletedAt: null,
},
data: {
syncStatus: "PENDING",
Expand Down
2 changes: 2 additions & 0 deletions packages/task-sync/src/services/task-connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ export function createTaskConnectionService(
await tx.taskReference.updateMany({
where: {
credentialId: { in: credentialIds },
deletedAt: null,
},
data: {
syncStatusReason: null,
Expand Down Expand Up @@ -702,6 +703,7 @@ export function createTaskConnectionService(
where: {
credentialId,
provider: credential.provider,
deletedAt: null,
},
data: {
syncStatusReason: null,
Expand Down
1 change: 1 addition & 0 deletions packages/task-sync/src/services/task-sync-retry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function createTaskSyncRetryService(
provider: destination.provider,
credential: { userId: input.userId },
syncStatus: { in: RETRYABLE_STATUSES },
deletedAt: null,
...(limitedTaskIds ? { taskId: { in: limitedTaskIds } } : {}),
},
...(limitedTaskIds
Expand Down