Files
outline/server/presenters/collection.ts
Tom Moor f103d73b48 Move collection description rendering to JSON (#6944)
* First pass, moving collection description rendering to JSON

* tsc

* docs

* refactor

* test
2024-05-25 15:17:19 -07:00

30 lines
981 B
TypeScript

import { colorPalette } from "@shared/utils/collections";
import Collection from "@server/models/Collection";
import { DocumentHelper } from "@server/models/helpers/DocumentHelper";
import { APIContext } from "@server/types";
export default async function presentCollection(
ctx: APIContext | undefined,
collection: Collection
) {
const asData = !ctx || Number(ctx?.headers["x-api-version"] ?? 0) >= 3;
return {
id: collection.id,
url: collection.url,
urlId: collection.urlId,
name: collection.name,
data: asData ? await DocumentHelper.toJSON(collection) : undefined,
description: asData ? undefined : collection.description,
sort: collection.sort,
icon: collection.icon,
index: collection.index,
color: collection.color || colorPalette[0],
permission: collection.permission,
sharing: collection.sharing,
createdAt: collection.createdAt,
updatedAt: collection.updatedAt,
deletedAt: collection.deletedAt,
};
}