|
1 | 1 | import { applyDecorators } from '@nestjs/common';
|
2 | 2 | import { ObjectType } from '@nestjs/graphql';
|
3 |
| -import { setToStringTag } from '@seedcompany/common'; |
| 3 | +import { type Nil, setToStringTag } from '@seedcompany/common'; |
4 | 4 | import { markSkipClassTransformation } from '@seedcompany/nest';
|
5 | 5 | import { IsObject } from 'class-validator';
|
6 | 6 | import { createHash } from 'crypto';
|
@@ -82,23 +82,19 @@ export const RichTextField = (options?: OptionalFieldOptions) =>
|
82 | 82 | OptionalField(() => RichTextScalar, {
|
83 | 83 | optional: false,
|
84 | 84 | ...options,
|
85 |
| - transform: (value) => { |
86 |
| - const doc = RichTextDocument.fromMaybe(value); |
87 |
| - if (doc) { |
88 |
| - return doc; |
| 85 | + transform: (prev) => (value) => { |
| 86 | + const doc: RichTextDocument | Nil = prev( |
| 87 | + RichTextDocument.fromMaybe(value), |
| 88 | + ); |
| 89 | + if (doc == null && !options?.nullable && !options?.optional) { |
| 90 | + // Should never _really_ get here. |
| 91 | + // UI should understand & send null instead of an empty document. |
| 92 | + // Would prefer this to be done with validators. |
| 93 | + // But I believe this needs `null`s to be validated. |
| 94 | + // skipMissingProperties -> skipUndefinedProperties |
| 95 | + throw new InputException('RichText must be given'); |
89 | 96 | }
|
90 |
| - if (options?.nullable) { |
91 |
| - return null; |
92 |
| - } |
93 |
| - if (options?.optional) { |
94 |
| - return undefined; |
95 |
| - } |
96 |
| - // Should never _really_ get here. |
97 |
| - // UI should understand & send null instead of an empty document. |
98 |
| - // Would prefer this to be done with validators. |
99 |
| - // But I believe this needs to `null`s to be validated. |
100 |
| - // skipMissingProperties -> skipUndefinedProperties |
101 |
| - throw new InputException('RichText must be given'); |
| 97 | + return doc; |
102 | 98 | },
|
103 | 99 | }),
|
104 | 100 | IsObject(),
|
|
0 commit comments