Last active
March 21, 2022 08:38
-
-
Save dattp/45ccc95eb44cf048d009cdf120b6db55 to your computer and use it in GitHub Desktop.
schema mongo in typescript
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
import { | |
Schema, model, Document, | |
} from "mongoose"; | |
import { IAsset } from "@type/asset.type"; | |
interface AssetDocument extends IAsset, Document { | |
transform(): string | |
} | |
const schema = new Schema<AssetDocument>({ | |
name: { type: String, required: true }, | |
collection_slug: { type: String, required: true }, | |
token_id: { type: String, required: true }, | |
description: String, | |
}, { versionKey: false, timestamps: true }); | |
schema.method({ | |
transform(): string { | |
console.log("====>this: ", this); | |
const a = this.name; | |
return a; | |
}, | |
}); | |
const AssetModel = model<AssetDocument>("Asset", schema); | |
export default AssetModel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment