@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 4.7 kB
Source Map (JSON)
{"version":3,"file":"document-workflows.mjs","names":["mediaFormatter","formatter"],"sources":["../../../src/libs/formatters/document-workflows.ts"],"sourcesContent":["import type {\n\tDocumentWorkflow,\n\tDocumentWorkflowAssignee,\n} from \"@lucidcms/types\";\nimport type CollectionBuilder from \"../collection/builders/collection-builder/index.js\";\nimport type { DocumentWorkflowDetailedQueryResponse } from \"../repositories/document-workflows.js\";\nimport formatter, { mediaFormatter } from \"./index.js\";\nimport type { MediaPosterPropsT } from \"./media.js\";\n\ntype DocumentWorkflowFormatInput = {\n\tid?: number | null;\n\tcollection_key?: string | null;\n\tdocument_id?: number | null;\n\tstage_key?: string | null;\n\tcreated_by?: number | null;\n\tcreated_at?: string | Date | null;\n\tupdated_by?: number | null;\n\tupdated_at?: string | Date | null;\n\tassignees?: DocumentWorkflowDetailedQueryResponse[\"assignees\"];\n};\n\nconst getEffectiveStage = (props: {\n\tcollection: CollectionBuilder;\n\tstageKey?: string | null;\n}) => {\n\tconst workflow = props.collection.getData.workflow;\n\tif (!workflow) return null;\n\n\tif (\n\t\tprops.stageKey &&\n\t\tworkflow.stages.some((stage) => stage.key === props.stageKey)\n\t) {\n\t\treturn props.stageKey;\n\t}\n\n\treturn workflow.initial;\n};\n\nconst formatSingle = (props: {\n\tworkflow?: DocumentWorkflowFormatInput | null;\n\tcollection: CollectionBuilder;\n\thost: string;\n}): DocumentWorkflow | null => {\n\tconst stage = getEffectiveStage({\n\t\tcollection: props.collection,\n\t\tstageKey: props.workflow?.stage_key,\n\t});\n\tif (!stage) return null;\n\n\treturn {\n\t\tstage,\n\t\tassignees:\n\t\t\tprops.workflow?.assignees?.map((assignee) => ({\n\t\t\t\tid: assignee.id,\n\t\t\t\tuser: {\n\t\t\t\t\tid: assignee.user_id,\n\t\t\t\t\temail: assignee.email ?? null,\n\t\t\t\t\tusername: assignee.username ?? null,\n\t\t\t\t\tfirstName: assignee.first_name ?? null,\n\t\t\t\t\tlastName: assignee.last_name ?? null,\n\t\t\t\t\tprofilePicture: mediaFormatter.formatProfilePicture({\n\t\t\t\t\t\tposter: assignee.profile_picture?.[0],\n\t\t\t\t\t\thost: props.host,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\tassignedBy: assignee.assigned_by,\n\t\t\t\tassignedAt: formatter.formatDate(assignee.assigned_at),\n\t\t\t})) ?? [],\n\t\tcreatedAt: formatter.formatDate(props.workflow?.created_at),\n\t\tupdatedAt: formatter.formatDate(props.workflow?.updated_at),\n\t\tupdatedBy: props.workflow?.updated_by ?? null,\n\t};\n};\n\nconst formatSummary = (props: {\n\tstageKey?: string | null;\n\tcollection: CollectionBuilder;\n}): DocumentWorkflow | null => {\n\tconst stage = getEffectiveStage({\n\t\tcollection: props.collection,\n\t\tstageKey: props.stageKey,\n\t});\n\tif (!stage) return null;\n\n\treturn {\n\t\tstage,\n\t\tassignees: [],\n\t\tcreatedAt: null,\n\t\tupdatedAt: null,\n\t\tupdatedBy: null,\n\t};\n};\n\nconst formatAssigneeUsers = (props: {\n\tusers: Array<{\n\t\tid: number;\n\t\temail: string | null;\n\t\tusername: string | null;\n\t\tfirstName: string | null;\n\t\tlastName: string | null;\n\t\tprofile_picture?: MediaPosterPropsT[];\n\t}>;\n\thost: string;\n}): Array<DocumentWorkflowAssignee[\"user\"]> =>\n\tprops.users.map((user) => ({\n\t\tid: user.id,\n\t\temail: user.email,\n\t\tusername: user.username,\n\t\tfirstName: user.firstName,\n\t\tlastName: user.lastName,\n\t\tprofilePicture: mediaFormatter.formatProfilePicture({\n\t\t\tposter: user.profile_picture?.[0],\n\t\t\thost: props.host,\n\t\t}),\n\t}));\n\nexport default {\n\tformatAssigneeUsers,\n\tformatSingle,\n\tformatSummary,\n\tgetEffectiveStage,\n};\n"],"mappings":"sDAqBA,MAAM,EAAqB,GAGrB,CACL,IAAM,EAAW,EAAM,WAAW,QAAQ,SAU1C,OATK,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