def mutate(self, info, snippet_id, tag_ids): snippetId = functions.resolveGlobalId(snippet_id) for id in tag_ids: tagId = functions.resolveGlobalId(id) taggedSnippet = TaggedSnippets(snippet_id=snippetId, tag_id=tagId) db.session.add(taggedSnippet) db.session.commit() return CreateTaggedSnippet(taggedSnippet=taggedSnippet)
def mutate(self, info, snippet_id, tag_id): snippetId, tagId = functions.resolveGlobalId(snippet_id), functions.resolveGlobalId(tag_id) snippet = db.session.query(Snippet).filter_by(id=snippetId).first() if functions.isResourceMatch(snippet): taggedSnippet = db.session.query(TaggedSnippets).filter_by(snippet_id=snippetId, tag_id=tagId).first() db.session.delete(taggedSnippet) db.session.commit() return DeleteTaggedSnippet( status=StatusField(error=False, message=f'Successfully deleted tag id {tagId} from tagged snippet {snippetId},') )
def mutate(self, info, input): snippetId = functions.resolveGlobalId(input.pop('snippet_id')) snippet = db.session.query(Snippet).filter_by(id=snippetId).first() if functions.isResourceMatch(snippet): # transform string ids present in input, to integer values before insertion input.update({ k : functions.resolveGlobalId(v) for (k,v) in input.items() if 'id' in k.split('_') }) db.session.query(Snippet).filter_by(id=snippetId).update(input) db.session.commit() snippet = db.session.query(Snippet).filter_by(id=snippetId).first() return UpdateSnippet(snippet=snippet, status=StatusField(error=False, message="Snippet update success."))
def mutate(self, info, input): userId = functions.resolveUserId() languageId = functions.resolveGlobalId(input['language_id']) folderId = functions.resolveGlobalId(input['folder_id']) dateCreated = pendulum.now().to_datetime_string() snippet = Snippet( user_id=userId, folder_id=folderId, language_id=languageId, title=input['title'], content=input['content'], description=input['description'], date_created=dateCreated ) db.session.add(snippet) db.session.commit() return CreateSnippet(snippet=snippet, status=StatusField(error=False, message="Snippet creation successful"))
def mutate(self, info, snippet_id): snippetId = functions.resolveGlobalId(snippet_id) snippet = db.session.query(Snippet).filter_by(id=snippetId).first() snippetTitle = snippet.title if functions.isResourceMatch(snippet): db.session.delete(snippet) db.session.commit() return DeleteSnippet(status=StatusField(error=False, message=f'Successfully deleted { snippetTitle }'))
def mutate(self, info, **input): folderId = functions.resolveGlobalId(input.pop('folder_id')) folder = db.session.query(Folder).filter_by(id=folderId).first() if functions.isResourceMatch(folder): db.session.query(Folder).filter_by(id=folderId).update(input) db.session.commit() folder = db.session.query(Folder).filter_by(id=folderId).first() return UpdateFolder(folder=folder, status=StatusField(error=False, message="Folder update successful"))
def mutate(self, info, folder_ids): folderIds = [functions.resolveGlobalId(id) for id in folder_ids] for id in folderIds: folder = db.session.query(Folder).filter_by(id=id).first() if functions.isResourceMatch(folder): db.session.delete(folder) db.session.commit() else: return DeleteFolders(status=StatusField(error=True, message="Folder resource does not match user.")) return DeleteFolders(status=StatusField(error=False, message="Folder deletion successful"))
def mutate(self, info, user_id, new_password): userId = functions.resolveGlobalId(user_id) user = db.session.query(User).filter_by(id=userId) user.update({'password': functions.getHashedPass(new_password)}) db.session.commit() return UpadteUserPassword(status=StatusField(error=False, message="Password change successful"))