сравнение имени пользователя и имени для отображения данных соответственно в node js - PullRequest
0 голосов
/ 07 августа 2020

Я пытаюсь сравнить имя пользователя в userSchema и имя в studentSchema, чтобы отображать только контент с именем пользователя в таблице. Я использую пароль js для аутентификации и mongodb для базы данных. Вот мой пользователь. js

var mongoose = require("mongoose");
var passportLocalMongoose = require("passport-local-mongoose");

var UserSchema = new mongoose.Schema({
    username: String,
    password: String,
    isAdmin: { type: Boolean, default: false }
});

UserSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("User", UserSchema);

и моя схема ученика

var studentSchema = new mongoose.Schema({
    name: String,
    dob: String,
    email: String,
});
вот мой e js для просмотра содержимого в виде таблицы,

<div class="table-responsive">
        <table id="tableinfo" class="table w-auto">
            <p><a id="tran" class="btn btn-primary btn-sm " href="#">Change alignment</a></p>
            <thead class="thead-dark">
                <tr>
                    <!-- <th scope="col">NUM</th> -->
                    <th scope="col">NAME</th>
                    <th scope="col">DOB</th>
                    <th scope="col">EMAIL</th>
                    <%if(currentUser && currentUser.isAdmin) { %>
                    <th class="actbutton" scope="col">EDIT</th>
                    <th class="actbutton" scope="col">DELETE</th>
                    <% } %>
                </tr>
            </thead>
            <tbody>
                <% allstudents.forEach(function(allstudent){ %>
                <tr>
        
                    <td scope="row">
                        <form class="formbutton" action="/allstudents/<%= allstudent.id %>/profile" method="GET"><a
                                href="/allstudents/<%= allstudent.id %>/profile"><%= allstudent.name %></a></form>
                    </td>
                    <td scope="row"><%= allstudent.dob %></td>
                    <td scope="row"><%= allstudent.email %></td>

                    <div class="button">

                        <%if(currentUser && currentUser.isAdmin) { %>


                        <td class="actbutton">
                            <form class="formbutton" action="/allstudents/<%= allstudent.id %>/edit" method="GET">
                                <button class="btn  btn-warning">Edit</button>
                            </form>

                        </td>
                        <td class="actbutton" scope="row">
                            <form class="formbutton" action="/allstudents/<%=allstudent.id%>?_method=DELETE"
                                method="POST">
                                <button class="btn btn-danger">Delete</button>
                            </form>

                        </td>
                    </div>
                    <% } %>

                </tr>
                <% }); %>

            </tbody>
        </table>
        <div class="addnew">
            <a class="btn btn-info btn-group-lg" href="/allstudents/new">Add New Student</a>
        </div>
        <div class="downloadall">

            <button class="btn btn-primary" id="pdf">Download As Pdf</button>
            <button class="btn btn-primary" id="csv">Download As CSV</button>
        </div>

    </div>

вот все зависимости, «зависимости»: {

    "body-parser": "^1.19.0",

    "connect-flash": "^0.1.1",

    "ejs": "^3.1.3",

    "express": "^4.17.1",

    "express-session": "^1.17.1",

    "locus": "^2.0.4",

    "method-override": "^3.0.0",

    "mongoose": "^5.9.26",

    "passport": "^0.4.1",

    "passport-local": "^1.0.0",

    "passport-local-mongoose": "^6.0.1"

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...