Coder Social home page Coder Social logo

.save() never returns about typegoose HOT 3 CLOSED

szokodiakos avatar szokodiakos commented on July 20, 2024
.save() never returns

from typegoose.

Comments (3)

szokodiakos avatar szokodiakos commented on July 20, 2024

Hello

This is actually a feature and this isn't about Typegoose but it's how Mongoose's API works.

Mongoose supports both callback and Promise interface. Since you are using async/await meaning you .then on the operation in the behind scenes the callback gets ignored.

If you want to use the callback style, remove the async/await keywords from the code and it should be fine.

from typegoose.

roeibh avatar roeibh commented on July 20, 2024

Thanks for the answer.
I've changed the code to work with async-await and now the code looks something like this:

user.model.ts:

public static async addUser(email: string, password: string, username: string, name?: string): Promise<User> {
        password = await hash(password, { type: argon2id });
        const user: User = new User();
        user.email = email;
        user.name = name;
        user.password = password;
        user.username = username;
        await Model.create(user);
        return user;
    }

users.route.ts:

const user: User = await User.addUser(req.body.email, req.body.password, req.body.username, req.body.name);

it worked!

from typegoose.

vinczedani avatar vinczedani commented on July 20, 2024

Hi @roeibh
Since you said that the above solution worked, I close the issue.
If you have any new question feel free to create a new issue.
Cheers,
Daniel

from typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.