创建新用户将忽略来自 create-user.dto.ts
但是,当我更新用户时,它会添加不需要的字段,如下所示:
// update-user.dto.ts
import { IsEmail } from 'class-validator';
import { Address } from '../model/address';
export class UpdateUserDto {
firstName: string;
lastName: string;
@IsEmail(undefined, { message: 'Not a valid e-mail' })
email: string;
username: string;
password: string;
addresses: Address[];
}
Run Code Online (Sandbox Code Playgroud)
这是来自用户服务的更新操作
// user.service.ts
async update(data: UpdateUserDto) {
try {
this.logger.log(data);
const id = '5c6dd9852d4f441638c2df86';
const user = await this.userRepository.update(id, data);
return { message: 'Updated your information' };
} catch (error) {
this.logger.log(error);
throw new HttpException('', HttpStatus.INTERNAL_SERVER_ERROR);
}
} …Run Code Online (Sandbox Code Playgroud) 使用时
@UseInterceptors(ClassSerializerInterceptor)
Run Code Online (Sandbox Code Playgroud)
就像这里的文档中所解释的那样
我得到了所需的过滤结果,但是在使用 mongodb 时,id 被格式化_bsontype而不是string像以前那样没有拦截器的正常格式,如下所示:
{
"id": {
"_bsontype": "ObjectID",
"id": {
"0": 92,
"1": 108,
"2": 182,
"3": 85,
"4": 185,
"5": 20,
"6": 221,
"7": 12,
"8": 56,
"9": 66,
"10": 131,
"11": 172
}
},
"createdAt": "2019-02-20T02:07:17.895Z",
"updatedAt": "2019-02-20T02:07:17.895Z",
"firstName": "The First Name",
"lastName": "The Last Name",
"email": "giberish@gmail.com"
}
Run Code Online (Sandbox Code Playgroud)
如何将其转换回像这样的普通 id 字符串?
{
"id": "5c6cb655b914dd0c384283ac",
"createdAt": "2019-02-20T02:07:17.895Z",
"updatedAt": "2019-02-20T02:07:17.895Z",
"firstName": "The First Name",
"lastName": "The Last Name",
"email": …Run Code Online (Sandbox Code Playgroud) 我试过使用
userRepository.find({
where: [
{
email: 'giberish@gmail.com',
},
{
username: 'thisismyusername',
},
]
});
Run Code Online (Sandbox Code Playgroud)
就像 typeorm 文档中解释的那样,但我收到此错误:
errmsg:
'Error getting filter : Error getting filter BSON field from doc = [{find user} {filter [[{email giberish@gmail.com}] [{username thisismyusername}]]} {returnKey false} {showRecordId false} {$clusterTime [{clusterTime 6660127540193001473} {signature [{hash [184 253 193 112 111 39 205 239 38 92 178 205 149 85 131 136 252 114 180 30]} {keyId 6637077103550398465}]}]}] : not bson []interface {} [[{email craftball@gmail.com}] [{username thisismyusername}]]\n\tat erh/mongonet/bsonutil.go:122\n\tat 10gen/atlasproxy/bson_util.go:32\n\tat 10gen/atlasproxy/commands_security.go:521\n\tat …Run Code Online (Sandbox Code Playgroud) 我在 Chrome 和 Firefox 中运行相同的 Anuglar (mat-table) html。Chrome 有一个滚动条来滚动表格单元格,而 Firefox 则重叠文本
<td
style="
min-width: 160px;
max-width: 400px;
text-overflow: clip;
overflow: hidden;
overflow-x: scroll;
white-space: nowrap;
"
mat-cell
*matCellDef="let element"
>
Run Code Online (Sandbox Code Playgroud)