#File organization

3 messages · Page 1 of 1 (latest)

mild spindle
#

So this is how im organising my services files, insted of placing all route logic into one auth.service.ts file, i decided to place all route login to their separate file so this is what my module structure:

So is this a valid way to organise? or there some another ways to achieve this?

auth/ -> Dir
 services/ -> Dir
  sign-in.service.ts
  sign-up.service.ts
 auth.controller.ts
 auth.module.ts
import { Body, Controller, Post } from '@nestjs/common';
import { SignUpService } from './services/sign-up.service';
import { SignUpDto } from './dtos/sign-up.dto';
import { SignInService } from './services/sign-in.service';

@Controller('auth')
export class AuthController {
  constructor(
    private readonly signUpService: SignUpService,
    private readonly signInService: SignInService,
    // Other services for each routes
  ) {}

  @Post('sign-up')
  async signUp(@Body() dto: SignUpDto): Promise<unknown> {
    return this.signUpService.signUp(dto);
  }

  @Post('sign-in')
  async signIn(): Promise<unknown> {
    return this.signInService.signIn();
  }
}

viscid basalt
#

So is this a valid way to organise?
I mean, it's valid to even put everything in a single directory and not split things up, not recommended, but valid. Mainly just pointing out that "valid" might not be what you're looking for here.

But yeah, it's a fine way to go about splitting up your services further.

lavish crow