external-account.js 830 B

12345678910111213141516171819202122232425262728293031
  1. const debug = require('debug')('crowi.models.external-account');
  2. const mongoose = require('mongoose');
  3. const uniqueValidator = require('mongoose-unique-validator');
  4. const ObjectId = mongoose.Schema.Types.ObjectId;
  5. /*
  6. * define schema
  7. */
  8. const schema = new mongoose.Schema({
  9. providerType: { type: String, required: true },
  10. accountId: { type: String, required: true },
  11. user: { type: ObjectId, ref: 'User', required: true },
  12. createdAt: { type: Date, default: Date.now, required: true },
  13. });
  14. // compound index
  15. schema.index({ providerType: 1, accountId: 1 });
  16. // apply plugins
  17. schema.plugin(uniqueValidator);
  18. /**
  19. * ExternalAccount Class
  20. *
  21. * @class ExternalAccount
  22. */
  23. class ExternalAccount {
  24. }
  25. module.exports = function(crowi) {
  26. schema.loadClass(ExternalAccount);
  27. return mongoose.model('ExternalAccount', schema);
  28. }