todo auth
This commit is contained in:
31
server/routers/todo/model/todo/auth.js
Normal file
31
server/routers/todo/model/todo/auth.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const {
|
||||
TODO_AUTH_PASSWD_MODEL_NAME,
|
||||
TODO_AUTH_USER_MODEL_NAME,
|
||||
} = require("../../const");
|
||||
|
||||
const schema = new Schema({
|
||||
login: { type: String, required: true, unique: true },
|
||||
hash: { type: String, required: true },
|
||||
salt: { type: String, required: true },
|
||||
userId: { type: Schema.Types.ObjectId, ref: TODO_AUTH_USER_MODEL_NAME },
|
||||
created: {
|
||||
type: Date,
|
||||
default: () => new Date().toISOString(),
|
||||
},
|
||||
});
|
||||
|
||||
schema.set("toJSON", {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform: function (doc, ret) {
|
||||
delete ret._id;
|
||||
},
|
||||
});
|
||||
|
||||
schema.virtual("id").get(function () {
|
||||
return this._id.toHexString();
|
||||
});
|
||||
|
||||
exports.AuthModel = model(TODO_AUTH_PASSWD_MODEL_NAME, schema);
|
||||
27
server/routers/todo/model/todo/user.js
Normal file
27
server/routers/todo/model/todo/user.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { Schema, model } = require("mongoose");
|
||||
|
||||
const { TODO_AUTH_USER_MODEL_NAME } = require("../../const");
|
||||
|
||||
const schema = new Schema({
|
||||
login: { type: String, required: true, unique: true },
|
||||
email: { type: String, required: true, unique: true },
|
||||
role: { type: String, default: "user" },
|
||||
created: {
|
||||
type: Date,
|
||||
default: () => new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
schema.set("toJSON", {
|
||||
virtuals: true,
|
||||
versionKey: false,
|
||||
transform: function (doc, ret) {
|
||||
delete ret._id
|
||||
},
|
||||
})
|
||||
|
||||
schema.virtual("id").get(function () {
|
||||
return this._id.toHexString()
|
||||
})
|
||||
|
||||
exports.UserModel = model(TODO_AUTH_USER_MODEL_NAME, schema);
|
||||
Reference in New Issue
Block a user