fix type of User.member

This commit is contained in:
sam 2024-03-26 17:15:35 +01:00
parent a09f40fa35
commit da87b4e273
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
2 changed files with 18 additions and 5 deletions

View file

@ -5,7 +5,7 @@ from quart_schema import QuartSchema, RequestSchemaValidationError
from .blueprints import members_blueprint, users_blueprint
from .db.aio import async_session
from .db.util import validate_token
from .exceptions import ExpectedError
from .exceptions import ExpectedError, ErrorCode
app = Quart(__name__)
app = cors(
@ -23,8 +23,8 @@ for bp in (users_blueprint, members_blueprint):
@app.errorhandler(RequestSchemaValidationError)
async def handle_request_validation_error(error: RequestSchemaValidationError):
print(error.validation_error)
return {"error": "VALIDATION"}, 400
# TODO: parse the error and return a format closer to the draft APIv2
return {"code": ErrorCode.BadRequest, "message": "Bad request"}, 400
@app.errorhandler(ExpectedError)
@ -32,6 +32,16 @@ async def handle_expected_error(error: ExpectedError):
return {"code": error.type, "message": error.msg}, error.status_code
@app.errorhandler(404)
async def handle_404(_):
return {"code": 404, "message": "Not found"}, 404
@app.errorhandler(500)
async def handle_500(_):
return {"code": 500, "message": "Internal server error"}, 500
@app.before_request
async def get_user_from_token():
"""Get the current user from a token given in the `Authorization` header or the `pronounscc-token` cookie.

View file

@ -1,6 +1,6 @@
import enum
from datetime import datetime
from typing import Any
from typing import Any, TYPE_CHECKING
from sqlalchemy import BigInteger, DateTime, ForeignKey, Integer, Text
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
@ -9,6 +9,9 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
from .base import Base
from .snowflake import Snowflake
if TYPE_CHECKING:
from .member import Member
class User(Base):
__tablename__ = "users"
@ -30,7 +33,7 @@ class User(Base):
auth_methods: Mapped[list["AuthMethod"]] = relationship(
back_populates="user", cascade="all, delete-orphan"
)
members: Mapped[list["Member"]] = relationship( # noqa: F821
members: Mapped[list["Member"]] = relationship(
back_populates="user", cascade="all, delete-orphan"
)