Skip to content

Commit

Permalink
Create role admin for authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyendacthienngan committed Dec 26, 2021
1 parent 1ca48e7 commit 37023f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
8 changes: 8 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
const mongoose = require('mongoose');
const { Role } = require('./role.js')
mongoose.connect('mongodb://127.0.0.1:27017/watch-out-server')

// let admin = new Role({ _id: new mongoose.mongo.ObjectId("61c835841cf23b3200a016e8"), role_name: 'admin' });
// let user = new Role({ _id: new mongoose.mongo.ObjectId("61c835841cf23b3200a016e9"), role_name: 'user' });

// (async () => {
// await Role.create(admin, user);
// })();
11 changes: 11 additions & 0 deletions models/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var mongoose = require("mongoose");
const schemaOptions = {
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
};

const roleSchema = new mongoose.Schema({
role_name: String,
}, schemaOptions);

const Role = mongoose.model('Role', roleSchema);
module.exports.Role = Role;
13 changes: 7 additions & 6 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var mongoose = require("mongoose");
const mongoose = require("mongoose");
const schemaOptions = {
timestamps: { createdAt: 'created_at', updatedAt: 'updated_at' },
};
Expand All @@ -19,14 +19,15 @@ const User = new mongoose.Schema ({
},
gender: { type: String },
birth_date: { type: Date },
phone: { type: Number },
phone_number: { type: String },
country: { type: String },
password: {
type: String,
required: true,
min: 6,
max: 255
type: String,
required: true,
min: 6,
max: 255
},
role: { type: mongoose.Schema.Types.ObjectId, ref: "roleSchema", default: mongoose.mongo.ObjectId("61c835841cf23b3200a016e8") },
avatar: { type: String },
}, schemaOptions);

Expand Down

0 comments on commit 37023f0

Please sign in to comment.