Skip to content
Snippets Groups Projects
Commit 5debc9ec authored by Sebastian's avatar Sebastian
Browse files

feat(component-user-manager): add author fields to patch

parent c8a66d90
No related branches found
No related tags found
1 merge request!5Refactor component invite
......@@ -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
......
......@@ -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) {
......
......@@ -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()
......
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment