community model and resolver fixes

This commit is contained in:
tonyrewin 2022-06-28 22:40:44 +03:00
parent f658f27f04
commit 0f6e505706
2 changed files with 19 additions and 19 deletions

View File

@ -9,46 +9,47 @@ from sqlalchemy import and_
@mutation.field("createCommunity")
@login_required
async def create_community(_, info, title, desc):
async def create_community(_, info, input):
auth = info.context["request"].auth
user_id = auth.user_id
community = Community.create(
title = title,
desc = desc
slug = input.get('slug', ''),
title = input.get('title', ''),
desc = input.get('desc', ''),
pic = input.get('pic', '')
)
return {"community": community}
@mutation.field("updateCommunity")
@login_required
async def update_community(_, info, id, title, desc, pic):
async def update_community(_, info, input):
auth = info.context["request"].auth
user_id = auth.user_id
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:
return {"error": "invalid community id"}
if community.owner != user_id:
if community.createdBy != user_id:
return {"error": "access denied"}
community.title = title
community.desc = desc
community.pic = pic
community.title = input.get('title', '')
community.desc = input.get('desc', '')
community.pic = input.get('pic', '')
community.updatedAt = datetime.now()
session.commit()
@mutation.field("deleteCommunity")
@login_required
async def delete_community(_, info, id):
async def delete_community(_, info, slug):
auth = info.context["request"].auth
user_id = auth.user_id
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:
return {"error": "invalid community id"}
return {"error": "invalid community slug"}
if community.owner != user_id:
return {"error": "access denied"}
community.deletedAt = datetime.now()

View File

@ -29,7 +29,7 @@ type UserResult {
input ShoutInput {
slug: String!
body: String!
community: Int!
community: String!
mainTopic: String
topic_slugs: [String]
title: String
@ -133,9 +133,9 @@ type Mutation {
rateComment(id: Int!, value: Int!): Result!
# community
createCommunity(title: String!, desc: String!): Community!
createCommunity(community: CommunityInput!): Community!
updateCommunity(community: CommunityInput!): Community!
deleteCommunity(id: Int!): Result!
deleteCommunity(slug: String!): Result!
# collab
inviteAuthor(author: String!, shout: String!): Result!
@ -239,7 +239,7 @@ type Permission {
type Role {
id: Int!
name: String!
community: Int!
community: String!
desc: String
permissions: [Permission!]!
}
@ -318,7 +318,7 @@ type Shout {
authors: [User!]!
ratings: [Rating]
visibleFor: [User]
community: Int
community: String
cover: String
layout: String
# replyTo: Shout
@ -334,7 +334,6 @@ type Shout {
deletedBy: Int
publishedBy: Int # if there is no published field - it is not published
publishedAt: DateTime
stat: ShoutStat
}