-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose visuals constraints through the API (with args) (#4743)
* Expose visuals constraints through the API * address coderabbit comments * added args input * Address CR comments, cleaned up and renamed to defaultVisualConstraints --------- Co-authored-by: Carlos Cano <[email protected]> Co-authored-by: Bobby Kolev <[email protected]>
- Loading branch information
1 parent
99e1ec5
commit 7340096
Showing
6 changed files
with
113 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { VisualType } from '@common/enums/visual.type'; | ||
import { Field, ObjectType } from '@nestjs/graphql'; | ||
|
||
export const VISUAL_ALLOWED_TYPES = [ | ||
'image/png', | ||
'image/jpeg', | ||
'image/jpg', | ||
'image/svg+xml', | ||
'image/webp', | ||
] as const; | ||
|
||
export const DEFAULT_VISUAL_CONSTRAINTS = { | ||
[VisualType.AVATAR]: { | ||
minWidth: 190, | ||
maxWidth: 410, | ||
minHeight: 190, | ||
maxHeight: 410, | ||
aspectRatio: 1, | ||
allowedTypes: VISUAL_ALLOWED_TYPES, | ||
}, | ||
[VisualType.BANNER]: { | ||
minWidth: 384, | ||
maxWidth: 1536, | ||
minHeight: 64, | ||
maxHeight: 256, | ||
aspectRatio: 6, | ||
allowedTypes: VISUAL_ALLOWED_TYPES, | ||
}, | ||
[VisualType.CARD]: { | ||
minWidth: 307, | ||
maxWidth: 410, | ||
minHeight: 192, | ||
maxHeight: 256, | ||
aspectRatio: 1.6, | ||
allowedTypes: VISUAL_ALLOWED_TYPES, | ||
}, | ||
[VisualType.BANNER_WIDE]: { | ||
minWidth: 640, | ||
maxWidth: 2560, | ||
minHeight: 64, | ||
maxHeight: 256, | ||
aspectRatio: 10, | ||
allowedTypes: VISUAL_ALLOWED_TYPES, | ||
}, | ||
} as const; | ||
|
||
@ObjectType('VisualConstraints') | ||
export class VisualConstraints { | ||
@Field(() => Number, { | ||
description: 'Minimum width resolution.', | ||
}) | ||
minWidth!: number; | ||
|
||
@Field(() => Number, { | ||
description: 'Maximum width resolution.', | ||
}) | ||
maxWidth!: number; | ||
|
||
@Field(() => Number, { | ||
description: 'Minimum height resolution.', | ||
}) | ||
minHeight!: number; | ||
|
||
@Field(() => Number, { | ||
description: 'Maximum height resolution.', | ||
}) | ||
maxHeight!: number; | ||
|
||
@Field(() => Number, { | ||
description: 'Dimensions ratio width / height.', | ||
}) | ||
aspectRatio!: number; | ||
|
||
@Field(() => [String], { | ||
description: 'Allowed file types.', | ||
}) | ||
allowedTypes!: typeof VISUAL_ALLOWED_TYPES; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { KonfigService } from './config.service'; | ||
import { ConfigurationResolverFields } from './config.resolver.fields'; | ||
|
||
@Module({ | ||
providers: [KonfigService], | ||
providers: [KonfigService, ConfigurationResolverFields], | ||
exports: [KonfigService], | ||
}) | ||
export class KonfigModule {} |
21 changes: 21 additions & 0 deletions
21
src/platform/configuration/config/config.resolver.fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
VisualConstraints, | ||
DEFAULT_VISUAL_CONSTRAINTS, | ||
} from '@domain/common/visual/visual.constraints'; | ||
import { Args, ResolveField } from '@nestjs/graphql'; | ||
import { Resolver } from '@nestjs/graphql'; | ||
import { IConfig } from './config.interface'; | ||
import { VisualType } from '@common/enums/visual.type'; | ||
|
||
@Resolver(() => IConfig) | ||
export class ConfigurationResolverFields { | ||
@ResolveField(() => VisualConstraints, { | ||
nullable: false, | ||
description: 'Visual constraints for the given type', | ||
}) | ||
defaultVisualTypeConstraints( | ||
@Args('type', { type: () => VisualType }) visualTypeInput: VisualType | ||
): VisualConstraints { | ||
return DEFAULT_VISUAL_CONSTRAINTS[visualTypeInput]; | ||
} | ||
} |