community model and resolver fixes
This commit is contained in:
parent
f658f27f04
commit
0f6e505706
|
@ -9,46 +9,47 @@ from sqlalchemy import and_
|
||||||
|
|
||||||
@mutation.field("createCommunity")
|
@mutation.field("createCommunity")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_community(_, info, title, desc):
|
async def create_community(_, info, input):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
community = Community.create(
|
community = Community.create(
|
||||||
title = title,
|
slug = input.get('slug', ''),
|
||||||
desc = desc
|
title = input.get('title', ''),
|
||||||
|
desc = input.get('desc', ''),
|
||||||
|
pic = input.get('pic', '')
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"community": community}
|
return {"community": community}
|
||||||
|
|
||||||
@mutation.field("updateCommunity")
|
@mutation.field("updateCommunity")
|
||||||
@login_required
|
@login_required
|
||||||
async def update_community(_, info, id, title, desc, pic):
|
async def update_community(_, info, input):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
community = session.query(Community).filter(Community.id == id).first()
|
community = session.query(Community).filter(Community.slug == inpit.get('slug', '')).first()
|
||||||
if not community:
|
if not community:
|
||||||
return {"error": "invalid community id"}
|
return {"error": "invalid community id"}
|
||||||
if community.owner != user_id:
|
if community.createdBy != user_id:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
community.title = title
|
community.title = input.get('title', '')
|
||||||
community.desc = desc
|
community.desc = input.get('desc', '')
|
||||||
community.pic = pic
|
community.pic = input.get('pic', '')
|
||||||
community.updatedAt = datetime.now()
|
community.updatedAt = datetime.now()
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@mutation.field("deleteCommunity")
|
@mutation.field("deleteCommunity")
|
||||||
@login_required
|
@login_required
|
||||||
async def delete_community(_, info, id):
|
async def delete_community(_, info, slug):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
community = session.query(Community).filter(Community.id == id).first()
|
community = session.query(Community).filter(Community.slug == slug).first()
|
||||||
if not community:
|
if not community:
|
||||||
return {"error": "invalid community id"}
|
return {"error": "invalid community slug"}
|
||||||
if community.owner != user_id:
|
if community.owner != user_id:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
community.deletedAt = datetime.now()
|
community.deletedAt = datetime.now()
|
||||||
|
|
|
@ -29,7 +29,7 @@ type UserResult {
|
||||||
input ShoutInput {
|
input ShoutInput {
|
||||||
slug: String!
|
slug: String!
|
||||||
body: String!
|
body: String!
|
||||||
community: Int!
|
community: String!
|
||||||
mainTopic: String
|
mainTopic: String
|
||||||
topic_slugs: [String]
|
topic_slugs: [String]
|
||||||
title: String
|
title: String
|
||||||
|
@ -133,9 +133,9 @@ type Mutation {
|
||||||
rateComment(id: Int!, value: Int!): Result!
|
rateComment(id: Int!, value: Int!): Result!
|
||||||
|
|
||||||
# community
|
# community
|
||||||
createCommunity(title: String!, desc: String!): Community!
|
createCommunity(community: CommunityInput!): Community!
|
||||||
updateCommunity(community: CommunityInput!): Community!
|
updateCommunity(community: CommunityInput!): Community!
|
||||||
deleteCommunity(id: Int!): Result!
|
deleteCommunity(slug: String!): Result!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
inviteAuthor(author: String!, shout: String!): Result!
|
inviteAuthor(author: String!, shout: String!): Result!
|
||||||
|
@ -239,7 +239,7 @@ type Permission {
|
||||||
type Role {
|
type Role {
|
||||||
id: Int!
|
id: Int!
|
||||||
name: String!
|
name: String!
|
||||||
community: Int!
|
community: String!
|
||||||
desc: String
|
desc: String
|
||||||
permissions: [Permission!]!
|
permissions: [Permission!]!
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ type Shout {
|
||||||
authors: [User!]!
|
authors: [User!]!
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
visibleFor: [User]
|
visibleFor: [User]
|
||||||
community: Int
|
community: String
|
||||||
cover: String
|
cover: String
|
||||||
layout: String
|
layout: String
|
||||||
# replyTo: Shout
|
# replyTo: Shout
|
||||||
|
@ -334,7 +334,6 @@ type Shout {
|
||||||
deletedBy: Int
|
deletedBy: Int
|
||||||
publishedBy: Int # if there is no published field - it is not published
|
publishedBy: Int # if there is no published field - it is not published
|
||||||
publishedAt: DateTime
|
publishedAt: DateTime
|
||||||
|
|
||||||
stat: ShoutStat
|
stat: ShoutStat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user