mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
feat(backend): event parameters
This commit is contained in:
parent
f00b36b99e
commit
927da4ffb8
22
backend/src/schema/resolvers/helpers/events.js
Normal file
22
backend/src/schema/resolvers/helpers/events.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { UserInputError } from 'apollo-server'
|
||||
|
||||
export const validateEventParams = (params) => {
|
||||
const { eventInput } = params
|
||||
validateEventDate(eventInput.eventStart)
|
||||
params.eventStart = eventInput.eventStart
|
||||
if (eventInput.eventLocation && !eventInput.eventVenue) {
|
||||
throw new UserInputError('Event venue must be present if event location is given!')
|
||||
}
|
||||
params.eventVenue = eventInput.eventVenue
|
||||
params.eventLocation = eventInput.eventLocation
|
||||
}
|
||||
|
||||
const validateEventDate = (dateString) => {
|
||||
const date = new Date(dateString)
|
||||
if (date.toString() === 'Invalid Date')
|
||||
throw new UserInputError('Event start date must be a valid date!')
|
||||
const now = new Date()
|
||||
if (date.getTime() < now.getTime()) {
|
||||
throw new UserInputError('Event start date must be in the future!')
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,8 @@ import Resolver from './helpers/Resolver'
|
||||
import { filterForMutedUsers } from './helpers/filterForMutedUsers'
|
||||
import { filterInvisiblePosts } from './helpers/filterInvisiblePosts'
|
||||
import { filterPostsOfMyGroups } from './helpers/filterPostsOfMyGroups'
|
||||
import { validateEventParams } from './helpers/events'
|
||||
import { createOrUpdateLocations } from './users/location'
|
||||
import CONFIG from '../../config'
|
||||
|
||||
const maintainPinnedPosts = (params) => {
|
||||
@ -81,6 +83,15 @@ export default {
|
||||
CreatePost: async (_parent, params, context, _resolveInfo) => {
|
||||
const { categoryIds, groupId } = params
|
||||
const { image: imageInput } = params
|
||||
|
||||
if (params.postType && params.postType === 'Event') {
|
||||
validateEventParams(params)
|
||||
}
|
||||
delete params.eventInput
|
||||
|
||||
const locationName = params.eventLocation ? params.eventLocation : null
|
||||
delete params.eventLoaction
|
||||
|
||||
delete params.categoryIds
|
||||
delete params.image
|
||||
delete params.groupId
|
||||
@ -143,6 +154,9 @@ export default {
|
||||
})
|
||||
try {
|
||||
const post = await writeTxResultPromise
|
||||
if (locationName) {
|
||||
await createOrUpdateLocations('Post', post.id, locationName, session)
|
||||
}
|
||||
return post
|
||||
} catch (e) {
|
||||
if (e.code === 'Neo.ClientError.Schema.ConstraintValidationFailed')
|
||||
|
||||
@ -171,14 +171,26 @@ type Post {
|
||||
@cypher(statement: "MATCH (this)<-[emoted:EMOTED]-(:User) RETURN COUNT(DISTINCT emoted)")
|
||||
|
||||
group: Group @relation(name: "IN", direction: "OUT")
|
||||
|
||||
postType: [PostType]
|
||||
@cypher(statement: "RETURN filter(l IN labels(this) WHERE NOT l = 'Post')")
|
||||
|
||||
eventLocationName: String
|
||||
eventLocation: Location @cypher(statement: "MATCH (this)-[:IS_IN]->(l:Location) RETURN l")
|
||||
eventVenue: String
|
||||
eventStart: String
|
||||
}
|
||||
|
||||
input _PostInput {
|
||||
id: ID!
|
||||
}
|
||||
|
||||
input _EventInput {
|
||||
eventStart: String!
|
||||
eventLocation: String
|
||||
eventVenue: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
CreatePost(
|
||||
id: ID
|
||||
@ -192,6 +204,7 @@ type Mutation {
|
||||
contentExcerpt: String
|
||||
groupId: ID
|
||||
postType: PostType = Article
|
||||
eventInput: _EventInput
|
||||
): Post
|
||||
UpdatePost(
|
||||
id: ID!
|
||||
@ -204,6 +217,7 @@ type Mutation {
|
||||
language: String
|
||||
categoryIds: [ID]
|
||||
postType: PostType
|
||||
eventInput: _EventInput
|
||||
): Post
|
||||
DeletePost(id: ID!): Post
|
||||
AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user