Skip to content

Commit f435599

Browse files
committed
Split out DTOs into separate files
1 parent a939dfd commit f435599

14 files changed

+157
-140
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './media.dto';
2+
export * from './media-list.dto';
3+
export * from './upload.dto';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { InputType, ObjectType } from '@nestjs/graphql';
2+
import {
3+
PaginatedList,
4+
SortablePaginationInput,
5+
Variant,
6+
VariantInputField,
7+
} from '~/common';
8+
import { ProgressReport } from '../../dto';
9+
import { MediaVariant, ProgressReportMedia } from './media.dto';
10+
11+
@InputType()
12+
export class ProgressReportMediaListInput extends SortablePaginationInput<
13+
'createdAt' | 'variant'
14+
>({
15+
defaultSort: 'createdAt',
16+
}) {
17+
@VariantInputField(ProgressReportMedia, {
18+
nullable: true,
19+
many: true,
20+
description: 'Filter to these specific variants',
21+
})
22+
variants?: ReadonlyArray<Variant<MediaVariant>>;
23+
}
24+
25+
@ObjectType()
26+
export class ProgressReportMediaList extends PaginatedList(
27+
ProgressReportMedia,
28+
) {
29+
readonly report: ProgressReport;
30+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Field, InputType, ObjectType } from '@nestjs/graphql';
2+
import { setOf } from '@seedcompany/common';
3+
import { keys as keysOf } from 'ts-transformer-keys';
4+
import {
5+
IdField,
6+
IdOf,
7+
Resource,
8+
SecuredProps,
9+
Variant,
10+
VariantOf,
11+
} from '~/common';
12+
import { SetDbType } from '~/core';
13+
import { RegisterResource } from '~/core/resources';
14+
import { FileId, Media } from '../../../file';
15+
import { User } from '../../../user';
16+
import { ProgressReport } from '../../dto';
17+
import { ProgressReportHighlight } from '../../dto/highlights.dto';
18+
import { MediaCategory } from '../media-category.enum';
19+
20+
export type VariantGroup = IdOf<'ProgressReportMediaVariantGroup'>;
21+
22+
@RegisterResource()
23+
@InputType({ isAbstract: true })
24+
@ObjectType()
25+
export class ProgressReportMedia extends Resource {
26+
static Props = keysOf<ProgressReportMedia>();
27+
static SecuredProps = keysOf<SecuredProps<ProgressReportMedia>>();
28+
static BaseNodeProps = [...Resource.Props, 'category', 'creator', 'variant'];
29+
static readonly Parent = import('../../dto/progress-report.entity').then(
30+
(m) => m.ProgressReport,
31+
);
32+
static readonly ConfirmThisClassPassesSensitivityToPolicies = true;
33+
34+
static Variants = ProgressReportHighlight.Variants;
35+
// Only the last variant is publicly visible (accessible by anyone anonymously)
36+
// Saved in DB, so adjust with caution
37+
static PublicVariants = setOf(
38+
ProgressReportHighlight.Variants.slice(-1).map((v) => v.key),
39+
);
40+
41+
readonly report: IdOf<ProgressReport>;
42+
43+
@Field(() => Variant)
44+
readonly variant: Variant<MediaVariant> & SetDbType<MediaVariant>;
45+
46+
@Field(() => MediaCategory, { nullable: true })
47+
readonly category?: MediaCategory | null;
48+
49+
readonly media: IdOf<Media>;
50+
readonly file: FileId;
51+
52+
@IdField()
53+
readonly variantGroup: VariantGroup;
54+
55+
readonly creator: IdOf<User>;
56+
}
57+
58+
export type MediaVariant = VariantOf<typeof ProgressReportMedia>;
59+
60+
declare module '~/core/resources/map' {
61+
interface ResourceMap {
62+
ProgressReportMedia: typeof ProgressReportMedia;
63+
}
64+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Field, InputType } from '@nestjs/graphql';
2+
import { stripIndent } from 'common-tags';
3+
import {
4+
IdField,
5+
IdOf,
6+
IntersectionType as Merge,
7+
PickType,
8+
Variant,
9+
VariantInputField,
10+
} from '~/common';
11+
import {
12+
CreateDefinedFileVersionInput,
13+
MediaUserMetadata,
14+
} from '../../../file';
15+
import { ProgressReport } from '../../dto';
16+
import { MediaVariant, ProgressReportMedia, VariantGroup } from './media.dto';
17+
18+
@InputType()
19+
export class UploadProgressReportMedia extends PickType(ProgressReportMedia, [
20+
'category',
21+
]) {
22+
@IdField()
23+
readonly reportId: IdOf<ProgressReport>;
24+
25+
@Field()
26+
readonly file: CreateDefinedFileVersionInput;
27+
28+
@VariantInputField(ProgressReportMedia)
29+
readonly variant: Variant<MediaVariant>;
30+
31+
@IdField({
32+
description: stripIndent`
33+
Associate this media with an existing set of media.
34+
Idea being the "same image" across multiple variants.
35+
Group might not be the best name for this.
36+
37+
If none is given a new group will be created.
38+
`,
39+
nullable: true,
40+
})
41+
readonly variantGroup?: VariantGroup;
42+
}
43+
44+
@InputType()
45+
export class UpdateProgressReportMedia extends Merge(
46+
PickType(ProgressReportMedia, ['category']),
47+
MediaUserMetadata,
48+
) {
49+
@IdField()
50+
readonly id: IdOf<ProgressReportMedia>;
51+
}

