小编ade*_*ola的帖子

您如何检测 typeorm 中的密码等属性是否已更改

在 typeorm 中,我试图在持久化到数据库之前使用订阅者装饰器来散列用户密码。不幸的是,我在文档中找不到参考。

在 sequelizejs 中,我使用以下代码,

User.hashPassword = (user, options) => {
    if (!user.changed('password')) {
      return null;
    }
    // hash password
    return Bcrypt.hash(user.get('password'), SALT_ROUNDS)
      .then(hash => user.set('password', hash));
  };
Run Code Online (Sandbox Code Playgroud)

现在,我正在尝试将代码迁移到typeorm,我的翻译大致是

@BeforeInsert()
@BeforeUpdate()
hashPassword() {
    // conditional to detect if password has changed goes here
    this.password = bcrypt.hashSync(this.password, SALT_ROUNDS);
}
Run Code Online (Sandbox Code Playgroud)

问题是,我停留在!user.changed('password'). 是否有等效的功能可以在typeorm不推出我自己的解决方案的情况下执行此操作?

javascript node.js typeorm nestjs

6
推荐指数
1
解决办法
5647
查看次数

如何将值从组件传递到Formik多步骤表单向导?

正如标题所说。我有一个基于文档react-bootstrap-typeaheadFormik多步骤向导示例的无状态组件和一个表单向导。

但是,我无法将从typeahead组件获得的值传递给formik。我无法访问setFieldValue

    const FormElements = setFieldValue => (
        <Wizard
          initialValues={FORM_VALUES}
          onSubmit={(values, actions) => {
            sleep(300).then(() => {
              window.alert(JSON.stringify(values, null, 2));
              actions.setSubmitting(false);
            });
          }}
        >
          <Wizard.Page>
            <GoogleMapsPlaceLookup
              value={location => {
                console.log("I got the value correctly from my child: ", location);
              }}
            />
          </Wizard.Page>
        </Wizard>
    );

    export default FormElements;
Run Code Online (Sandbox Code Playgroud)

我如何将此值注入其中Formik,以便可以对其进行处理onSubmit。任何指针或帮助将不胜感激。谢谢

reactjs react-bootstrap-typeahead formik

3
推荐指数
1
解决办法
3380
查看次数

Nestjs - 控制器中定义的路由相互覆盖

我有一个控制器

//imports etc
...

@Get('me')
async get(@Req res): Promise<UserVm> {
    // extract auth user from request object
    // return auth user
}

@Get(':id') // uuid
async get(@Param('id') id: string): Promise<UserSummaryVm> {
    // return a summary user profile
}
...
Run Code Online (Sandbox Code Playgroud)

然而,/:id是压倒性的/me。我尝试重新排序路线但无济于事。我总是收到以下错误:

[Nest] 94764   - 8/23/2018, 7:45:50 PM   [ExceptionsHandler] Could not find 
any entity of type "User" matching: "me"
EntityNotFound: Could not find any entity of type "User" matching: "me"
at new EntityNotFoundError
([PROJECT_ROOT]\src\error\EntityNotFoundError.ts:11:9)
at [PROJECT_ROOT]\src\entity-manager\EntityManager.ts:622:39
at process._tickCallback …
Run Code Online (Sandbox Code Playgroud)

nestjs

2
推荐指数
1
解决办法
3363
查看次数