-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8419 from ever-co/fix/actor-type-transformer-integer
[Fix] Integer Storage for ActorTypeEnum in Database
- Loading branch information
Showing
10 changed files
with
93 additions
and
53 deletions.
There are no files selected for viewing
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
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
28 changes: 28 additions & 0 deletions
28
packages/core/src/shared/pipes/actor-type-transform.pipe.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,28 @@ | ||
import { ValueTransformer } from 'typeorm'; | ||
import { ActorTypeEnum } from '@gauzy/contracts'; | ||
|
||
/** | ||
* ActorTypeTransformerPipe handles the conversion between the enum string values | ||
* (used in the application) and the integer values (stored in the database). | ||
*/ | ||
export class ActorTypeTransformerPipe implements ValueTransformer { | ||
/** | ||
* Converts the enum string value to its integer representation when writing to the database. | ||
* | ||
* @param value - The `ActorTypeEnum` value ('System' or 'User'). | ||
* @returns The corresponding integer value to be stored in the database (0 for System, 1 for User). | ||
*/ | ||
to(value: ActorTypeEnum): number { | ||
return value === ActorTypeEnum.User ? 1 : 0; // 1 for 'User', 0 for 'System' (default) | ||
} | ||
|
||
/** | ||
* Converts the integer value to its corresponding `ActorTypeEnum` string when reading from the database. | ||
* | ||
* @param value - The integer value (0 or 1) from the database. | ||
* @returns The corresponding `ActorTypeEnum` ('System' for 0, 'User' for 1). | ||
*/ | ||
from(value: number): ActorTypeEnum { | ||
return value === 1 ? ActorTypeEnum.User : ActorTypeEnum.System; | ||
} | ||
} |
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,7 +1,8 @@ | ||
export * from './uuid-validation.pipe'; | ||
export * from './parse-json.pipe'; | ||
export * from './abstract-validation.pipe'; | ||
export * from './actor-type-transform.pipe'; | ||
export * from './bulk-body-load-transform.pipe'; | ||
export * from './column-numeric-transformer.pipe'; | ||
export * from './abstract-validation.pipe'; | ||
export * from './use-validation-pipe.pipe'; | ||
export * from './http-method-transformer.pipe'; | ||
export * from './parse-json.pipe'; | ||
export * from './use-validation.pipe'; | ||
export * from './uuid-validation.pipe'; |
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,15 @@ | ||
import { UsePipes, ValidationPipe, ValidationPipeOptions } from '@nestjs/common'; | ||
|
||
/** | ||
* Creates and applies a custom validation pipe with optional configuration. | ||
* | ||
* This function is a helper for applying NestJS's `ValidationPipe` with custom options | ||
* to a route or controller. It wraps the `UsePipes` decorator and makes it easier to | ||
* customize validation behavior. | ||
* | ||
* @param options - Optional `ValidationPipeOptions` to customize the validation behavior. | ||
* @returns A decorator that applies the `ValidationPipe` with the given options. | ||
*/ | ||
export function UseValidationPipe(options?: Partial<ValidationPipeOptions>) { | ||
return UsePipes(new ValidationPipe(options ?? {})); | ||
} |