src/components/progress-report/media/handlers/update-media-metadata-check.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventsHandler, GqlContextHost, ResourceLoader } from '~/core';
22
import { Privileges } from '../../../authorization';
33
import { CanUpdateMediaUserMetadataEvent } from '../../../file/media/events/can-update-event';
4-
import { ProgressReportMedia as ReportMedia } from '../media.dto';
4+
import { ProgressReportMedia as ReportMedia } from '../dto';
55

66
@EventsHandler(CanUpdateMediaUserMetadataEvent)
77
export class ProgressReportUpdateMediaMetadataCheckHandler {

src/components/progress-report/media/media.dto.ts

Lines changed: 0 additions & 131 deletions
This file was deleted.

src/components/progress-report/media/progress-report-featured-media.loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DataLoaderOptions } from '@seedcompany/data-loader';
22
import { IdOf } from '~/common';
33
import { LoaderFactory, SessionAwareLoaderStrategy } from '~/core';
44
import { ProgressReport } from '../dto';
5-
import { ProgressReportMedia as ReportMedia } from './media.dto';
5+
import { ProgressReportMedia as ReportMedia } from './dto';
66
import { ProgressReportMediaService } from './progress-report-media.service';
77

88
@LoaderFactory()

src/components/progress-report/media/progress-report-media.loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { forwardRef, Inject } from '@nestjs/common';
22
import { IdOf } from '~/common';
33
import { LoaderFactory, SessionAwareLoaderStrategy } from '~/core';
4-
import { ProgressReportMedia as ReportMedia } from './media.dto';
4+
import { ProgressReportMedia as ReportMedia } from './dto';
55
import { ProgressReportMediaService } from './progress-report-media.service';
66

77
@LoaderFactory(() => ReportMedia)

src/components/progress-report/media/progress-report-media.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
ProgressReportMedia as ReportMedia,
3434
UpdateProgressReportMedia as UpdateMedia,
3535
UploadProgressReportMedia as UploadMedia,
36-
} from './media.dto';
36+
} from './dto';
3737

3838
@Injectable()
3939
export class ProgressReportMediaRepository extends DtoRepository<

src/components/progress-report/media/progress-report-media.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
ProgressReportMediaList as ReportMediaList,
1818
UpdateProgressReportMedia as UpdateMedia,
1919
UploadProgressReportMedia as UploadMedia,
20-
} from './media.dto';
20+
} from './dto';
2121
import { ProgressReportMediaLoader } from './progress-report-media.loader';
2222
import { ProgressReportMediaRepository } from './progress-report-media.repository';
2323

0 commit comments

Comments
 (0)