From 3922868d5d0ffdda774c7efcb814479da7a0af38 Mon Sep 17 00:00:00 2001 From: Matheus Ribeiro Pimenta Nunes Date: Tue, 8 Oct 2019 12:44:23 -0300 Subject: [PATCH] fix: fix response of `POST /register` Fix #8 --- src/controllers/UserController.ts | 4 ++-- src/schemas/User.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index bb0e2be..6bf0ab2 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express' import * as Yup from 'yup' -import omit from 'lodash/omit' +import pick from 'lodash/pick' import User from '../schemas/User' import CheckUserEmail from '../services/CheckUserEmail' @@ -25,7 +25,7 @@ class UserController { } const user = await User.create(req.body) - return res.json(omit(user.toObject(), ['password'])) + return res.json(pick(user.toObject(), ['_id', 'name', 'email'])) } catch (err) { return res.status(400).json({ error: 'Registration failed' }) } diff --git a/src/schemas/User.ts b/src/schemas/User.ts index 236583f..f9fa45a 100644 --- a/src/schemas/User.ts +++ b/src/schemas/User.ts @@ -20,8 +20,7 @@ const UserSchema = new Schema({ }, password: { type: String, - required: true, - select: false + required: true } }, { versionKey: false,