28 lines
641 B
JavaScript
28 lines
641 B
JavaScript
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);
|