Skip to content

Commit

Permalink
Merge pull request #9 from liglig99/lib-structure
Browse files Browse the repository at this point in the history
lib
  • Loading branch information
liglig99 authored May 5, 2024
2 parents bd93e95 + 8e71f02 commit aca83e7
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

#expo
frontend/.expo/
11 changes: 11 additions & 0 deletions apps/auth/src/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ import { jwtConstants } from './auth.constants';
import { MongooseModule } from '@nestjs/mongoose';
import { UsersService } from './users/users.service';
import { UserSchema } from './users/users.schema';
import { LoggerModule } from '@app/common';
import { ConfigModule } from '@nestjs/config';
import * as Joi from 'joi';

@Module({
imports: [
LoggerModule,
UsersModule,
JwtModule.register({
global: true,
secret: jwtConstants.secret,
signOptions: { expiresIn: '60s' },
}),
ConfigModule.forRoot({
isGlobal: true,
validationSchema: Joi.object({
MONGODB_URI: Joi.string().default('mongodb://admin:secret@mongodb/'),
MONGODB_DATABASE: Joi.string().default('auth'),
}),
}),
MongooseModule.forRoot(
'mongodb://admin:secret@mongodb/auth?authSource=admin',
),
Expand Down
2 changes: 2 additions & 0 deletions apps/auth/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { AuthModule } from './auth.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
Expand All @@ -12,6 +13,7 @@ async function bootstrap() {
},
},
);
app.useLogger(app.get(Logger));

await app.listen();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SignInDto } from 'apps/auth/src/dto/sign-in.dto';
import { CreateUserDto } from 'apps/auth/src/dto/create-user.dto';
import { ClientProxy } from '@nestjs/microservices';
import { Observable, tap } from 'rxjs';
import { Public } from '@app/common/lib/auth.guard';
import { Public } from '@app/common';
import { Response, Request } from 'express';

@Controller('auth')
Expand Down
4 changes: 3 additions & 1 deletion apps/gateway/src/gateway.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { ClientsModule, Transport } from '@nestjs/microservices';
import { JwtModule } from '@nestjs/jwt';
import { jwtConstants } from 'apps/auth/src/auth.constants';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from '@app/common/lib/auth.guard';
import { WorkoutsController } from './workouts.controller';
import { AuthGuard } from '@app/common';
import { LoggerModule } from '@app/common';

@Module({
imports: [
LoggerModule,
ClientsModule.register([
{
name: 'AUTH_SERVICE',
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions apps/gateway/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
} from '@nestjs/common';
import { ExpressAdapter } from '@nestjs/platform-express';
import { GatewayModule } from './gateway.module';
import { AllGlobalExceptionsFilter } from '@app/common/lib/global-exception-filter';
import { AllGlobalExceptionsFilter } from './global-exception-filter';
import * as cookieParser from 'cookie-parser';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
const app: INestApplication & INestMicroservice = await NestFactory.create(
Expand All @@ -18,7 +19,7 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalFilters(new AllGlobalExceptionsFilter());
app.use(cookieParser());

app.useLogger(app.get(Logger));
await app.listen(3000);
}
bootstrap();
2 changes: 1 addition & 1 deletion apps/gateway/src/workouts.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Body, Controller, Get, Inject, Post, Query } from '@nestjs/common';
import { GatewayService } from './gateway.service';
import { ClientProxy } from '@nestjs/microservices';
import { Public } from '@app/common/lib/auth.guard';
import { Public } from '@app/common';
import { CreateExcerciseDto } from 'apps/workouts/src/dto/create-excercise.dto';
import { CreateWorkoutDto } from 'apps/workouts/src/dto/create-workout.dto';
import { CreateWorkoutLogDto } from 'apps/workouts/src/dto/create-workout-log.dto';
Expand Down
17 changes: 0 additions & 17 deletions libs/common/src/database/abstract.repository.ts

This file was deleted.

8 changes: 0 additions & 8 deletions libs/common/src/database/abstract.schema.ts

This file was deleted.

19 changes: 0 additions & 19 deletions libs/common/src/database/database.module.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/common/src/database/index.ts

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions libs/common/src/guards/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './auth.guard';
3 changes: 2 additions & 1 deletion libs/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './database';
export * from './guards';
export * from './logger';
1 change: 1 addition & 0 deletions libs/common/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './logger.module';
18 changes: 18 additions & 0 deletions libs/common/src/logger/logger.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Module } from '@nestjs/common';
import { LoggerModule as PinoLoggerModule } from 'nestjs-pino';

@Module({
imports: [
PinoLoggerModule.forRoot({
pinoHttp: {
transport: {
target: 'pino-pretty',
options: {
singleLine: true,
},
},
},
}),
],
})
export class LoggerModule {}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@
"class-validator": "^0.14.1",
"cookie-parser": "^1.4.6",
"express": "^4.19.2",
"joi": "^17.13.1",
"mongoose": "^8.2.4",
"nestjs-pino": "^4.0.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pino-http": "^9.0.0",
"pino-pretty": "^11.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
Expand All @@ -49,6 +53,7 @@
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/joi": "^17.2.3",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand Down
Loading

0 comments on commit aca83e7

Please sign in to comment.