Skip to content

Commit

Permalink
- Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennenoel committed Nov 18, 2024
1 parent 6949792 commit d38469e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {DataMappingBuilder} from "./data-mapping.builder";
import {DataMappingNode} from "../nodes/data-mapping.node";
import {ClassMetadata, PropertyInformationEnum, PropertyMetadata, TypeEnum, TypeUtils} from "@pristine-ts/metadata";
import {DataMappingLeaf} from "../nodes/data-mapping.leaf";
import {NumberNormalizer} from "../normalizers/number.normalizer";
import {StringNormalizer} from "../normalizers/string.normalizer";
import {DateNormalizer} from "../normalizers/date.normalizer";
import {NumberNormalizer, NumberNormalizerUniqueKey} from "../normalizers/number.normalizer";
import {StringNormalizer, StringNormalizerUniqueKey} from "../normalizers/string.normalizer";
import {DateNormalizer, DateNormalizerUniqueKey} from "../normalizers/date.normalizer";
import {DataMappingNodeTypeEnum} from "../enums/data-mapping-node-type.enum";
import {AutoDataMappingBuilderOptions} from "../options/auto-data-mapping-builder.options";
import {MetadataEnum} from "../enums/metadata.enum";
Expand Down Expand Up @@ -102,15 +102,15 @@ export class AutoDataMappingBuilder {
// todo: Allow for options to be specified per attribute. We should probably add a decorator to can customize the normalizer.
switch (nestedElementType) {
case TypeEnum.Number:
normalizers.push(NumberNormalizer.name);
normalizers.push(NumberNormalizerUniqueKey);
break;

case TypeEnum.String:
normalizers.push(StringNormalizer.name);
normalizers.push(StringNormalizerUniqueKey);
break;

case TypeEnum.Date:
normalizers.push(DateNormalizer.name);
normalizers.push(DateNormalizerUniqueKey);
break;
}
normalizers.forEach(normalizer => dataMappingLeaf.addNormalizer(normalizer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {DateNormalizerOptions} from "../normalizer-options/date-normalizer.optio
import {TypeEnum, TypeUtils} from "@pristine-ts/metadata";
import {BaseNormalizer} from "./base.normalizer";

export const DateNormalizerUniqueKey = "PRISTINE_DATE_NORMALIZER";

export class DateNormalizer extends BaseNormalizer<DateNormalizerOptions> implements DataNormalizerInterface<Date | undefined, DateNormalizerOptions> {
getUniqueKey(): string {
return "PRISTINE_DATE_NORMALIZER";
return DateNormalizerUniqueKey;
}

normalize(source: any, options?: DateNormalizerOptions): Date | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {NormalizerInvalidSourceTypeError} from "../errors/normalizer-invalid-sou
import {LowercaseNormalizerOptions} from "../normalizer-options/lowercase-normalizer.options";
import {BaseNormalizer} from "./base.normalizer";

export const LowercaseNormalizerUniqueKey = "PRISTINE_LOWERCASE_NORMALIZER";

export class LowercaseNormalizer extends BaseNormalizer<LowercaseNormalizerOptions> implements DataNormalizerInterface<string, LowercaseNormalizerOptions>{
getUniqueKey(): DataNormalizerUniqueKey {
return "PRISTINE_LOWERCASE_NORMALIZER";
return LowercaseNormalizerUniqueKey;
}

normalize(source: any, options?: LowercaseNormalizerOptions): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {NumberNormalizerOptions} from "../normalizer-options/number-normalizer.o
import {TypeEnum, TypeUtils} from "@pristine-ts/metadata";
import {BaseNormalizer} from "./base.normalizer";

export const NumberNormalizerUniqueKey = "PRISTINE_NUMBER_NORMALIZER";

export class NumberNormalizer extends BaseNormalizer<NumberNormalizerOptions> implements DataNormalizerInterface<number | undefined, NumberNormalizerOptions> {
getUniqueKey(): string {
return "PRISTINE_NUMBER_NORMALIZER";
return NumberNormalizerUniqueKey;
}

normalize(source: any, options?: NumberNormalizerOptions): number | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import {StringNormalizerOptions} from "../normalizer-options/string-normalizer.o
import {format} from "date-fns";
import {BaseNormalizer} from "./base.normalizer";

export const StringNormalizerUniqueKey = "PRISTINE_STRING_NORMALIZER";

export class StringNormalizer extends BaseNormalizer<StringNormalizerOptions> implements DataNormalizerInterface<string | undefined, StringNormalizerOptions> {
getUniqueKey(): string {
return "PRISTINE_STRING_NORMALIZER";
return StringNormalizerUniqueKey;
}

normalize(source: any, options?: StringNormalizerOptions): string | undefined {
Expand Down

0 comments on commit d38469e

Please sign in to comment.