与实例方法中无确切的匹配' filter'在蒸气中

发布于 2025-02-12 03:57:43 字数 1239 浏览 1 评论 0原文

我面临有关“过滤”函数的错误[Fluent的查询API |汽]。

我阅读了Vapor为此案提供的文档,看来语法很好。因此,我不知道确切的问题在哪里。

  • 错误屏幕截图附加下面:

“

  • 这是整个函数的代码段:
        func login(req: Request) throws -> EventLoopFuture<String>
        {
            let userToLogin = try
                req.content.decode(UserLogin.self)
            print("user to login \(userToLogin)")
            
            //Get user from DB
            return User.query(on: req.db)
                .filter( \.$email == userToLogin.email)
                .first()
                .unwrap(or: Abort(.notFound))
                .flatMapThrowing { dbUser in 
                    let verified = try dbUser.verify(password: userToLogin.password)
                    print("attempt verify password \(verified)")
                    if verified == false {
                        throw Abort(.unauthorized)
                    }
                    
                    req.auth.login(dbUser)
                    let user = try req.auth.require(User.self)
                    return try user.generateToken(req.application)
                }
        }

I'm facing an error regarding 'filter' function [Fluent's query API | Vapor].

I read the documentation that´s provided by Vapor for this case and it seems the syntax is fine. Hence I've no idea where the exact issue is located.

  • Error screenshot is attached below:

Screenshot Link

  • Here is the code segment for the whole function:
        func login(req: Request) throws -> EventLoopFuture<String>
        {
            let userToLogin = try
                req.content.decode(UserLogin.self)
            print("user to login \(userToLogin)")
            
            //Get user from DB
            return User.query(on: req.db)
                .filter( \.$email == userToLogin.email)
                .first()
                .unwrap(or: Abort(.notFound))
                .flatMapThrowing { dbUser in 
                    let verified = try dbUser.verify(password: userToLogin.password)
                    print("attempt verify password \(verified)")
                    if verified == false {
                        throw Abort(.unauthorized)
                    }
                    
                    req.auth.login(dbUser)
                    let user = try req.auth.require(User.self)
                    return try user.generateToken(req.application)
                }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她说她爱他 2025-02-19 03:57:43

问题不是filter,而是==需要重载。

确保您的

import Fluent
import Vapor

文件中有。

The problem is not with filter, but with == that needs to be overloaded.

Make sure you have

import Fluent
import Vapor

in you file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文