Created
January 17, 2019 18:08
-
-
Save muhammadfaizan/239d5c56879c07616b46b8d17c1572e1 to your computer and use it in GitHub Desktop.
Defining Mongoose Schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | |
}] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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