diff --git a/server/model-channel/src/channel.js b/server/model-channel/src/channel.js index 47040abc05e29a4b392f7588353b9e1a5949415a..f8d7315347823bde420469d775d76507138df9e6 100644 --- a/server/model-channel/src/channel.js +++ b/server/model-channel/src/channel.js @@ -40,11 +40,11 @@ class Channel extends BaseModel { }, }, manuscript: { - relation: BaseModel.HasOneRelation, + relation: BaseModel.BelongsToOneRelation, modelClass: Manuscript, join: { - from: 'channels.id', - to: 'manuscripts.channelId', + from: 'channels.manuscriptId', + to: 'manuscripts.id', }, }, users: { @@ -66,11 +66,10 @@ class Channel extends BaseModel { static get schema() { return { properties: { - name: { type: 'string' }, type: { type: ['string', 'null'] }, topic: { type: 'string' }, teamId: { type: ['string', 'null'], format: 'uuid' }, - userId: { type: 'string' }, + manuscriptId: { type: ['string', 'null'], format: 'uuid' }, }, } } diff --git a/server/model-channel/src/graphql/index.js b/server/model-channel/src/graphql/index.js index 736540b3bbae2eaa16da317bd04b34a4eeda4b1c..735d8b1155ee2612d385ff453fcb3618f6ac5570 100644 --- a/server/model-channel/src/graphql/index.js +++ b/server/model-channel/src/graphql/index.js @@ -73,10 +73,8 @@ const resolvers = { const typeDefs = ` type Channel { - user: User id: String - doi: String - name: String + manuscript: Manuscript topic: String type: String team: Team diff --git a/server/model-channel/src/migrations/1585323910-add-channels.sql b/server/model-channel/src/migrations/1585323910-add-channels.sql index b05165a2ddea2509eca692d5cf6da34525964dc1..00b50f44df9754f8af82b46adfe61a6c6cb9fc86 100644 --- a/server/model-channel/src/migrations/1585323910-add-channels.sql +++ b/server/model-channel/src/migrations/1585323910-add-channels.sql @@ -1,10 +1,9 @@ CREATE TABLE channels ( id UUID PRIMARY KEY, - user_id uuid NOT NULL REFERENCES users(id), + manuscript_id uuid REFERENCES manuscripts(id) ON DELETE CASCADE, team_id uuid REFERENCES teams(id), created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp, updated TIMESTAMP WITH TIME ZONE, - name TEXT, topic TEXT, type TEXT ); @@ -13,7 +12,7 @@ CREATE TABLE channel_members ( id UUID PRIMARY KEY, created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp, updated TIMESTAMP WITH TIME ZONE, - user_id uuid NOT NULL REFERENCES users(id), + user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE, channel_id uuid NOT NULL REFERENCES channels(id) ); diff --git a/server/model-manuscript/src/graphql.js b/server/model-manuscript/src/graphql.js index 4685d5731b17c1fc0f07f0c17dfacdc9622d18c9..d0ed5f66ce40823472d7db866637f55e0ce80212 100644 --- a/server/model-manuscript/src/graphql.js +++ b/server/model-manuscript/src/graphql.js @@ -1,5 +1,6 @@ const merge = require('lodash/merge') const form = require('../../../app/storage/forms/submit.json') +const { ref } = require('objection') const resolvers = { Mutation: { @@ -29,9 +30,6 @@ const resolvers = { }), status: 'new', submission, - channel: { - user_id: ctx.user, - }, } // eslint-disable-next-line @@ -39,6 +37,19 @@ const resolvers = { emptyManuscript, ).saveGraph() + // Create two channels: 1. free for all involved, 2. editorial + const allChannel = new ctx.connectors.Channel.model({ + manuscriptId: manuscript.id, + topic: 'Manuscript discussion', + type: 'all', + }).save() + + const editorialChannel = new ctx.connectors.Channel.model({ + manuscriptId: manuscript.id, + topic: 'Editorial discussion', + type: 'editorial', + }).save() + manuscript.manuscriptVersions = [] manuscript.files = [] files.map(async file => { @@ -67,6 +78,7 @@ const resolvers = { ) manuscript.teams = [createdTeam] + manuscript.channels = [allChannel, editorialChannel] return manuscript }, async deleteManuscript(_, { id }, ctx) { @@ -152,7 +164,9 @@ const resolvers = { async manuscript(_, { id }, ctx) { const Manuscript = require('./manuscript') - const manuscript = await Manuscript.find(id) + const manuscript = await Manuscript.query() + .findById(id) + .eager('channels') if (!manuscript.meta) { manuscript.meta = {} @@ -177,9 +191,9 @@ const resolvers = { manuscript.teams = await manuscript.getTeams() manuscript.reviews = await manuscript.getReviews() manuscript.manuscriptVersions = await manuscript.getManuscriptVersions() - manuscript.channel = await ctx.connectors.Channel.model.find( - manuscript.channelId, - ) + // manuscript.channel = await ctx.connectors.Channel.model.find( + // manuscript.channelId, + // ) return manuscript }, async manuscripts(_, { where }, ctx) { @@ -195,8 +209,12 @@ const resolvers = { const totalCount = await query.resultSize() if (sort) { - // e.g. 'created_DESC' into 'created' and 'DESC' arguments - query.orderBy(...sort.split('_')) + const [sortName, sortDirection] = sort.split('_') + + query.orderBy(ref(sortName), sortDirection) + // } + // // e.g. 'created_DESC' into 'created' and 'DESC' arguments + // query.orderBy(...sort.split('_')) } if (limit) { @@ -277,7 +295,7 @@ const typeDefs = ` authors: [Author] meta: ManuscriptMeta submission: String - channel: Channel + channels: [Channel] } type ManuscriptVersion implements Object { diff --git a/server/model-manuscript/src/manuscript.js b/server/model-manuscript/src/manuscript.js index 38c13711638161c65163a9a2cb5771ddeaa0b2d9..e08f9805020d3a16060169fec610bc5e41109260 100644 --- a/server/model-manuscript/src/manuscript.js +++ b/server/model-manuscript/src/manuscript.js @@ -175,12 +175,12 @@ class Manuscript extends BaseModel { const { Channel } = require('@pubsweet/models') return { - channel: { - relation: BaseModel.BelongsToOneRelation, + channels: { + relation: BaseModel.HasManyRelation, modelClass: Channel, join: { - from: 'manuscripts.channelId', - to: 'channels.id', + from: 'manuscripts.id', + to: 'channels.manuscriptId', }, }, } @@ -263,9 +263,8 @@ class Manuscript extends BaseModel { keywords: { type: ['string', 'null'] }, }, }, - // TODO - channelId: { type: ['string', 'null'], format: 'uuid' }, submission: {}, + submitterId: { type: ['string', 'null'], format: 'uuid' }, }, } } diff --git a/server/model-manuscript/src/migrations/1537450834-manuscript.sql b/server/model-manuscript/src/migrations/1581450834-manuscript.sql similarity index 88% rename from server/model-manuscript/src/migrations/1537450834-manuscript.sql rename to server/model-manuscript/src/migrations/1581450834-manuscript.sql index 1fe9713efa673e157a3e6118e33280972c377f46..85c0588b23631008f3876ffa144f24bf92af5c5c 100644 --- a/server/model-manuscript/src/migrations/1537450834-manuscript.sql +++ b/server/model-manuscript/src/migrations/1581450834-manuscript.sql @@ -3,6 +3,7 @@ CREATE TABLE manuscripts ( created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT current_timestamp, updated TIMESTAMP WITH TIME ZONE, parent_id UUID, + submitter_id UUID REFERENCES users(id), status TEXT, decision TEXT, authors JSONB, diff --git a/server/model-manuscript/src/migrations/1591879913-add-channel.sql b/server/model-manuscript/src/migrations/1591879913-add-channel.sql deleted file mode 100644 index 064bfee117da818c30a0a4c5e91cc601ade7168a..0000000000000000000000000000000000000000 --- a/server/model-manuscript/src/migrations/1591879913-add-channel.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE manuscripts ADD COLUMN channel_id UUID; \ No newline at end of file