Created
March 27, 2025 18:28
-
-
Save Vatsalya-singhi/678a46a36ce3203b3c638930ba0a1376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Users Service (Provides Business Logic) | |
import { Injectable } from '@nestjs/common'; | |
// injectables include wide range of configurations such as when and how to initialise the provider | |
@Injectable() | |
export class UsersService { | |
private users = ['Alice', 'Bob', 'Charlie']; | |
findAll(): string[] { | |
return this.users; | |
} | |
} | |
// Users Controller (Depends on UsersService) | |
import { Controller, Get } from '@nestjs/common'; | |
import { UsersService } from './users.service'; | |
@Controller('users') | |
export class UsersController { | |
constructor(private readonly usersService: UsersService) {} // Dependency Injection | |
@Get() | |
findAll(): string[] { | |
return this.usersService.findAll(); // Uses service to get data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment