Skip to content
Snippets Groups Projects
Commit 1afdc7f4 authored by Jure's avatar Jure
Browse files

feat: support two channels per manuscripts

parent 5b15712c
No related branches found
No related tags found
No related merge requests found
......@@ -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' },
},
}
}
......
......@@ -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
......
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)
);
......
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 {
......
......@@ -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' },
},
}
}
......
......@@ -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,
......
ALTER TABLE manuscripts ADD COLUMN channel_id UUID;
\ No newline at end of file
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