Giter Club home page Giter Club logo

Comments (2)

santiq avatar santiq commented on July 21, 2024

Sure.
This project is written in typescript, so

public async SignUp(userInputDTO: IUserInputDTO): Promise<{ user: IUser; token: string }> {
...
}

There we are using typescript to type the response of the function, which will be Promise where it holds a value that is an object with the shape of { user, token }

In plain javascript would be something similar to this

async SignUp(userInputDTO) {
 ...
};

======

Here we are using Mongoose, which is a node.js package to connect to Mongodb and an ODM

export default mongoose.model<IUser & mongoose.Document>('User', User);

The part where we are using <> is called Generics it is used to give a Type to the result of the database's results.

Then the IUser & mongoose.Document is telling that the results of the databases will be an object which type is the Intersection of the interface IUser and the interface mongoose.Document

In practice, the mongoose.Document means that the result will have the property _id and all of the properties of the interface IUser

======

This is a little trickier

 export default ({ mongoConnection, models }: { mongoConnection; models: { name: string; model: any }[] })

We are exporting an object, which has this shape: { mongoConnection, models }
but also defining the type on the same line with the : operator.
since models is an array of objects, I'm saying that each object of the array will have the shape { name: string, model: any}

from bulletproof-nodejs.

ssow avatar ssow commented on July 21, 2024

Very kind of you and cristal clear.
May i ask you a last explanation regarding the following type declaration and the purpose of the Models namespace please ?

namespace Models {
export type UserModel = Model<IUser & Document>;
}

Thank you.

from bulletproof-nodejs.

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.