From b8c07eb2984a95bbc8a341f982c437225c1bfe15 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 1 Jan 2025 17:02:45 -0500 Subject: [PATCH] chore: Cleanup unused pinDestroyer (#8180) --- server/commands/documentMover.ts | 11 +++---- server/commands/pinDestroyer.test.ts | 42 ------------------------- server/commands/pinDestroyer.ts | 46 ---------------------------- 3 files changed, 5 insertions(+), 94 deletions(-) delete mode 100644 server/commands/pinDestroyer.test.ts delete mode 100644 server/commands/pinDestroyer.ts diff --git a/server/commands/documentMover.ts b/server/commands/documentMover.ts index a3d25aecad..01ab23aad5 100644 --- a/server/commands/documentMover.ts +++ b/server/commands/documentMover.ts @@ -1,5 +1,6 @@ import invariant from "invariant"; import { Transaction } from "sequelize"; +import { createContext } from "@server/context"; import { traceFunction } from "@server/logging/tracing"; import { User, @@ -10,7 +11,6 @@ import { UserMembership, GroupMembership, } from "@server/models"; -import pinDestroyer from "./pinDestroyer"; type Props = { /** User attempting to move the document */ @@ -213,14 +213,13 @@ async function documentMover({ lock: Transaction.LOCK.UPDATE, }); - if (pin) { - await pinDestroyer({ + await pin?.destroyWithCtx( + createContext({ user, - pin, ip, transaction, - }); - } + }) + ); } } diff --git a/server/commands/pinDestroyer.test.ts b/server/commands/pinDestroyer.test.ts deleted file mode 100644 index 0594848cb5..0000000000 --- a/server/commands/pinDestroyer.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Event, Pin } from "@server/models"; -import { buildDocument, buildUser } from "@server/test/factories"; -import pinDestroyer from "./pinDestroyer"; - -describe("pinCreator", () => { - const ip = "127.0.0.1"; - - it("should destroy existing pin", async () => { - const user = await buildUser(); - const document = await buildDocument({ - userId: user.id, - teamId: user.teamId, - }); - - const pin = await Pin.create({ - teamId: document.teamId, - documentId: document.id, - collectionId: document.collectionId, - createdById: user.id, - index: "P", - }); - - await pinDestroyer({ - pin, - user, - ip, - }); - - const count = await Pin.count({ - where: { - teamId: user.teamId, - }, - }); - expect(count).toEqual(0); - - const event = await Event.findLatest({ - teamId: user.teamId, - }); - expect(event!.name).toEqual("pins.delete"); - expect(event!.modelId).toEqual(pin.id); - }); -}); diff --git a/server/commands/pinDestroyer.ts b/server/commands/pinDestroyer.ts deleted file mode 100644 index af59e095d0..0000000000 --- a/server/commands/pinDestroyer.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Transaction } from "sequelize"; -import { Event, Pin, User } from "@server/models"; - -type Props = { - /** The user destroying the pin */ - user: User; - /** The pin to destroy */ - pin: Pin; - /** The IP address of the user creating the pin */ - ip: string; - /** Optional existing transaction */ - transaction?: Transaction; -}; - -/** - * @deprecated use pin.destroyWithCtx instead. This will be removed once document routes migrate to auto event insertion using APIContext. - * - * This command destroys a document pin. This just removes the pin itself and - * does not touch the document - * - * @param Props The properties of the pin to destroy - * @returns void - */ -export default async function pinDestroyer({ - user, - pin, - ip, - transaction, -}: Props): Promise { - await Event.create( - { - name: "pins.delete", - modelId: pin.id, - teamId: user.teamId, - actorId: user.id, - documentId: pin.documentId, - collectionId: pin.collectionId, - ip, - }, - { transaction } - ); - - await pin.destroy({ transaction }); - - return pin; -}