Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose les objets tags lors d'une requête GraphQL user { articles } et user { article(id) } #725

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions front/src/components/Write/Versions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,11 @@ import styles from './versions.module.scss'
import menuStyles from './menu.module.scss'
import buttonStyles from '../button.module.scss'

import { generateArticleExportId } from '../../helpers/identifier'

import Modal from '../Modal'
import Export from '../Export'
import Button from '../Button'
import CreateVersion from './CreateVersion'

const date = new Intl.DateTimeFormat(['en', 'fr'], {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: 'numeric',
minute: 'numeric',
timeZone: 'UTC',
timeZoneName: 'short',
})

const dateFormat = date.format.bind(date)
import formatTimeAgo from '../../helpers/formatTimeAgo.js'

export default function Versions ({ article, selectedVersion, compareTo, readOnly }) {
const articleVersions = useSelector(state => state.articleVersions, shallowEqual)
Expand Down Expand Up @@ -89,10 +76,12 @@ export default function Versions ({ article, selectedVersion, compareTo, readOnl
<p>
{v.owner && (
<span>
by <strong>{v.owner.displayName}</strong>{' '}
by <strong>{v.owner.displayName}</strong>{', '}
</span>
)}
{<span>on <time dateTime={v.updatedAt}>{dateFormat(v.updatedAt)}</time></span>}
<span>
<time dateTime={v.updatedAt}>{formatTimeAgo(v.updatedAt)}</time>
</span>
</p>
<ul className={styles.actions}>
{v._id !== compareTo && (
Expand Down
2 changes: 1 addition & 1 deletion graphql/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ articleSchema.methods.unshareWith = async function shareWith(user) {

articleSchema.methods.createNewVersion = async function createNewVersion ({ mode, message, user }) {
const { bib, yaml, md } = this.workingVersion
const mostRecentVersion = this.version.at(0)
const mostRecentVersion = this.versions.at(0)

const { revision, version } = mode === 'MAJOR'
? computeMajorVersion(mostRecentVersion)
Expand Down
12 changes: 10 additions & 2 deletions graphql/resolvers/userResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,21 @@ module.exports = {

User: {
async articles(user, { limit }) {
await user.populate({ path: 'articles', options: { limit } }).execPopulate()
await user.populate({
path: 'articles',
options: { limit },
populate: { path: 'owner tags' }
}).execPopulate()

return user.articles
},

async article (user, { id: _id }) {
await user.populate({ path: 'articles', match: { _id }}).execPopulate()
await user.populate({
path: 'articles',
match: { _id },
populate: { path: 'owner tags' }
}).execPopulate()

return user.articles[0]
}
Expand Down