我目前在 NestJS 项目中使用 Swagger,并且启用了资源管理器:
在 main.js
const options = new DocumentBuilder()
.setTitle('My App')
.setSchemes('https')
.setDescription('My App API documentation')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, options)
SwaggerModule.setup('docs', app, document, {
customSiteTitle: 'My App documentation',
})
Run Code Online (Sandbox Code Playgroud)
有了这个,资源管理器可以访问,/docs
这是我所期望的。但我想知道是否可以向资源管理器添加任何身份验证层,因此只接受某些请求。
我想让这个资源管理器在生产中可以访问,但仅限于经过身份验证的用户。
提前致谢 :)
我想从模型中获取新行.在给定日期之后创建的行.查询应该很简单:
其中updatedAt > = givenDate
但它不起作用:(
我的代码:
// Date from client
var lastDate = req.param("date");
// Parse date with moment? I have tried with and without this.
lastDate = moment(lastDate).format('YYYY-MM-DD hh:mm:ss');
var query = Message.find().where({
updatedAt: {
'>=': lastDate
}
});
query.exec(function(err, messages) {
// I get ALL the messages, :(
res.send(messages);
});
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我有一个 Laravel 模型,它有一个计算访问器:
模型Job有一些JobApplications与User相关联。我想知道用户是否已经申请了工作。
为此,我创建了一个user_applied
获取applications
与当前用户关系的访问器。这可以正常工作,但是每次访问该字段时都会计算访问器(进行查询)。
有没有什么简单的方法可以只计算一次访问器
/**
* Whether the user applied for this job or not.
*
* @return bool
*/
public function getUserAppliedAttribute()
{
if (!Auth::check()) {
return false;
}
return $this->applications()->where('user_id', Auth::user()->id)->exists();
}
Run Code Online (Sandbox Code Playgroud)
提前致谢。
accessor ×1
eloquent ×1
laravel ×1
nestjs ×1
node.js ×1
openapi ×1
optimization ×1
php ×1
sails.js ×1
swagger-ui ×1
typescript ×1
waterline ×1