• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EcrituresNumeriques / stylo / 15922807606

27 Jun 2025 09:18AM UTC coverage: 39.241% (+0.04%) from 39.201%
15922807606

push

github

web-flow
Crée des requêtes de prévisualisation d'articles/corpus (#1592)

Co-authored-by: Thomas Parisot <thom4parisot@users.noreply.github.com>
Co-authored-by: Guillaume Grossetie <ggrossetie@yuzutech.fr>

570 of 800 branches covered (71.25%)

Branch coverage included in aggregate %.

90 of 250 new or added lines in 17 files covered. (36.0%)

137 existing lines in 8 files now uncovered.

5638 of 15020 relevant lines covered (37.54%)

2.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.56
/graphql/models/workspace.js
1
const mongoose = require('mongoose')
1✔
2
const toHex = require('colornames')
1✔
3
const { ApiError } = require('../helpers/errors')
1✔
4
const Schema = mongoose.Schema
1✔
5

1✔
6
const WorkspaceMemberSchema = new Schema({
1✔
7
  user: {
1✔
8
    type: mongoose.Schema.Types.ObjectId,
1✔
9
    ref: 'User',
1✔
10
  },
1✔
11
})
1✔
12

1✔
13
const workspaceSchema = new Schema(
1✔
14
  {
1✔
15
    name: {
1✔
16
      type: String,
1✔
17
      required: true,
1✔
18
    },
1✔
19
    color: {
1✔
20
      type: String,
1✔
21
      required: true,
1✔
22
      get: (color) => toHex(color) || color || '#ccc',
1✔
23
    },
1✔
24
    description: {
1✔
25
      type: String,
1✔
26
    },
1✔
27
    bibliographyStyle: {
1✔
28
      type: String,
1✔
29
    },
1✔
30
    members: [WorkspaceMemberSchema],
1✔
31
    articles: [
1✔
32
      {
1✔
33
        type: Schema.Types.ObjectId,
1✔
34
        ref: 'Article',
1✔
35
      },
1✔
36
    ],
1✔
37
    creator: {
1✔
38
      type: Schema.Types.ObjectId,
1✔
39
      ref: 'User',
1✔
40
    },
1✔
41
  },
1✔
42
  { timestamps: true }
1✔
43
)
1✔
44

1✔
45
workspaceSchema.methods.findMembersByArticle =
1✔
46
  async function findMembersByArticle(articleId) {
1✔
47
    const result = await this.aggregate([
×
48
      { $match: { articles: articleId } },
×
49
      // flatten members in order to create a unique set
×
50
      { $unwind: '$members' },
×
51
      { $group: { _id: null, memberIds: { $addToSet: '$members' } } },
×
52
      {
×
53
        $lookup: {
×
54
          from: 'users',
×
55
          localField: 'memberIds',
×
56
          foreignField: '_id',
×
57
          as: 'members',
×
58
        },
×
59
      },
×
60
    ])
×
61
    return result[0].members
×
UNCOV
62
  }
×
63

1✔
64
workspaceSchema.statics.getWorkspaceById = async function getWorkspaceById(
1✔
65
  workspaceId,
×
66
  user
×
67
) {
×
NEW
68
  if (user?.admin === true) {
×
69
    const workspace = await this.findById(workspaceId)
×
NEW
70
    if (!workspace) {
×
NEW
71
      throw new ApiError(
×
72
        'NOT_FOUND',
×
73
        `Unable to find workspace with id ${workspaceId}`
×
74
      )
×
75
    }
×
UNCOV
76
    return workspace
×
UNCOV
77
  }
×
UNCOV
78
  const workspace = await this.findOne({
×
UNCOV
79
    $and: [{ _id: workspaceId }, { 'members.user': user?._id }],
×
UNCOV
80
  })
×
UNCOV
81
  if (!workspace) {
×
UNCOV
82
    throw new ApiError(
×
UNCOV
83
      'NOT_FOUND',
×
UNCOV
84
      `Unable to find workspace with id ${workspaceId} for user with id ${user?._id}`
×
UNCOV
85
    )
×
UNCOV
86
  }
×
UNCOV
87
  return workspace
×
UNCOV
88
}
×
89

1✔
90
module.exports = mongoose.model('Workspace', workspaceSchema)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc