You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
736 B
28 lines
736 B
// content-vote.js
|
|
// Copyright (C) 2022 DTP Technologies, LLC
|
|
// License: Apache-2.0
|
|
|
|
'use strict';
|
|
|
|
const mongoose = require('mongoose');
|
|
const Schema = mongoose.Schema;
|
|
|
|
const ContentVoteSchema = new Schema({
|
|
created: { type: Date, default: Date.now, required: true },
|
|
resourceType: { type: String, required: true },
|
|
resource: { type: Schema.ObjectId, required: true, refPath: 'resourceType' },
|
|
user: { type: Schema.ObjectId, required: true, ref: 'User' },
|
|
vote: { type: String, enum: ['up','down'], required: true },
|
|
});
|
|
|
|
ContentVoteSchema.index({
|
|
user: 1,
|
|
resource: 1,
|
|
}, {
|
|
unique: true,
|
|
name: 'unique_user_content_vote',
|
|
});
|
|
|
|
module.exports = (conn) => {
|
|
return conn.model('ContentVote', ContentVoteSchema);
|
|
};
|