mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 10:26:26 +01:00
fix(server): make concurrent unstars idempotent
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
bcea9310b2
commit
7efbf70f45
2 files changed
+16
-11
No files matched your search
@@ -447,14 +447,15 @@ describeEmbeddedPostgres("resource membership routes", () => {
|
||||
expect(list.body.documentStarredAt[documentId]).toBe(first.body.starredAt);
|
||||
await expect(db.select().from(documentMemberships)).resolves.toHaveLength(1);
|
||||
|
||||
await request(app)
|
||||
.put(`/api/companies/${companyId}/resource-memberships/me/documents/${documentId}`)
|
||||
.send({ starred: false })
|
||||
.expect(200);
|
||||
await request(app)
|
||||
.put(`/api/companies/${companyId}/resource-memberships/me/documents/${documentId}`)
|
||||
.send({ starred: false })
|
||||
.expect(200);
|
||||
const unstars = await Promise.all([
|
||||
request(app)
|
||||
.put(`/api/companies/${companyId}/resource-memberships/me/documents/${documentId}`)
|
||||
.send({ starred: false }),
|
||||
request(app)
|
||||
.put(`/api/companies/${companyId}/resource-memberships/me/documents/${documentId}`)
|
||||
.send({ starred: false }),
|
||||
]);
|
||||
expect(unstars.map((response) => response.status)).toEqual([200, 200]);
|
||||
await expect(db.select().from(documentMemberships)).resolves.toHaveLength(0);
|
||||
|
||||
await request(app)
|
||||
|
||||
@@ -524,15 +524,19 @@ export function resourceMembershipService(db: Db, options: ResourceMembershipSer
|
||||
policySource: decision.source ?? "oss_default",
|
||||
};
|
||||
}
|
||||
await db.delete(documentMemberships).where(eq(documentMemberships.id, existing.id));
|
||||
const [deleted] = await db
|
||||
.delete(documentMemberships)
|
||||
.where(eq(documentMemberships.id, existing.id))
|
||||
.returning({ id: documentMemberships.id });
|
||||
const changed = deleted !== undefined;
|
||||
return {
|
||||
resourceType: "document",
|
||||
resourceId: input.documentId,
|
||||
state: "joined",
|
||||
starredAt: null,
|
||||
updatedAt: new Date(),
|
||||
changed: true,
|
||||
changeKind: "unstarred",
|
||||
changed,
|
||||
changeKind: changed ? "unstarred" : null,
|
||||
policySource: decision.source ?? "oss_default",
|
||||
};
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user