Skip to content

Instantly share code, notes, and snippets.

@muhammadfaizan
Created January 17, 2019 18:08
Show Gist options
  • Save muhammadfaizan/239d5c56879c07616b46b8d17c1572e1 to your computer and use it in GitHub Desktop.
Save muhammadfaizan/239d5c56879c07616b46b8d17c1572e1 to your computer and use it in GitHub Desktop.
Defining Mongoose Schema
const mongoose = require('mongoose')
const RK = mongoose.Schema.ObjectId
module.exports = class BaseSchema extends mongoose.Schema {
constructor (schema) {
const updater = {
created: {
by: { type: String},
user: { type: RK, ref: 'User', select: false },
},
updated: {
by: { type: String},
user: { type: RK, ref: 'User', select: false },
}
}
super(Object.assign(updater, schema), { timestamps: true })
}
}
const AuthorizationSchema = require('./authorization-schema')
// const companySchema = require('./company');
const RK = require('mongoose').Schema.ObjectId
// ::::::::::: SCHEMA SECTION ::::::::::::://
const clientSchema = new AuthorizationSchema({
key: [{
value1: { type: RK, ref: 'Client' },
value2: { type: RK, ref: 'NotClient' }
}]
})
const mongoose = require('mongoose')
const BaseSchema = require('./base-schema')
const { attributeSetter } = require('../services/index')
const personSchema = require('./person')
const { generateHash, token, validPassword } = attributeSetter
const RK = mongoose.Schema.ObjectId
module.exports = class AuthorizationSchema extends BaseSchema {
constructor (schema) {
super(Object.assign({
party: { type: RK, ref: 'Party' },
person: {
type: RK, ref: 'Person', es_schema: personSchema, es_indexed: true
},
email: { type: String, index: true },
mobile: { type: String, index: true },
password: { type: String, set: generateHash },
permission: { type: RK, ref: 'Permission' },
lastSignin: { type: Date },
verificationCode: { type: String, default: token },
isEmailVerified: { type: Boolean, default: false },
isMobileVerified: { type: Boolean, default: false },
hasAccess: { type: Boolean, default: true }
}, schema))
this.methods.validPassword = validPassword
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment