var mongoose = require('mongoose'); var uniqueValidator = require('mongoose-unique-validator'); var PriceSchema = new mongoose.Schema({ timestamp: { type: Number, default: 0 }, metal: { type: String, upercase: true, default: 'ØØØ' }, currency: { type: String, upercase: true, default: 'ØØØ' }, exchange: { type: String, upercase: true, default: '' }, symbol: { type: String, upercase: true, default: '' }, prev_close_price: { type: Number, default: 0 }, open_price: { type: Number, default: 0 }, low_price: { type: Number, default: 0 }, high_price: { type: Number, default: 0 }, open_time: { type: Number, default: 0 }, price: { type: Number, default: 0 }, ch: { type: Number, default: 0 }, chp: { type: Number, default: 0 }, ask: { type: Number, default: 0 }, bid: { type: Number, default: 0 }, price_gram_24k: { type: Number, default: 0 }, price_gram_22k: { type: Number, default: 0 }, price_gram_21k: { type: Number, default: 0 }, price_gram_20k: { type: Number, default: 0 }, price_gram_18k: { type: Number, default: 0 }, price_gram_16k: { type: Number, default: 0 }, price_gram_14k: { type: Number, default: 0 }, price_gram_10k: { type: Number, default: 0 } }, { timestamps: true, toJSON: { virtuals: true } }); PriceSchema.plugin(uniqueValidator, { message: 'is already taken' }); PriceSchema.methods.toJSONFor = function () { /* let a = { timestamp: 1689944788, metal: "XAU", currency: "EUR", exchange: "FOREXCOM", symbol: "FOREXCOM:XAUEUR", prev_close_price: 0.00, open_price: 0.00, low_price: 0.00, high_price: 0.00, open_time: 1689897600, price: 0.00, ch: 0.00, chp: 0.00, ask: 0.00, bid: 0.00, price_gram_24k: 0.00, price_gram_22k: 0.00, price_gram_21k: 0.00, price_gram_20k: 0.00, price_gram_18k: 0.00, price_gram_16k: 0.00, price_gram_14k: 0.00, price_gram_10k: 0.00 }; */ return { timestamp: this.timestamp, metal: this.metal, currency: this.currency, exchange: this.exchange, symbol: this.symbol, prev_close_price: this.prev_close_price, open_price: this.open_price, low_price: this.low_price, high_price: this.high_price, open_time: this.open_time, price: this.price, ch: this.ch, chp: this.chp, ask: this.ask, bid: this.bid, price_gram_24k: this.price_gram_24k, price_gram_22k: this.price_gram_22k, price_gram_21k: this.price_gram_21k, price_gram_20k: this.price_gram_20k, price_gram_18k: this.price_gram_18k, price_gram_16k: this.price_gram_16k, price_gram_14k: this.price_gram_14k, price_gram_10k: this.price_gram_10k }; }; mongoose.model('Price', PriceSchema);