Files
outline/server/commands/documentDuplicator.ts
Tom Moorandgoogle-labs-jules[bot] 1836d2ef63 chore: Fix various lint warnings (#9362)
* Fix various linting errors

This commit addresses several linting warnings reported by ESLint:

- @typescript-eslint/no-shadow:
  - I renamed variables in inner scopes to avoid conflicts with variables in outer scopes in the following files:
    - server/commands/accountProvisioner.ts
    - server/commands/documentDuplicator.ts
    - server/commands/documentMover.ts
    - server/commands/teamProvisioner.test.ts
    - server/commands/teamProvisioner.ts
    - server/commands/userInviter.ts
    - server/commands/userProvisioner.ts
    - server/emails/templates/BaseEmail.tsx
- @typescript-eslint/no-explicit-any:
  - I replaced `any` with more specific types (Record<string, unknown> or void) in the following files:
    - server/emails/templates/BaseEmail.tsx
    - server/emails/templates/InviteEmail.tsx
    - server/emails/templates/SigninEmail.tsx
    - server/logging/Logger.ts

These changes improve code clarity and type safety without altering functionality.

* Update BaseEmail.tsx

* lint

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2025-06-01 10:59:55 -04:00

103 lines
2.8 KiB
TypeScript

import { Op } from "sequelize";
import { User, Collection, Document } from "@server/models";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
import { APIContext } from "@server/types";
import documentCreator from "./documentCreator";
type Props = {
/** The user who is creating the document */
user: User;
/** The document to duplicate */
document: Document;
/** The collection to add the duplicated document to */
collection?: Collection | null;
/** Override of the parent document to add the duplicate to */
parentDocumentId?: string;
/** Override of the duplicated document title */
title?: string;
/** Override of the duplicated document publish state */
publish?: boolean;
/** Whether to duplicate child documents */
recursive?: boolean;
/** The request context */
ctx: APIContext;
};
export default async function documentDuplicator({
user,
document,
collection,
parentDocumentId,
title,
publish,
recursive,
ctx,
}: Props): Promise<Document[]> {
const newDocuments: Document[] = [];
const sharedProperties = {
user,
collectionId: collection?.id,
publish: publish ?? !!document.publishedAt,
ctx,
};
const duplicated = await documentCreator({
parentDocumentId,
icon: document.icon,
color: document.color,
template: document.template,
title: title ?? document.title,
content: ProsemirrorHelper.removeMarks(
DocumentHelper.toProsemirror(document),
["comment"]
),
...sharedProperties,
});
duplicated.collection = collection ?? null;
newDocuments.push(duplicated);
async function duplicateChildDocuments(
original: Document,
duplicatedDocument: Document
) {
const childDocuments = await original.findChildDocuments(
{
archivedAt: original.archivedAt
? {
[Op.ne]: null,
}
: {
[Op.eq]: null,
},
},
ctx
);
for (const childDocument of childDocuments) {
const duplicatedChildDocument = await documentCreator({
parentDocumentId: duplicatedDocument.id,
icon: childDocument.icon,
color: childDocument.color,
title: childDocument.title,
content: ProsemirrorHelper.removeMarks(
DocumentHelper.toProsemirror(childDocument),
["comment"]
),
...sharedProperties,
});
duplicatedChildDocument.collection = collection ?? null;
newDocuments.push(duplicatedChildDocument);
await duplicateChildDocuments(childDocument, duplicatedChildDocument);
}
}
if (recursive && !document.template) {
await duplicateChildDocuments(document, duplicated);
}
return newDocuments;
}