#Newbie on NestJS Framework
108 messages · Page 1 of 1 (latest)
Okay. Thanks. But its very hard to seperate the Frontend and Backend yes? While in Laravel u have Standard the Auth in there
Why is it hard to separate the front end and back end
What about auth?
NestJS is a Node framework. It exists entirely on the server. You can use whatever front end you want, they're unrelated. Hell, you could write a front end using web assemply or an iOS/Android app.
I don't understand what the "like:..." part is here
like what i must do for moduless. iodk
A module is a collection of compenents that create a feature, in my opinion. You have things like providers (services, configurations to be injected, possibly global enhancer bindings), controllers, how you can call to the module from outside the server, imports, other features that this feature requires, and exports, how you expose providers to other modules
How much of the documentation have you read and tried to follow along with?
Have you actually started coding anything, or is it all conceptual knowledge right now?
mostly all! and i dont understand the module thing
Okay, what about Nest's use of the term "modules" confuses you?
How can I help clarify it
I am having a hard time determining what is a module and what is not at this time?
As described above, I plan to build a restaurant application. Which should allow customers to request restaurants, which ones I accept or reject in the admin area, etc. For this we need a user, auth, admin area, customer area etc. How does this work? What would you say? Restaurants (is e.g. restaurant a module? a restaurant also has products that can be ordered later, as well as categories e.g. (salads - chicken salad))
Can u make a list, what for modules are correct here? like
Can u make a list, what for modules are correct here?
I canmake a list of what modules I would create. Technically, a Nest application only needs one module to function. However, separation of concerns makes life easier in the long run
So, it seems like you'd really have two modules here: a User/AuthModule and a RestaurantMoudle.
- The admin area is inside of the
RestaurantModuleand makes use of theUser/AuthModuleto ensure that only the admin can access and modify that data. - The
User/AuthModuleis in charge of allowing users to signup and sign-in, which should probably return the user's type as well on sign in/authenticate, so that you can properly protect the admin endpoints inside theRestaurantMoudle.
Does that make sense to you?
Is this the right way? Idk.. Like in laravel i have a Module in there is a controller for admin and user area..
and then policies etc.
and in there i can use all models
like user, etc.
You could make an admin module if you want to, but it really is going to depend on how you want to set up your admin endpoint(s)
It all comes out to how you architect your server
yep.. wait i show u one thing rn wait
what my question answers
This is like i have in laravel
and i cant build that so or?
the structure
only
very clean and organized
Why can't you build that?
Nest doesn'trestrict your file structure or anything like that
You can put whatever you want wherever you want
but the dtos i have seen in typescript with nest not like mine how i use it
Sure, it's opinionated, but that doesn't mean it's restrictive
I dunno PHP or Laravel at all, so I dunno what to say. You're entering a different language, there's gonna be differences
yepp
ok i test arround with it!
thx to yu
If you have specific questions about how to connect the modules or things of the like, I'll be happy to answer that. Most of the time when it comes to creating/determining modules people will have differing opinions depending on how they want to approach things so it's hard to give more definitive answers
Sure, i will come back to this then! Give me a little 😄 to create and test arround
did u have a nice and clean typescript code style file?
is gts not a code style fixer? https://github.com/google/gts
ye orr
Oh god, gts. I've got mixed feeliings on that as, to my knowledge, it doesn't have an integrated IDE plugin and has to be ran separately and can change your files from there. I'm used to linters changing things, but it was superannoying how it parses things out.
I usually just stick with the stock eslint config that Nest provides on nest new. Maybe add in a few rules here or there as necessary
eslint nice 🙂
yee
and first of all all what i code make a test for or? like i have only made ín php for all controllers a test. what u prefere? also all services etc.?=
or no testing
on which app?
Any of them. It's a bunch of testing examples
So @austere totem like, now is this plan correct?
- in
Usercreate a AuthModule for the Auth of Users. RestaurantModule and in there a Admin Module and Customer Module?
or how u mean?
You could make a customer and admin module within the restaurant module, or you could just have the endpoints mixed and have proper authentication on the admin ones. It's really up to you
ok
What's hard? What's hard about it? What habe you tried? Where are you stuck?
i stuck on start i created a new nestjs application
idk how to start
generated a module
What have you tried?
Stop overthinking
? 😦
Start with simple, build the functionality, re-evaluate and refactor as complexity grows
So generally, generate the module, generate the controller and service, add in the business logic
But is auth in User? or under the restaurant?
That's your decision. Where does it make sense to add auth? My opinion is it's its own feature
How about you do this, because my answer will almost always be "what works best for you?": Try implementing it how your gut initially feels is right, and then evaluate it.. See if it will scale and if not refactor.
can u say me a project which i can make to learn? like say me something and i build and show here to get better
@austere totem
The linked repository is an excellent list of curated resources for NestJS.
It includes various resources such as modules, examples, articles, and tools that can be useful for developers using NestJS.
The repository aims to provide a one-stop solution for developers exploring the NestJS ecosystem and leveraging its features to build robust and scalable applications.
these are all examples of repos that could help
@hazy pulsar - You want to try that again? What you've written makes no sense at all.
idk why so much like here https://github.com/CatsMiaow/nestjs-project-structure/tree/master/src (auth) is random in src folder?
why not in admin or so
makes for me no sense
You're focusing too much on structure and not enough on the logic. If you want to put it under admin that's fine. Don't do like everyone else just because that's your they still do it; experiment, learn why that's the way people do it
bro wait a problem now
i created a role decorator
and a guard
so i used
@Get()
@Roles(['admin'])
getAllTasks() {
return {
message: 'This action returns all tasks',
};
}
why dont work?
@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
console.log('RolesGuard');
const roles = this.reflector.get('roles', context.getHandler());
if (!roles) {
return true;
}
const request = context.switchToHttp().getRequest();
const user = request.user;
const hasRole = () => user.roles.some((role) => roles.includes(role));
return user && user.roles && hasRole();
}
}