Commit 99f83d95 authored by Yannis Barlas's avatar Yannis Barlas

chore(*): delete related teams and members along with manuscript

parent eb9658ee
......@@ -24,6 +24,7 @@ const isTeamMember = async (user, roles, object, context) => {
}
const isGlobalTeamMember = async (user, roles, context) => {
console.log(user)
const teams = await Promise.all(
user.teams.map(teamId => context.models.Team.find(getId(teamId))),
)
......
......@@ -4,7 +4,7 @@ const isEqual = require('lodash/isEqual')
const merge = require('lodash/merge')
const union = require('lodash/union')
const { Team, User } = require('@pubsweet/models')
const { Team, TeamMember, User } = require('@pubsweet/models')
const Manuscript = require('./manuscript')
const Review = require('../../review/src/review')
......@@ -50,6 +50,16 @@ const resolvers = {
Mutation: {
async deleteManuscript(_, { id }) {
await Manuscript.query().deleteById(id)
const relatedTeams = await Team.query()
.select('id')
.where({ objectId: id })
const relatedTeamIds = relatedTeams.map(t => t.id)
await TeamMember.query()
.delete()
.whereIn('teamId', relatedTeamIds)
return id
},
async handleInvitation(_, { action, articleId, currentUserId }, context) {
......
Markdown is supported
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