我的API /auth/login端点采用req.body如下:
{
"email": "jacob@gmail.com",
"password": "supersecretpassword"
}
Run Code Online (Sandbox Code Playgroud)
在端点,我引用了我的Firebase数据库(https://jacob.firebaseio.com/users).我搜索数据,当我找到一个匹配电子邮件的用户时req.body.email,我将密码与存储在数据库中的密码进行比较.
我遵循了此Firebase博客文章中概述的承诺结构.
router.post('/login', function(req, res) {
const ref = db.ref('/users');
ref.orderByChild('email')
.equalTo(req.body.email)
.once('child_added')
.then(function (snapshot) {
return snapshot.val();
})
.then(function (usr) {
// Do my thing, throw any errors that come up
})
.catch(function (err) {
// Handle my errors with grace
return;
});
});
Run Code Online (Sandbox Code Playgroud)
如果找不到孩子ref,则该功能不会继续(请参阅此答案).我甚至没有抛出错误.
我的目标是在没有找到某个电子邮件的用户时运行代码(即没有找到ref满足的子级.equalTo(req.body.email)),但是如果找到用户则不运行代码.找不到任何内容时不会抛出任何错误.
我尝试return在数据库调用的战略要点(在我的.then()承诺结束时)添加语句,目的是在代码运行后完全断开端点.然后我在调用数据库之后输入代码:
.then(function (usr) { …Run Code Online (Sandbox Code Playgroud) javascript node.js promise firebase firebase-realtime-database
更新我的Post模型时,我运行:
$post->title = request('title');
$post->body = request('body');
$post->save();
Run Code Online (Sandbox Code Playgroud)
这并没有更新我的职务.但它应该根据Laravel文档更新Eloquent模型.为什么我的模型没有更新?
save成功是true.Post 模型:
class Post extends Model
{
protected $fillable = [
'type',
'title',
'body',
'user_id',
];
....
}
Run Code Online (Sandbox Code Playgroud)
Post 控制器:
public function store($id)
{
$post = Post::findOrFail($id);
// Request validation
if ($post->type == 1) {
// Post type has title
$this->validate(request(), [
'title' => 'required|min:15',
'body' => 'required|min:19',
]);
$post->title = request('title'); …Run Code Online (Sandbox Code Playgroud) 我在应用程序中使用Firebase身份验证,并使用电子邮件和密码注册了用户。当用户使用自己的帐户登录时,我也想获取其他用户的详细信息(与登录用户分开)。我如何获得该信息?
我在 Heroku 上启动了一个应用程序,该应用程序运行 Django 2.0.1,并提供了 Postgres 资源。经过几次迭代后,我的 Procfile 如下所示:
配置文件
release: python manage.py migrate --noinput
web: gunicorn app.wsgi --log-file -
Run Code Online (Sandbox Code Playgroud)
当我从 GitHub 部署时(不是从命令行......我之前没有从命令行部署,因为 GitHub 部署工作对我来说至关重要)一切正常。迁移运行正常,日志确认迁移时没有错误。事实上,部署到 Heroku 根本没有错误。
当我启动站点(强制它进入调试模式以查看错误)时,我在首页上收到此错误:
ProgrammingError at /
relation "posts_post" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "posts_post" INNER JOIN "u...
Run Code Online (Sandbox Code Playgroud)
尝试加载管理站点时存在类似错误:
ProgrammingError at /admin/login/
relation "django_site" does not exist
LINE 1: ..."django_site"."domain", "django_site"."name" FROM "django_si...
^
Run Code Online (Sandbox Code Playgroud)
我遵循了Django 中的建议:关系“django_site”不存在首先迁移sites,但这什么也没做。
此外,GitHub 上的这个问题是相关的,但没有帮助。
澄清一下,该应用程序是可访问的。Heroku 部署不会失败。该应用程序只是出错了。
追溯 …
这里有人对如何在 Visual Studio Code 中快速更改工作区有建议吗?
当我测试需要构造函数中的一个参数的服务时,我必须使用对象将服务初始化为提供者,而不是简单地将服务作为提供者传递:
auth.service.ts(示例)
@Injectable()
export class AuthService {
constructor(
@InjectRepository(Admin)
private readonly adminRepository: Repository<Admin>,
) { }
// ...
}
Run Code Online (Sandbox Code Playgroud)
auth.service.spec.ts(示例)
describe('AuthService', () => {
let authService: AuthService
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
AuthService,
{
provide: getRepositoryToken(Admin),
useValue: mockRepository,
},
],
}).compile()
authService = module.get<AuthService>(AuthService)
})
// ...
})
Run Code Online (Sandbox Code Playgroud)
有关此解释的来源,请参阅GitHub 上的此问题。
我有一个在构造函数中需要 2 个参数的服务:
auth.service.ts
@Injectable()
export class AuthService {
constructor(
private readonly jwtService: JwtService,
private readonly authHelper: AuthHelper, …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的对象.
{
_id: '577fe7a842c9b447',
name: 'Jacob\'s Bronze Badges',
competitors: [
{
_id: '577fe7a842c9bd6d',
name: 'Peter\'s Silver Badges',
sites: [
{
_id: '577fe7a842c9bd6d',
name: 'Facebook',
url: 'fb.com/peter'
},
{
_id: '577fe7a842c9bd6d'
name: 'Google',
url: 'google.com/peter'
}
]
},
{
_id: '599fe7a842c9bd6d',
name: 'Paul\'s Gold Badges',
sites: [
{
'_id': '577fe7a842c9bd6d',
name: 'Facebook',
url: 'fb.com/paul'
},
{
_id: '577fe7a842c9bd6d',
name: 'Google',
url: 'google.com/paul'
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的目标是引用competitors数组并使用所有值更新内部的项目req.body.我基于这个代码关闭的这个答案,以及该另一个.
Location.update(
{ 'competitors._id': req.params.competitorId, }, …Run Code Online (Sandbox Code Playgroud) 在我的website.com/v2/bridge/:locationId/process端点,传入内容req.body如下所示:
{
choice: 'a',
data: [
{
...
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
我想根据 的值来访问特定的路线req.body.choice。如果req.body.choice === 'a'那时我想继续传递website.com/v2/bridge/:locationId/process/choiceA同样的内容。req
我不知道需要使用什么中间件来实现这一点。我不知道这是否可能。
我极其简化的路线:
// website.com/v2/bridge
const proc = require('./process');
router.use('/:locationId/process', proc);
module.exports = router;
// website.com/v2/bridge/56/process
router.use(function (req, res, next) {
// ?????????????????????????
next();
});
const choiceA = require('./choice-a');
const choiceB = require('./choice-b');
router.use('/choice-a', choiceA);
router.use('/choice-b', choiceB);
module.exports = router;
// website.com/v2/bridge/56/process/choice-a
router.post('/', function (req, res) {
res.send('I got here.');
return;
});
module.exports = …Run Code Online (Sandbox Code Playgroud)