added ignored fields
parent
50ecea2a6b
commit
b5a97350c2
|
@ -1,6 +1,9 @@
|
|||
import { Request, Response } from "express";
|
||||
import { User } from "../models/user";
|
||||
import { ADMIN_MAX_USERS_PER_PAGE } from "../utils/utils";
|
||||
import {
|
||||
ADMIN_MAX_USERS_PER_PAGE,
|
||||
MONGODB_IGNORED_FIELDS,
|
||||
} from "../utils/constants";
|
||||
|
||||
export async function GetAllUsers(req: Request, res: Response) {
|
||||
try {
|
||||
|
@ -21,7 +24,7 @@ export async function GetAllUsers(req: Request, res: Response) {
|
|||
// Query for the current page with limit and skip
|
||||
const users = await User.find({})
|
||||
.lean()
|
||||
.select("-password -_id -__v") // Exclude password and other fields
|
||||
.select(MONGODB_IGNORED_FIELDS) // Exclude password and other fields
|
||||
.skip(skip)
|
||||
.limit(pageSize);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Request, Response } from "express";
|
|||
import bcrypt from "bcrypt";
|
||||
import { User } from "../models/user";
|
||||
import { saveSession } from "../utils/utils";
|
||||
import { MONGODB_IGNORED_FIELDS } from "../utils/constants";
|
||||
|
||||
export async function SignUp(req: Request, res: Response) {
|
||||
if (!req.body.accountName || !req.body.username || !req.body.password) {
|
||||
|
@ -10,7 +11,9 @@ export async function SignUp(req: Request, res: Response) {
|
|||
|
||||
const { accountName, username, password } = req.body;
|
||||
|
||||
const existingUser = await User.findOne({ accountName }).lean();
|
||||
const existingUser = await User.findOne({ accountName })
|
||||
.select("accountName -_id")
|
||||
.lean();
|
||||
|
||||
if (existingUser) {
|
||||
return res.status(400).json({ status: 1 });
|
||||
|
@ -89,7 +92,9 @@ export async function GetUserProfile(req: Request, res: Response) {
|
|||
try {
|
||||
const user = await User.findOne({
|
||||
accountName: req.params.accountName,
|
||||
}).lean();
|
||||
})
|
||||
.select(MONGODB_IGNORED_FIELDS)
|
||||
.lean();
|
||||
|
||||
if (!user) {
|
||||
return res.status(404).json({ status: "err" });
|
||||
|
|
|
@ -3,3 +3,5 @@ export const DEFAULT_SESSION_EXPIRATION: number = 7 * 24 * 60 * 60 * 1000;
|
|||
|
||||
// Maximum number of users to display per page in the admin interface
|
||||
export const ADMIN_MAX_USERS_PER_PAGE: number = 10;
|
||||
|
||||
export const MONGODB_IGNORED_FIELDS: string = "-password -_id -__v";
|
||||
|
|
Reference in New Issue