Last active
October 18, 2023 19:18
-
-
Save Mifrill/90de68b449dda780dcac271bb6f12f9c to your computer and use it in GitHub Desktop.
mongoose-schema-type_encrypted-string
This file contains hidden or 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
import mongoose from 'mongoose' | |
import { Cryptography } from './cryptography' | |
export class EncryptedString extends mongoose.SchemaType { | |
constructor(key: string, options: Record<string, any>) { | |
options.get = (value: any): string => new Cryptography().decrypt(value) | |
super(key, options, 'EncryptedString') | |
} | |
cast(value: any): any { | |
return new Cryptography().encrypt(value) | |
} | |
} | |
mongoose.Schema.Types.EncryptedString = EncryptedString |
Author
Mifrill
commented
Oct 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment