habitica/website/server/models/iapPurchaseReceipt.js

26 lines
810 B
JavaScript
Raw Normal View History

2016-06-26 15:04:16 +00:00
import mongoose from 'mongoose';
import validator from 'validator';
2019-10-08 14:57:10 +00:00
import baseModel from '../libs/baseModel';
2016-06-26 15:04:16 +00:00
2019-10-08 14:57:10 +00:00
const { Schema } = mongoose;
2016-06-26 15:04:16 +00:00
2019-10-08 14:57:10 +00:00
export const schema = new Schema({
_id: { $type: String, required: true }, // Use a custom string as _id
consumed: { $type: Boolean, default: false, required: true },
userId: {
$type: String, ref: 'User', required: true, validate: [v => validator.isUUID(v), 'Invalid uuid.'],
},
2016-06-26 15:04:16 +00:00
}, {
strict: true,
minimize: false, // So empty objects are returned
typeKey: '$type', // So that we can use fields named `type`
2016-06-26 15:04:16 +00:00
});
schema.plugin(baseModel, {
noSet: ['id', '_id', 'userId', 'consumed'], // Nothing can be set from the client
timestamps: true,
_id: false, // using custom _id
});
2019-10-08 14:57:10 +00:00
export const model = mongoose.model('IapPurchaseReceipt', schema);