mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
WIP - first try to create a report mutation which attaches nodes internally
This commit is contained in:
parent
7593a094e0
commit
5c88037d5c
@ -5,6 +5,7 @@ import bcrypt from 'bcryptjs'
|
||||
import zipObject from 'lodash/zipObject'
|
||||
import generateJwt from './jwt/generateToken'
|
||||
import { fixUrl } from './middleware/fixImageUrlsMiddleware'
|
||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
|
||||
export const typeDefs =
|
||||
fs.readFileSync(process.env.GRAPHQL_SCHEMA || path.join(__dirname, 'schema.graphql'))
|
||||
@ -121,6 +122,12 @@ export const resolvers = {
|
||||
|
||||
session.close()
|
||||
throw new Error('No Such User exists.')
|
||||
},
|
||||
report: async (parent, { resource, description }, { driver, req, user }, resolveInfo) => {
|
||||
return neo4jgraphql(parent, { resource, description }, { driver, req, user }, resolveInfo)
|
||||
// console.log('params', { resource, description })
|
||||
// console.log(`the user with the id ${user.id} tries to create a report on content of type ${resource.type} (${resource.id})`)
|
||||
// throw new Error(`resource.id: ${resource.id}, resource.type: ${resource.type}, description: ${description}, user: ${user.id}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import { rule, shield, allow } from 'graphql-shield'
|
||||
|
||||
/*
|
||||
* TODO: implement
|
||||
* See: https://github.com/Human-Connection/Nitro-Backend/pull/40#pullrequestreview-180898363
|
||||
* TODO: implement
|
||||
* See: https://github.com/Human-Connection/Nitro-Backend/pull/40#pullrequestreview-180898363
|
||||
*/
|
||||
const isAuthenticated = rule()(async (parent, args, ctx, info) => {
|
||||
return ctx.user !== null
|
||||
})
|
||||
/*
|
||||
const isAdmin = rule()(async (parent, args, ctx, info) => {
|
||||
return ctx.user.role === 'ADMIN'
|
||||
})
|
||||
@ -26,8 +28,9 @@ const permissions = shield({
|
||||
// customers: and(isAuthenticated, isAdmin)
|
||||
},
|
||||
Mutation: {
|
||||
report: isAuthenticated
|
||||
// addFruitToBasket: isAuthenticated
|
||||
// CreateUser: allow
|
||||
// CreateUser: allow,
|
||||
},
|
||||
User: {
|
||||
email: isOwner,
|
||||
|
||||
@ -5,6 +5,7 @@ type Query {
|
||||
type Mutation {
|
||||
login(email: String!, password: String!): LoggedInUser
|
||||
signup(email: String!, password: String!): Boolean!
|
||||
report(resource: Resource!, description: String): Report
|
||||
}
|
||||
type LoggedInUser {
|
||||
id: ID!
|
||||
@ -32,6 +33,17 @@ scalar Date
|
||||
scalar Time
|
||||
scalar DateTime
|
||||
|
||||
input Resource {
|
||||
id: ID!,
|
||||
type: _ResourceType!
|
||||
}
|
||||
|
||||
enum _ResourceType {
|
||||
contribution
|
||||
comment
|
||||
user
|
||||
}
|
||||
|
||||
enum VisibilityEnum {
|
||||
public
|
||||
friends
|
||||
@ -138,6 +150,16 @@ type Comment {
|
||||
disabled: Boolean
|
||||
}
|
||||
|
||||
type Report {
|
||||
id: ID!
|
||||
author: User @relation(name: "REPORTED", direction: "IN")
|
||||
description: String
|
||||
createdAt: String
|
||||
comment: Comment @relation(name: "REPORTED", direction: "OUT")
|
||||
contribution: Post @relation(name: "REPORTED", direction: "OUT")
|
||||
user: User @relation(name: "REPORTED", direction: "OUT")
|
||||
}
|
||||
|
||||
type Category {
|
||||
id: ID!
|
||||
name: String!
|
||||
|
||||
@ -15,7 +15,9 @@ const seed = {
|
||||
Organization: require('./organizations.js').default,
|
||||
Post: require('./posts.js').default,
|
||||
Comment: require('./comments.js').default,
|
||||
UserShouts: require('./users-shouts.js').default
|
||||
UserShouts: require('./users-shouts.js').default,
|
||||
|
||||
Reports: require('./reports.js').default
|
||||
}
|
||||
|
||||
let data = {}
|
||||
|
||||
45
src/seed/data/reports.js
Normal file
45
src/seed/data/reports.js
Normal file
@ -0,0 +1,45 @@
|
||||
export default function (data) {
|
||||
return `
|
||||
mutation {
|
||||
r1: CreateReport(id: "r1", description: "Bad Stuff") {
|
||||
id
|
||||
}
|
||||
r2: CreateReport(id: "r2", description: "Please remove this sh**") {
|
||||
id
|
||||
}
|
||||
r3: CreateReport(id: "r3", description: "The user have misbehaved!") {
|
||||
id
|
||||
}
|
||||
ra1: AddReportAuthor(from: { id: "u1" }, to: { id: "r1" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
ra2: AddReportAuthor(from: { id: "u2" }, to: { id: "r2" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
ra3: AddReportAuthor(from: { id: "u3" }, to: { id: "r3" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
rc1: AddReportContribution(from: { id: "r1" }, to: { id: "p2" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
rc2: AddReportComment(from: { id: "r2" }, to: { id: "c2" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
rc3: AddReportUser(from: { id: "r3" }, to: { id: "u4" }) {
|
||||
from {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user