mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Merge branch 'uploads-on-server' of github.com:Human-Connection/Human-Connection into 399-user-profile-image-uploads
This commit is contained in:
commit
e2d6d6217f
@ -106,4 +106,4 @@
|
||||
"nodemon": "~1.19.0",
|
||||
"supertest": "~4.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import rewards from './resolvers/rewards.js'
|
||||
import socialMedia from './resolvers/socialMedia.js'
|
||||
import notifications from './resolvers/notifications'
|
||||
import comments from './resolvers/comments'
|
||||
import users from './resolvers/users'
|
||||
|
||||
export const typeDefs = fs
|
||||
.readFileSync(
|
||||
@ -36,6 +37,7 @@ export const resolvers = {
|
||||
...rewards.Mutation,
|
||||
...socialMedia.Mutation,
|
||||
...notifications.Mutation,
|
||||
...comments.Mutation
|
||||
...comments.Mutation,
|
||||
...users.Mutation
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { UserInputError } from 'apollo-server'
|
||||
const USERNAME_MIN_LENGTH = 3
|
||||
|
||||
const validateUsername = async (resolve, root, args, context, info) => {
|
||||
if (args.name && args.name.length >= USERNAME_MIN_LENGTH) {
|
||||
if (!('name' in args) || args.name && args.name.length >= USERNAME_MIN_LENGTH) {
|
||||
/* eslint-disable-next-line no-return-await */
|
||||
return await resolve(root, args, context, info)
|
||||
} else {
|
||||
|
||||
29
backend/src/resolvers/users.js
Normal file
29
backend/src/resolvers/users.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { neo4jgraphql } from 'neo4j-graphql-js'
|
||||
import { createWriteStream } from 'fs'
|
||||
|
||||
|
||||
const storeUpload = ({ stream, fileLocation}) =>
|
||||
new Promise((resolve, reject) =>
|
||||
stream
|
||||
.pipe(createWriteStream(`public${fileLocation}`))
|
||||
.on("finish", () => resolve())
|
||||
.on("error", reject)
|
||||
);
|
||||
|
||||
export default {
|
||||
Mutation: {
|
||||
UpdateUser: async (object, params, context, resolveInfo) => {
|
||||
const { avatarUpload } = params
|
||||
|
||||
if (avatarUpload) {
|
||||
const { stream, filename } = await avatarUpload ;
|
||||
const fileLocation = `/uploads/${filename}`
|
||||
await storeUpload({ stream, fileLocation });
|
||||
delete params.avatarUpload
|
||||
|
||||
params.avatar = fileLocation
|
||||
}
|
||||
return await neo4jgraphql(object, params, context, resolveInfo, false)
|
||||
}
|
||||
},
|
||||
};
|
||||
@ -1,3 +1,5 @@
|
||||
scalar Upload
|
||||
|
||||
type Query {
|
||||
isLoggedIn: Boolean!
|
||||
# Get the currently logged in User based on the given JWT Token
|
||||
@ -18,6 +20,7 @@ type Query {
|
||||
)
|
||||
CommentByPost(postId: ID!): [Comment]!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
# Get a JWT Token for the given Email and password
|
||||
login(email: String!, password: String!): String!
|
||||
@ -99,6 +102,7 @@ type User {
|
||||
slug: String
|
||||
password: String!
|
||||
avatar: String
|
||||
avatarUpload: Upload
|
||||
deleted: Boolean
|
||||
disabled: Boolean
|
||||
disabledBy: User @relation(name: "DISABLED", direction: "IN")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user