我正在使用带有环回的 mongodb,并且在成功连接后,我收到以下警告
Top-level use of w, wtimeout, j, and fsync is deprecated. Use writeConcern instead.
Run Code Online (Sandbox Code Playgroud)
环回版本:5.5.0
如何摆脱这个?请帮忙
我有一个端点,用户和来宾(未经过身份验证)都可以将数据发布到:
async create(
@requestBody({
content: {
'application/json': {
schema: {
type: 'object',
properties: {
create_account: {type: 'boolean'},
password: {type: 'string'},
password_repeat: {type: 'string'},
currency: {type: 'string'},
payment_method: {type: 'string'},
products: {type: 'array'},
voucher: {type: 'string'},
customer: {type: 'object'},
news_letter: {type: 'boolean'},
},
},
},
},
})
@inject(SecurityBindings.USER) currentUserProfile: UserProfile,
order: Omit<Order, 'id'>,
): Promise<{url: string}> {
const userId = currentUserProfile[securityId];
}
Run Code Online (Sandbox Code Playgroud)
但是,我不确定如何从会话中获取登录用户,因为我收到以下错误:
The key 'security.user' is not bound to any value in context
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何获取用户 ID?
我们目前正在将loopback3应用程序迁移到loopback4. 服务器的迁移是向前推进的,但是angular由于“sdk” ,迁移客户端似乎成为一个问题。
因为loopback3我们使用@mean-expert/loopback-sdk-builder为angular6+. 该项目似乎已终止,并且与loopback4.
loopback3以这种方式为我们生成 sdk :
服务器的 package.json:
"scripts": {
"gen-sdk": "node ./node_modules/@mean-expert/loopback-sdk-builder/bin/lb-sdk src/server.js ../frontend/src/app/shared/sdk --wipe=enabled"
}
Run Code Online (Sandbox Code Playgroud)
发电机启动服务器的副本,读取不同的内部元数据和生成的文件写入到客户端项目-据我可以看到它并没有利用的swagger.json提供loopback3。
我们正在寻找可与loopback4. 后端提供了一个openapi.json来描述端点。
您在angular项目中使用哪个 sdk (最好用 编写TypeScript)?是否有生成的代码最兼容的 sdk @mean-expert/loopback-sdk-builder?
到目前为止,我发现并测试了以下项目来生成一个 openapi 客户端:
TypeScriptloopback4?angular …
我在环回中的模型上添加了验证规则。验证工作正常,但我得到的响应消息在某种程度上是自动生成的。我需要根据验证发送自定义响应对象。
我的模型验证是 5 的乘数,如下所示
@property({
name: 'name',
description: "The product's common name.",
type: 'number',
required: true,
// Specify the JSON validation rules here
jsonSchema: {
multipleOf: 5
},
})
counter: number;
Run Code Online (Sandbox Code Playgroud)
我收到如下验证消息
{
"error": {
"statusCode": 422,
"name": "UnprocessableEntityError",
"message": "The request body is invalid. See error object `details` property for more info.",
"code": "VALIDATION_FAILED",
"details": [
{
"path": ".counter",
"code": "multipleOf",
"message": "should be multiple of 5",
"info": {
"multipleOf": 5
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我需要根据我的要求修改响应对象,我可以更新这个响应对象吗?
我对 Loopback 和 Typescript 有点陌生,所以我不知道如何实现它。我试图直接调用 Nodemailer,但到目前为止我一直收到错误。
我的邮寄服务:
import { SentMessageInfo } from 'nodemailer';
import Mail = require('nodemailer/lib/mailer');
const nodemailer = require("nodemailer");
export class MailerService {
async sendMail(mailOptions: Mail.Options): Promise<SentMessageInfo> {
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: 'albert.grimes@ethereal.email',
pass: 'qN85JT6SneBA9S5dhy'
}
});
return await transporter.sendMail(mailOptions);
}
}
Run Code Online (Sandbox Code Playgroud)
我的邮件控制器:
import { Request, RestBindings, get, ResponseObject } from
'@loopback/rest';
import { inject } from '@loopback/context';
import { MailerService } from "../services";
export class MailController {
constructor(
@inject ??? …Run Code Online (Sandbox Code Playgroud) 摘要
如何使用Loopback 4服务生成器并创建本地服务类来处理*.repository或*.controller
详细
我正在开发一个需要外部 API 来获取数据、复杂的散列/加密等不属于控制器范围或存储库范围的系统(为了干净的代码)。Loopback 4lb4 service需要生成CLI 命令,但service文档记录不足。如何在/service文件夹中创建一个类并导入(或注入或绑定或其他)并使用它的方法,就像我们对存储库所做的那样?
前任:
从服务中调用方法this.PasswordService.encrypt('some text')
或
目录this.TwitterApiService.getTweets()中定义的方法/service
在基于模式的多租户应用程序中,通常有一个具有多个模式的数据库。一种模式是存储通用应用程序数据的主要模式,一种用于应用程序的每个租户。每次有新客户注册到系统时,都会在数据库中自动创建一个新的隔离模式。这意味着,模式是在运行时创建的,并且事先不知道。客户的模式是根据客户的域命名的。当请求进入系统时,用户将得到验证并使用主模式上的数据选择模式。然后大多数/所有后续数据库操作都转到租户特定的模式。如您所见,我们要使用的模式仅在运行时才知道。
如何在运行时选择模式?我们正在使用 postgres 连接器。我们应该能够在运行时切换模式。
另一个问题是如何为不同的租户运行迁移?
db-schema 需要以请求范围的方式设置,以避免为可能属于其他客户的其他请求设置架构。为整个连接设置架构不是一个选项。
我一直无法根据对象数组中的属性查询对象。
我正在尝试查询具有 ID 为 7 的事件的所有订单:
const orders = await this.orderRepository.find({where: {events: {elemMatch: {'id': event.id}}}});
Run Code Online (Sandbox Code Playgroud)
以上给了我以下错误:
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''{\"id\":\"7\"}
Run Code Online (Sandbox Code Playgroud)
如果我尝试以下过滤器,我总是会得到一个空数组:
{where: {events: {like: '%id%'}}}
Run Code Online (Sandbox Code Playgroud)
Loopback 4 的正确方法是什么?
更新:
我正在使用 MySQL 8.0。
这是我的订单模型中事件的定义:
@property({
type: 'array',
itemType: 'object',
required: false,
})
events: CartItem[] | null;
Run Code Online (Sandbox Code Playgroud) 我们非常熟悉 IBM 的 Loopback,并且正在探索/比较 NestJS 作为替代方案。
第一个也是主要主题:一个总体上令人愉悦的功能是 Loopback 的模型内置 REST API,以及 TypeScript API 和 REST API 本身都支持的类似 GraphQL 的查询。很高兴能够包含我们喜欢的多个深度级别的相关实体,添加其他过滤和限制/范围以包含某些字段。(这给出了该功能的要点:https://loopback.io/doc/en/lb4/Include-filter.html)
这在 NestJS 世界中可能实现吗?我看到内置的 NestJS 的 RelationalQueryBuilder(https://orkhan.gitbook.io/typeorm/docs/relational-query-builder),但我没有看到它连接到内置的 REST API,它看起来其关系查询功能不太复杂。以下是 NestJS 中 CRUD REST 的一些装饰器,但没有查询支持(https://github.com/nestjsx/crud/wiki/Controllers#api-endpoints)。
此外,Loopback 中成熟的多态关系支持似乎是 Loopback 与 NestJS 中多态关系的新兴扩展的一个强大区别(https: //github.com/bashleigh/typeorm-polymorphic...谢谢 bashleigh!)。这里有什么成功/想法的意见吗?
与 NestJS 一起使用 MongoDB 效果如何(可以选择 TypeORM 或 Mongoose)?
看起来第一个功能和主要主题(内置 REST API 和流畅的查询)可能是真正让 Loopback 与众不同的。
我使用 OpenAPI 3.0.1,并使用具有类型/值验证的组件。(即类型/枚举/范围)。
当我使用错误的类型/值访问相关路径时,我会收到一条人类无法阅读的默认消息,例如:
"message": "request body has an error: doesn't match the schema: Error at <fieldName>: Doesn't match schema \"oneOf\"".
Run Code Online (Sandbox Code Playgroud)
相反,我想为每个组件创建自定义错误消息,即:
invalid argument: <fieldName>.
Run Code Online (Sandbox Code Playgroud) loopback4 ×10
loopbackjs ×5
typescript ×4
loopback ×3
openapi ×2
angular ×1
database ×1
go ×1
javascript ×1
mongodb ×1
mysql ×1
nestjs ×1
node.js ×1
relationship ×1
strongloop ×1
typeorm ×1