class-transformer#plainToClassFromExist TypeScript Examples

The following examples show how to use class-transformer#plainToClassFromExist. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user-repository.ts    From malagu with MIT License 6 votes vote down vote up
@Transactional()
    async update(user: User): Promise<User> {
        const repo = OrmContext.getRepository(User);
        const oldUser = await repo.findOne(user.id);
        if (oldUser) {
            const newUser = plainToClassFromExist(oldUser, classToPlain(user));
            return repo.save(newUser);
        }
        throw new UserNotFoundError(user.id);
    }