mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 06:42:06 +01:00
fix(server): harden document star idempotency
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
1763f5a76b
commit
bcea9310b2
4 files changed
+25
-13
No files matched your search
@@ -348,7 +348,7 @@ export function companyArtifactsService(db: Db, storage?: StorageService) {
|
||||
const artifactSortDates = new Map<string, string>();
|
||||
const workProductAttachmentIds = new Set<string>();
|
||||
|
||||
if (query.starred || query.kind === "all" || query.kind === "document") {
|
||||
if (query.kind === "all" || query.kind === "document") {
|
||||
const createdAgent = alias(agents, "document_created_agent");
|
||||
const updatedAgent = alias(agents, "document_updated_agent");
|
||||
const documentArtifactId = sql<string>`concat('document:', ${documents.id})`;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { and, eq, sql } from "drizzle-orm";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import {
|
||||
agentMemberships,
|
||||
@@ -491,19 +491,23 @@ export function resourceMembershipService(db: Db, options: ResourceMembershipSer
|
||||
.onConflictDoUpdate({
|
||||
target: [documentMemberships.companyId, documentMemberships.userId, documentMemberships.documentId],
|
||||
set: {
|
||||
starredAt: now,
|
||||
updatedAt: now,
|
||||
starredAt: sql`${documentMemberships.starredAt}`,
|
||||
updatedAt: sql`${documentMemberships.updatedAt}`,
|
||||
},
|
||||
})
|
||||
.returning();
|
||||
.returning({
|
||||
starredAt: documentMemberships.starredAt,
|
||||
updatedAt: documentMemberships.updatedAt,
|
||||
inserted: sql<boolean>`xmax = 0`,
|
||||
});
|
||||
return {
|
||||
resourceType: "document",
|
||||
resourceId: input.documentId,
|
||||
state: "joined",
|
||||
starredAt: row?.starredAt ?? now,
|
||||
updatedAt: row?.updatedAt ?? now,
|
||||
changed: true,
|
||||
changeKind: "starred",
|
||||
changed: row?.inserted === true,
|
||||
changeKind: row?.inserted === true ? "starred" : null,
|
||||
policySource: decision.source ?? "oss_default",
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user