diff --git a/api/nest-cli.json b/api/nest-cli.json index a808b8dc..b20d4e39 100644 --- a/api/nest-cli.json +++ b/api/nest-cli.json @@ -3,5 +3,6 @@ "collection": "@nestjs/schematics", "compilerOptions": { "deleteOutDir": true - } + }, + "entryFile": "api/src/main" } diff --git a/api/package.json b/api/package.json index 91ff8a84..21ce6993 100644 --- a/api/package.json +++ b/api/package.json @@ -11,7 +11,7 @@ "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", + "start:prod": "node dist/api/src/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest --config ./test/jest-config.json -i --detectOpenHandles" }, @@ -24,7 +24,8 @@ "pg": "^8.12.0", "reflect-metadata": "^0.2.0", "rxjs": "^7.8.1", - "typeorm": "^0.3.20" + "typeorm": "catalog:", + "class-transformer": "catalog:" }, "devDependencies": { "@nestjs/cli": "^10.0.0", diff --git a/api/src/modules/config/app-config.module.ts b/api/src/modules/config/app-config.module.ts index b1cf89c5..9fb05ac5 100644 --- a/api/src/modules/config/app-config.module.ts +++ b/api/src/modules/config/app-config.module.ts @@ -14,12 +14,13 @@ import { DatabaseModule } from '@api/modules/config/database/database.module'; ConfigModule.forRoot({ isGlobal: true, cache: true, + // TODO: This is a bit ugly, we should find a way to make this more elegant envFilePath: [ join( __dirname, - `../../../../shared/config/.env.${process.env.NODE_ENV}`, + `../../../../../../shared/config/.env.${process.env.NODE_ENV}`, ), - join(__dirname, '../../../../shared/config/.env'), + join(__dirname, '../../../../../../shared/config/.env'), ], }), ], diff --git a/api/src/modules/config/app-config.service.ts b/api/src/modules/config/app-config.service.ts index 2e560a0b..b69e6fd9 100644 --- a/api/src/modules/config/app-config.service.ts +++ b/api/src/modules/config/app-config.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { join } from 'path'; +import { DATABASE_ENTITIES } from '@shared/entities/database.entities'; @Injectable() export class ApiConfigService { @@ -9,6 +9,8 @@ export class ApiConfigService { /** * @note We could abstract this to a data layer access config specific class within database module, as well for other configs when the thing gets more complex. * we could also abstract the underlying engine type, which is now set in the main app module + * + * @note: Maybe it's a good idea to move the datasource config to shared folder, to be used potentially for a e2e test agent */ getDatabaseConfig() { return { @@ -17,7 +19,7 @@ export class ApiConfigService { username: this.configService.get('DB_USERNAME'), password: this.configService.get('DB_PASSWORD'), database: this.configService.get('DB_NAME'), - entities: [join(__dirname, '**', '*.entity.{ts,js}')], + entities: DATABASE_ENTITIES, synchronize: true, ssl: this.isProduction() ? { require: true, rejectUnauthorized: false } diff --git a/api/src/modules/users/users.module.ts b/api/src/modules/users/users.module.ts new file mode 100644 index 00000000..44f028e3 --- /dev/null +++ b/api/src/modules/users/users.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { UsersService } from './users.service'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { User } from '@shared/entities/users/user.entity'; + +@Module({ + imports: [TypeOrmModule.forFeature([User])], + providers: [UsersService], +}) +export class UsersModule {} diff --git a/api/src/modules/users/users.service.ts b/api/src/modules/users/users.service.ts new file mode 100644 index 00000000..ef0d82d2 --- /dev/null +++ b/api/src/modules/users/users.service.ts @@ -0,0 +1,4 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class UsersService {} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 405115cb..efd3f6d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,9 @@ settings: catalogs: default: + class-transformer: + specifier: ^0.5.1 + version: 0.5.1 pg: specifier: ^8.12.0 version: 8.12.0 @@ -24,19 +27,22 @@ importers: dependencies: '@nestjs/common': specifier: ^10.0.0 - version: 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) + version: 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) '@nestjs/config': specifier: ^3.2.3 - version: 3.2.3(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1) + version: 3.2.3(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1) '@nestjs/core': specifier: ^10.0.0 - version: 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + version: 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) '@nestjs/platform-express': specifier: ^10.0.0 - version: 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) + version: 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) '@nestjs/typeorm': specifier: ^10.0.2 - version: 10.0.2(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(reflect-metadata@0.2.2)(rxjs@7.8.1)(typeorm@0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4))) + version: 10.0.2(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(reflect-metadata@0.2.2)(rxjs@7.8.1)(typeorm@0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4))) + class-transformer: + specifier: 'catalog:' + version: 0.5.1 pg: specifier: ^8.12.0 version: 8.12.0 @@ -47,7 +53,7 @@ importers: specifier: ^7.8.1 version: 7.8.1 typeorm: - specifier: ^0.3.20 + specifier: 'catalog:' version: 0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4)) devDependencies: '@nestjs/cli': @@ -58,7 +64,7 @@ importers: version: 10.1.4(chokidar@3.6.0)(typescript@5.5.4) '@nestjs/testing': specifier: ^10.0.0 - version: 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1)) + version: 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1)) '@types/express': specifier: ^4.17.17 version: 4.17.21 @@ -152,6 +158,10 @@ importers: version: 5.5.4 shared: + dependencies: + class-transformer: + specifier: 'catalog:' + version: 0.5.1 devDependencies: pg: specifier: 'catalog:' @@ -1295,6 +1305,9 @@ packages: cjs-module-lexer@1.4.0: resolution: {integrity: sha512-N1NGmowPlGBLsOZLPvm48StN04V4YvQRL0i6b7ctrVY3epjP/ct7hFLOItz6pDIvRjwpfPxi52a2UWV2ziir8g==} + class-transformer@0.5.1: + resolution: {integrity: sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==} + cli-cursor@3.1.0: resolution: {integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==} engines: {node: '>=8'} @@ -4351,25 +4364,27 @@ snapshots: - uglify-js - webpack-cli - '@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1)': + '@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1)': dependencies: iterare: 1.2.1 reflect-metadata: 0.2.2 rxjs: 7.8.1 tslib: 2.6.3 uid: 2.0.2 + optionalDependencies: + class-transformer: 0.5.1 - '@nestjs/config@3.2.3(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1)': + '@nestjs/config@3.2.3(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(rxjs@7.8.1)': dependencies: - '@nestjs/common': 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) dotenv: 16.4.5 dotenv-expand: 10.0.0 lodash: 4.17.21 rxjs: 7.8.1 - '@nestjs/core@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1)': + '@nestjs/core@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1)': dependencies: - '@nestjs/common': 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) '@nuxtjs/opencollective': 0.3.2 fast-safe-stringify: 2.1.1 iterare: 1.2.1 @@ -4379,14 +4394,14 @@ snapshots: tslib: 2.6.3 uid: 2.0.2 optionalDependencies: - '@nestjs/platform-express': 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) + '@nestjs/platform-express': 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) transitivePeerDependencies: - encoding - '@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1)': + '@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1)': dependencies: - '@nestjs/common': 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) - '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) body-parser: 1.20.2 cors: 2.8.5 express: 4.19.2 @@ -4417,18 +4432,18 @@ snapshots: transitivePeerDependencies: - chokidar - '@nestjs/testing@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1))': + '@nestjs/testing@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1))': dependencies: - '@nestjs/common': 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) - '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) tslib: 2.6.3 optionalDependencies: - '@nestjs/platform-express': 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) + '@nestjs/platform-express': 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1) - '@nestjs/typeorm@10.0.2(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(reflect-metadata@0.2.2)(rxjs@7.8.1)(typeorm@0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4)))': + '@nestjs/typeorm@10.0.2(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/core@10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(reflect-metadata@0.2.2)(rxjs@7.8.1)(typeorm@0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4)))': dependencies: - '@nestjs/common': 10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1) - '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/common': 10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) + '@nestjs/core': 10.4.1(@nestjs/common@10.4.1(class-transformer@0.5.1)(reflect-metadata@0.2.2)(rxjs@7.8.1))(@nestjs/platform-express@10.4.1)(reflect-metadata@0.2.2)(rxjs@7.8.1) reflect-metadata: 0.2.2 rxjs: 7.8.1 typeorm: 0.3.20(pg@8.12.0)(ts-node@10.9.2(@types/node@20.16.5)(typescript@5.5.4)) @@ -5261,6 +5276,8 @@ snapshots: cjs-module-lexer@1.4.0: {} + class-transformer@0.5.1: {} + cli-cursor@3.1.0: dependencies: restore-cursor: 3.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index cb2ff508..47c110cc 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -7,4 +7,5 @@ packages: catalog: pg: "^8.12.0" typeorm: "^0.3.20" - zod: "^3.23.8" \ No newline at end of file + zod: "^3.23.8" + class-transformer: "^0.5.1" \ No newline at end of file diff --git a/shared/entities/database.entities.ts b/shared/entities/database.entities.ts new file mode 100644 index 00000000..8fe7e67e --- /dev/null +++ b/shared/entities/database.entities.ts @@ -0,0 +1,3 @@ +import { User } from "@shared/entities/users/user.entity"; + +export const DATABASE_ENTITIES = [User]; diff --git a/shared/entities/users/user.entity.ts b/shared/entities/users/user.entity.ts new file mode 100644 index 00000000..b62a9ee2 --- /dev/null +++ b/shared/entities/users/user.entity.ts @@ -0,0 +1,24 @@ +import { + Column, + CreateDateColumn, + Entity, + OneToMany, + PrimaryGeneratedColumn, +} from "typeorm"; +import { Exclude } from "class-transformer"; + +@Entity({ name: "users" }) +export class User { + @PrimaryGeneratedColumn("uuid") + id: string; + + @Column({ unique: true }) + email: string; + + @Column() + @Exclude() + password: string; + + @CreateDateColumn({ name: "created_at" }) + createdAt: Date; +} diff --git a/shared/package.json b/shared/package.json index 3f3cb7bd..be9a6248 100644 --- a/shared/package.json +++ b/shared/package.json @@ -5,5 +5,8 @@ "pg": "catalog:", "typeorm": "catalog:", "zod": "catalog:" + }, + "dependencies": { + "class-transformer": "catalog:" } }