33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const mongoosePaginate = require('mongoose-paginate-v2');
|
|
const s3Storage = require('../plugins/s3Storage');
|
|
|
|
function image(img) {
|
|
if (!img) return null;
|
|
if (img.startsWith('http://') || img.startsWith('https://')) return img;
|
|
return s3Storage.getPublicUrl(`uploads/images/users/${img}`);
|
|
}
|
|
|
|
const AdminSchema = mongoose.Schema({
|
|
firstName: String,
|
|
lastName: String,
|
|
password: String,
|
|
scope: {type: Array, default: ['admin']},
|
|
token: {type: String, default: null},
|
|
profilePic: {type: String, get: image, default: null},
|
|
mobileNumber: {type: String, default: null},
|
|
email: String,
|
|
registration_done: {type: Boolean, default: false},
|
|
_creator: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
_updatedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
|
username: {type: String, unique: true},
|
|
portals: {type: Array, default: []},
|
|
permissions: Array,
|
|
specialPermissions: [{type: mongoose.Schema.Types.ObjectId, ref: 'Category'}],
|
|
private: {type: Boolean, default: false}
|
|
})
|
|
|
|
AdminSchema.plugin(mongoosePaginate);
|
|
|
|
module.exports = mongoose.model('User', AdminSchema)
|