Skip to content

Commit

Permalink
feat: ✨ add @shared/infrastructure-mongoose
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Nov 18, 2024
1 parent c13db02 commit 0187f40
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ USER_PORT=15001
TASK_HOST=localhost
TASK_PORT=15002

DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306
DATABASE_HOST=localhost
DATABASE_PORT=27017
DATABASE_NAME=product_a_main
7 changes: 7 additions & 0 deletions libs/shared/infrastructure/mongoose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# shared-infrastructure-mongoose

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test shared-infrastructure-mongoose` to execute the unit tests via [Jest](https://jestjs.io).
3 changes: 3 additions & 0 deletions libs/shared/infrastructure/mongoose/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../../../eslint.config.js');

module.exports = [...baseConfig];
10 changes: 10 additions & 0 deletions libs/shared/infrastructure/mongoose/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'shared-infrastructure-mongoose',
preset: '../../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../../coverage/libs/shared/infrastructure/mongoose',
};
9 changes: 9 additions & 0 deletions libs/shared/infrastructure/mongoose/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "shared-infrastructure-mongoose",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/shared/infrastructure/mongoose/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project shared-infrastructure-mongoose --web",
"targets": {}
}
1 change: 1 addition & 0 deletions libs/shared/infrastructure/mongoose/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/database.module';
21 changes: 21 additions & 0 deletions libs/shared/infrastructure/mongoose/src/lib/database.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [
MongooseModule.forRootAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const databaseConfig = configService.get('database');
return {
// uri: `mongodb://${databaseConfig.host}:${databaseConfig.port}`,
uri: `mongodb://localhost:27017`,
// dbName: databaseConfig.name,
};
},
}),
],
exports: [MongooseModule],
})
export class DatabaseModule {}
22 changes: 22 additions & 0 deletions libs/shared/infrastructure/mongoose/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions libs/shared/infrastructure/mongoose/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
14 changes: 14 additions & 0 deletions libs/shared/infrastructure/mongoose/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.7",
"@nestjs/graphql": "^12.2.1",
"@nestjs/mongoose": "^10.1.0",
"@nestjs/platform-express": "^10.4.7",
"axios": "^1.7.7",
"graphql": "^16.9.0",
"graphql-tools": "^9.0.2",
"inlineTrace": "link:@apollo/server/plugin/inlineTrace",
"mongoose": "^8.8.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"zod": "^3.23.8"
Expand Down
Loading

0 comments on commit 0187f40

Please sign in to comment.