From 5debc9ec66846a70244397e5581ec2b4bd739dea Mon Sep 17 00:00:00 2001
From: Sebastian <sebastian.mihalache@thinslices.com>
Date: Tue, 10 Apr 2018 12:51:17 +0300
Subject: [PATCH] feat(component-user-manager): add author fields to patch

---
 .../component-user-manager/src/CollectionsUsers.js    |  5 ++++-
 .../src/routes/collectionsUsers/delete.js             |  1 +
 .../src/routes/collectionsUsers/patch.js              | 11 ++++++++++-
 .../src/tests/collectionsUsers/patch.test.js          |  6 ++++++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/packages/component-user-manager/src/CollectionsUsers.js b/packages/component-user-manager/src/CollectionsUsers.js
index 28d568991..825822638 100644
--- a/packages/component-user-manager/src/CollectionsUsers.js
+++ b/packages/component-user-manager/src/CollectionsUsers.js
@@ -111,7 +111,10 @@ const CollectionsUsers = app => {
    * @apiParamExample {json} Body
    *    {
    *      "isSubmitting": false,
-   *      "isCorresponding": true
+   *      "isCorresponding": true,
+   *      "firstName": "John",
+   *      "lastName": "Smith",
+   *      "affiliation": "UCLA"
    *    }
    * @apiSuccessExample {json} Success
    *    HTTP/1.1 200 OK
diff --git a/packages/component-user-manager/src/routes/collectionsUsers/delete.js b/packages/component-user-manager/src/routes/collectionsUsers/delete.js
index db4cdb7c4..2fae5bea5 100644
--- a/packages/component-user-manager/src/routes/collectionsUsers/delete.js
+++ b/packages/component-user-manager/src/routes/collectionsUsers/delete.js
@@ -20,6 +20,7 @@ module.exports = models => async (req, res) => {
     await collection.save()
     await teamHelper.removeTeamMember(team.id, userId, models.Team)
     user.teams = user.teams.filter(userTeamId => team.id !== userTeamId)
+    delete user.passwordResetToken
     await user.save()
     return res.status(200).json({})
   } catch (e) {
diff --git a/packages/component-user-manager/src/routes/collectionsUsers/patch.js b/packages/component-user-manager/src/routes/collectionsUsers/patch.js
index 4aedb7f38..fb2521e33 100644
--- a/packages/component-user-manager/src/routes/collectionsUsers/patch.js
+++ b/packages/component-user-manager/src/routes/collectionsUsers/patch.js
@@ -4,7 +4,13 @@ const helpers = require('../../helpers/helpers')
 module.exports = models => async (req, res) => {
   // TO DO: add authsome
   const { collectionId, userId } = req.params
-  const { isSubmitting, isCorresponding } = req.body
+  const {
+    isSubmitting,
+    isCorresponding,
+    firstName,
+    lastName,
+    affiliation,
+  } = req.body
 
   if (!helpers.checkForUndefinedParams(isSubmitting, isCorresponding)) {
     res.status(400).json({ error: 'Missing parameters' })
@@ -28,6 +34,9 @@ module.exports = models => async (req, res) => {
         error: 'Collection and user do not match',
       })
     }
+    matchingAuthor.firstName = firstName
+    matchingAuthor.lastName = lastName
+    matchingAuthor.affiliation = affiliation
     matchingAuthor.isSubmitting = isSubmitting
     matchingAuthor.isCorresponding = isCorresponding
     collection = await collection.save()
diff --git a/packages/component-user-manager/src/tests/collectionsUsers/patch.test.js b/packages/component-user-manager/src/tests/collectionsUsers/patch.test.js
index e18c21f6f..be165f4b6 100644
--- a/packages/component-user-manager/src/tests/collectionsUsers/patch.test.js
+++ b/packages/component-user-manager/src/tests/collectionsUsers/patch.test.js
@@ -4,6 +4,8 @@ process.env.SUPPRESS_NO_CONFIG_WARNING = true
 const httpMocks = require('node-mocks-http')
 const fixtures = require('./../fixtures/fixtures')
 const Model = require('./../helpers/Model')
+const Chance = require('chance')
+const chance = new Chance()
 
 const models = Model.build()
 jest.mock('pubsweet-component-mail-service', () => ({
@@ -17,6 +19,9 @@ const { standardCollection, authorsCollection } = fixtures.collections
 const body = {
   isSubmitting: false,
   isCorresponding: true,
+  firstName: chance.first(),
+  lastName: chance.last(),
+  affiliation: chance.company(),
 }
 const patchPath = '../../routes/collectionsUsers/patch'
 describe('Patch collections users route handler', () => {
@@ -36,6 +41,7 @@ describe('Patch collections users route handler', () => {
     )
     expect(matchingAuthor.isSubmitting).toBe(body.isSubmitting)
     expect(matchingAuthor.isCorresponding).toBe(body.isCorresponding)
+    expect(matchingAuthor.firstName).toBe(body.firstName)
   })
   it('should return an error when the params are missing', async () => {
     delete body.isSubmitting
-- 
GitLab