chore: Cleanup unused pinDestroyer (#8180)

This commit is contained in:
Tom Moor
2025-01-01 17:02:45 -05:00
committed by GitHub
parent adfca1e5ca
commit b8c07eb298
3 changed files with 5 additions and 94 deletions
+5 -6
View File
@@ -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,
});
}
})
);
}
}
-42
View File
@@ -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);
});
});
-46
View File
@@ -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<Pin> {
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;
}