AdonisJS-SyntaxError。意外字符“”

时间:2020-01-31 13:02:55

标签: javascript laravel api laravel-5 adonis.js

我试图从数据库中获取所有人才资源,但是当我在Postman上尝试端点时,它返回了 SyntaxError。意外字符“ ”错误。我不知道那个字符是从哪里来的,因为邮递员暗示错误是在控制器的66行上,但是在检查66行是空行还是空行。 可能导致此错误的原因是什么? 我的控制器代码(API调用的方法如下)

async searchTalent({ request, response }) {
        try {
            const params = request.except('projectId');
            let matchedTalents = [];
            let talentIds = [];
            const {tools, fullname} = params;

            if(tools) {
                const find = await Database.raw("SELECT * FROM pro WHERE MATCH tools AGAINST ('"+ tools +"' IN NATURAL LANGUAGE MODE)");
                const talents = find[0];
                if(talents) {
                    for(let t = 0; t < talents.length; t++) {
                        const talent = talents[t];
                        if(talent.active == true) {
                            const user = await User.query().where({id: talent.userId, active: true, type: 'talent', isDeleted: false}).first();

                            if(user) {
                                if(talentIds.length > 0) {
                                    if(talentIds.includes(talent.id) === false) {
                                        user.profile = talent;
                                        talentIds.push(talent.id);
                                        matchedTalents.push(user);
                                    }
                                } else {
                                    user.profile = talent;
                                    talentIds.push(talent.id);
                                    matchedTalents.push(user);
                                }
                            }
                        }
                    }
                }
                // for (let i = 0; i < tools.length; i++) {
                //  const tool = tools[i];
                // }
            } else if(fullname) {
                const getUsers = await User.query().where('first_name', 'LIKE', '%%' + fullname + '%%').orWhere('last_name', 'LIKE', '%%' + fullname + '%%').where({ active: true}).orderBy('id', 'desc').get();

                for (let i = 0; i < getUsers.length; i++) {
                    const user = getUsers[i];
                    if(user.type == 'talent')
                    {
                        const talent = await Pro.query().where({userId: user.id}).first();

                        if(talent)
                        {
                            user.profile = talent;
                            matchedTalents.push(user);
                        }
                    }
                }
            }
​
            const data = matchedTalents;
​
            return response.json({
                data: data,
                message: data.length + ' Talents fetched',
                error: false
            })
        } catch (e) {
            Event.fire('log::error', e.message)
            return response.json({
                data: [],
                message: e.message,
                error: true
            })
        }
    }

从昨天开始,我一直尝试搜索和修复,但是所有stackoverflow答案似乎都无法解决此问题。

0 个答案:

没有答案
相关问题