Skip to content

Instantly share code, notes, and snippets.

@dattp
Last active March 21, 2022 08:38
Show Gist options
  • Save dattp/45ccc95eb44cf048d009cdf120b6db55 to your computer and use it in GitHub Desktop.
Save dattp/45ccc95eb44cf048d009cdf120b6db55 to your computer and use it in GitHub Desktop.
schema mongo in typescript
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