Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import {
2 type ItemSubmission,
3 type NormalizedItemData,
4 type SubmissionId,
5} from '../services/itemProcessingService/index.js';
6import { type ItemType } from '../services/moderationConfigService/index.js';
7
8export { type ItemIdentifier } from '@roostorg/types';
9
10/**
11 * GQL exposes what is essentially an `ItemSubmission` using a different layout
12 * of the fields (and called just `Item`), because `ItemSubmission` didn't fully
13 * exist when the GQL API started returning item data. So, this types represents
14 * an `ItemSubmission` in the shape GQL needs.
15 */
16export type ItemSubmissionForGQL<T extends ItemType = ItemType> = Readonly<{
17 id: string; // the item id.
18 type: T;
19 data: NormalizedItemData;
20 submissionId: SubmissionId;
21 submissionTime?: Date;
22}>;
23
24/**
25 * See note on {@link ItemSubmissionForGQL}.
26 */
27export function formatItemSubmissionForGQL<T extends ItemType = ItemType>(
28 it: ItemSubmission<T>,
29): ItemSubmissionForGQL<T> {
30 return {
31 id: it.itemId,
32 type: it.itemType,
33 data: it.data,
34 submissionId: it.submissionId,
35 submissionTime: it.submissionTime,
36 };
37}