diff --git a/backend-services/user-service/controllers/appController.js b/backend-services/user-service/controllers/appController.js index 735587686d87210627bd0ead44b542f937285a75..ddecf556e03e4e6c7f304bdce15629f49f7d7973 100644 --- a/backend-services/user-service/controllers/appController.js +++ b/backend-services/user-service/controllers/appController.js @@ -70,7 +70,17 @@ export async function register(req,res){ // return save result as a response user.save() - .then(result => res.status(201).send({ msg: "User Registered Successfully"})) + .then(async (result) => { + const user = await UserModel.findOne({username: username}) + + // create jwt token + const token = jwt.sign({ + userId: user._id, + username : user.username + }, ENV.JWT_SECRET , { expiresIn : "24h"}); + + res.status(201).send({ msg: "User Registered Successfully", username: user.username, token }) + }) .catch(error => res.status(500).send({error})) }).catch(error => { @@ -195,3 +205,22 @@ export async function updateUser(req,res){ } } +/** + * GET /userlist + * This DOES NOT return emails and passwords + * @param {*} req + * @param {*} res + * @returns + * + * body: {userIdList: []} + */ +export const GetUserList = async (req,res) => { + try { + const {userIdList} = req.body; + const users = await UserModel.find({ '_id': { $in: userIdList } }, {password: 0, email: 0}); + return res.status(201).send({ userList: users}); + } catch(error){ + return res.status(401).send({ error }); + } +} +