mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-20 20:01:25 +00:00
- rename some variables in comments.spec.js while dealing with merge conflicts - rename EditCommentForm/index.vue with new naming convention - add comment to explain absense of <no-ssr> - use a comments content for edit comment form content, not excerpt
30 lines
911 B
JavaScript
30 lines
911 B
JavaScript
import { UserInputError } from 'apollo-server'
|
|
|
|
const validateUrl = async (resolve, root, args, context, info) => {
|
|
const { url } = args
|
|
const isValid = url.match(/^(?:https?:\/\/)(?:[^@\n])?(?:www\.)?([^:/\n?]+)/g)
|
|
if (isValid) {
|
|
/* eslint-disable-next-line no-return-await */
|
|
return await resolve(root, args, context, info)
|
|
} else {
|
|
throw new UserInputError('Input is not a URL')
|
|
}
|
|
}
|
|
|
|
const validateUpdateComment = async (resolve, root, args, context, info) => {
|
|
const COMMENT_MIN_LENGTH = 1
|
|
const content = args.content.replace(/<(?:.|\n)*?>/gm, '').trim()
|
|
if (!args.content || content.length < COMMENT_MIN_LENGTH) {
|
|
throw new UserInputError(`Comment must be at least ${COMMENT_MIN_LENGTH} character long!`)
|
|
}
|
|
|
|
return resolve(root, args, context, info)
|
|
}
|
|
|
|
export default {
|
|
Mutation: {
|
|
CreateSocialMedia: validateUrl,
|
|
UpdateComment: validateUpdateComment,
|
|
},
|
|
}
|