Ver Fonte

refactor: remove unused interfaces and services, and add MongoStatsPrismaService

- Deleted ApiResponse and OperationLogger interfaces as they were no longer needed.
- Removed ExceptionService and UtilsService implementations to streamline the codebase.
- Introduced MongoStatsPrismaService for handling MongoDB statistics.
- Updated PrismaModule to include MongoStatsPrismaService.
- Added new Prisma schemas for user login history, user session history, and user management.
Dave há 4 meses atrás
pai
commit
0cf779e6aa
57 ficheiros alterados com 86 adições e 723 exclusões
  1. 4 0
      .env.mgnt
  2. 1 6
      .env.mgnt.dev
  3. 1 0
      .env.mgnt.test
  4. 0 2
      libs/common/src/common.module.d.ts
  5. 0 55
      libs/common/src/common.module.js
  6. 0 1
      libs/common/src/common.module.js.map
  7. 0 8
      libs/common/src/config/pino.config.d.ts
  8. 0 46
      libs/common/src/config/pino.config.js
  9. 0 1
      libs/common/src/config/pino.config.js.map
  10. 0 2
      libs/common/src/crypto/aes-gcm.d.ts
  11. 0 40
      libs/common/src/crypto/aes-gcm.js
  12. 0 1
      libs/common/src/crypto/aes-gcm.js.map
  13. 0 1
      libs/common/src/decorators/auth-user.decorator.d.ts
  14. 0 9
      libs/common/src/decorators/auth-user.decorator.js
  15. 0 1
      libs/common/src/decorators/auth-user.decorator.js.map
  16. 0 10
      libs/common/src/decorators/operation-log.decorator.d.ts
  17. 0 16
      libs/common/src/decorators/operation-log.decorator.js
  18. 0 1
      libs/common/src/decorators/operation-log.decorator.js.map
  19. 0 4
      libs/common/src/dto/page-list.dto.d.ts
  20. 0 38
      libs/common/src/dto/page-list.dto.js
  21. 0 1
      libs/common/src/dto/page-list.dto.js.map
  22. 0 6
      libs/common/src/filters/http-exception.filter.d.ts
  23. 0 81
      libs/common/src/filters/http-exception.filter.js
  24. 0 0
      libs/common/src/filters/http-exception.filter.js.map
  25. 0 13
      libs/common/src/guards/rate-limit.guard.d.ts
  26. 0 89
      libs/common/src/guards/rate-limit.guard.js
  27. 0 0
      libs/common/src/guards/rate-limit.guard.js.map
  28. 0 13
      libs/common/src/interfaces/api-response.interface.d.ts
  29. 0 3
      libs/common/src/interfaces/api-response.interface.js
  30. 0 1
      libs/common/src/interfaces/api-response.interface.js.map
  31. 0 7
      libs/common/src/interfaces/operation-logger.interface.d.ts
  32. 0 5
      libs/common/src/interfaces/operation-logger.interface.js
  33. 0 1
      libs/common/src/interfaces/operation-logger.interface.js.map
  34. 0 8
      libs/common/src/services/exception.service.d.ts
  35. 0 78
      libs/common/src/services/exception.service.js
  36. 0 1
      libs/common/src/services/exception.service.js.map
  37. 0 6
      libs/db/src/prisma/mongo-prisma.service.d.ts
  38. 0 24
      libs/db/src/prisma/mongo-prisma.service.js
  39. 0 1
      libs/db/src/prisma/mongo-prisma.service.js.map
  40. 16 0
      libs/db/src/prisma/mongo-stats-prisma.service.ts
  41. 0 6
      libs/db/src/prisma/mysql-prisma.service.d.ts
  42. 0 24
      libs/db/src/prisma/mysql-prisma.service.js
  43. 0 1
      libs/db/src/prisma/mysql-prisma.service.js.map
  44. 0 2
      libs/db/src/prisma/prisma.module.d.ts
  45. 0 22
      libs/db/src/prisma/prisma.module.js
  46. 0 1
      libs/db/src/prisma/prisma.module.js.map
  47. 3 2
      libs/db/src/prisma/prisma.module.ts
  48. 0 2
      libs/db/src/shared.module.d.ts
  49. 0 25
      libs/db/src/shared.module.js
  50. 0 1
      libs/db/src/shared.module.js.map
  51. 0 7
      libs/db/src/utils.service.d.ts
  52. 0 49
      libs/db/src/utils.service.js
  53. 0 1
      libs/db/src/utils.service.js.map
  54. 11 0
      prisma/mongo_stats/schema/main.prisma
  55. 23 0
      prisma/mongo_stats/schema/user-login-history.prisma
  56. 13 0
      prisma/mongo_stats/schema/user-session-history.prisma
  57. 14 0
      prisma/mongo_stats/schema/user.prisma

+ 4 - 0
.env.mgnt

@@ -4,14 +4,18 @@ APP_ENV=test
 # Prisma Config
 # MYSQL_URL="mysql://boxdbuser:dwR%3D%29whu2Ze@localhost:3306/box_admin"
 # MONGO_URL="mongodb://boxuser:dwR%3D%29whu2Ze@localhost:27017/box_admin?authSource=admin"
+# MONGO_STATS_URL="mongodb://boxuser:dwR%3D%29whu2Ze@localhost:27017/box_stats?authSource=admin"
 
 # dave local
 MYSQL_URL="mysql://root:123456@localhost:3306/box_admin"
 MONGO_URL="mongodb://admin:ZXcv%21%21996@localhost:27017/box_admin?authSource=admin"
+MONGO_STATS_URL="mongodb://admin:ZXcv%21%21996@localhost:27017/box_stats?authSource=admin"
+
 
 # office dev env
 # MYSQL_URL="mysql://root:123456@192.168.0.100:3306/box_admin"
 # MONGO_URL="mongodb://msAdmin:Fl1%2A29MJe%26jLvj@192.168.0.100:27017/box_admin?authSource=admin&replicaSet=rs0"
+# MONGO_STATS_URL="mongodb://msAdmin:Fl1%2A29MJe%26jLvj@192.168.0.100:27017/box_stats?authSource=admin&replicaSet=rs0"
 
 # Redis Config
 REDIS_HOST=127.0.0.1

+ 1 - 6
.env.mgnt.dev

@@ -4,12 +4,7 @@ APP_ENV=development
 # Prisma Config
 MYSQL_URL="mysql://root:123456@192.168.0.100:3306/box_admin"
 MONGO_URL="mongodb://msAdmin:Fl1%2A29MJe%26jLvj@192.168.0.100:27017/box_admin?authSource=admin&replicaSet=rs0"
-
-# MYSQL_URL="mysql://root:123456@localhost:3306/box_admin"
-
-# MONGO_URL="mongodb://boxuser:dwR%3D%29whu2Ze@localhost:27017/box_admin?authSource=box_admin"
-# MONGO_URL="mongodb://admin:ZXcv%21%21996@localhost:27017/box_admin?authSource=admin"
-# MONGO_URL="mongodb://msAdmin:Fl1%2A29MJe%26jLvj@localhost:27017/box_admin?authSource=admin"
+MONGO_STATS_URL="mongodb://msAdmin:Fl1%2A29MJe%26jLvj@192.168.0.100:27017/box_stats?authSource=admin&replicaSet=rs0"
 
 # Redis Config
 REDIS_HOST=127.0.0.1

+ 1 - 0
.env.mgnt.test

@@ -4,6 +4,7 @@ APP_ENV=test
 # Prisma Config
 MYSQL_URL="mysql://boxdbuser:dwR=)whu2Ze@localhost:3306/box_admin"
 MONGO_URL="mongodb://boxuser:dwR%3D%29whu2Ze@localhost:27017/box_admin?authSource=admin"
+MONGO_STATS_URL="mongodb://boxuser:dwR%3D%29whu2Ze@localhost:27017/box_stats?authSource=admin"
 
 
 # Redis Config

+ 0 - 2
libs/common/src/common.module.d.ts

@@ -1,2 +0,0 @@
-export declare class CommonModule {
-}

+ 0 - 55
libs/common/src/common.module.js

@@ -1,55 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-var __importDefault = (this && this.__importDefault) || function (mod) {
-    return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.CommonModule = void 0;
-const common_1 = require("@nestjs/common");
-const core_1 = require("@nestjs/core");
-const nestjs_pino_1 = require("nestjs-pino");
-const pino_config_1 = __importDefault(require("./config/pino.config"));
-const http_exception_filter_1 = require("./filters/http-exception.filter");
-const logging_interceptor_1 = require("./interceptors/logging.interceptor");
-const operation_log_interceptor_1 = require("./interceptors/operation-log.interceptor");
-const response_interceptor_1 = require("./interceptors/response.interceptor");
-const correlation_interceptor_1 = require("./interceptors/correlation.interceptor");
-const exception_service_1 = require("./services/exception.service");
-let CommonModule = class CommonModule {
-};
-exports.CommonModule = CommonModule;
-exports.CommonModule = CommonModule = __decorate([
-    (0, common_1.Module)({
-        imports: [nestjs_pino_1.LoggerModule.forRoot(pino_config_1.default)],
-        providers: [
-            {
-                provide: core_1.APP_INTERCEPTOR,
-                useClass: correlation_interceptor_1.CorrelationInterceptor,
-            },
-            {
-                provide: core_1.APP_INTERCEPTOR,
-                useClass: logging_interceptor_1.LoggingInterceptor,
-            },
-            {
-                provide: core_1.APP_INTERCEPTOR,
-                useClass: operation_log_interceptor_1.OperationLogInterceptor,
-            },
-            {
-                provide: core_1.APP_INTERCEPTOR,
-                useClass: response_interceptor_1.ResponseInterceptor,
-            },
-            {
-                provide: core_1.APP_FILTER,
-                useClass: http_exception_filter_1.HttpExceptionFilter,
-            },
-            exception_service_1.ExceptionService,
-        ],
-        exports: [],
-    })
-], CommonModule);
-//# sourceMappingURL=common.module.js.map

+ 0 - 1
libs/common/src/common.module.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"common.module.js","sourceRoot":"","sources":["common.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwC;AACxC,uCAA2D;AAC3D,6CAA2C;AAC3C,uEAA8C;AAC9C,2EAAsE;AACtE,4EAAwE;AACxE,wFAAmF;AACnF,8EAA0E;AAC1E,oFAAgF;AAChF,oEAAgE;AA6BzD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IA3BxB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,0BAAY,CAAC,OAAO,CAAC,qBAAU,CAAC,CAAC;QAC3C,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,gDAAsB;aACjC;YACD;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,wCAAkB;aAC7B;YACD;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,mDAAuB;aAClC;YACD;gBACE,OAAO,EAAE,sBAAe;gBACxB,QAAQ,EAAE,0CAAmB;aAC9B;YACD;gBACE,OAAO,EAAE,iBAAU;gBACnB,QAAQ,EAAE,2CAAmB;aAC9B;YACD,oCAAgB;SACjB;QACD,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,YAAY,CAAG"}

+ 0 - 8
libs/common/src/config/pino.config.d.ts

@@ -1,8 +0,0 @@
-import pino from 'pino';
-declare const _default: {
-    pinoHttp: {
-        stream: pino.MultiStreamRes<pino.Level>;
-        autoLogging: boolean;
-    };
-};
-export default _default;

+ 0 - 46
libs/common/src/config/pino.config.js

@@ -1,46 +0,0 @@
-"use strict";
-var __importDefault = (this && this.__importDefault) || function (mod) {
-    return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-const pino_1 = __importDefault(require("pino"));
-const path_1 = require("path");
-const logDir = (0, path_1.join)(process.cwd(), 'logs');
-exports.default = {
-    pinoHttp: {
-        stream: pino_1.default.multistream([
-            pino_1.default.transport({
-                target: 'pino-pretty',
-                options: {
-                    colorize: true,
-                    translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l',
-                    ignore: 'pid,hostname,context,req,res',
-                    messageFormat: '{if context}[{context}] {end}{msg}',
-                },
-            }),
-            pino_1.default.transport({
-                target: 'pino/file',
-                options: {
-                    destination: (0, path_1.join)(logDir, 'info.log'),
-                    mkdir: true,
-                },
-                level: 'info',
-            }),
-            pino_1.default.transport({
-                target: 'pino-pretty',
-                options: {
-                    colorize: false,
-                    translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l',
-                    messageFormat: '[ERROR] [{context}] {msg}',
-                    ignore: 'pid,hostname,req,res',
-                    destination: (0, path_1.join)(logDir, 'error.log'),
-                    append: true,
-                    mkdir: true,
-                },
-                level: 'error',
-            }),
-        ]),
-        autoLogging: false,
-    },
-};
-//# sourceMappingURL=pino.config.js.map

+ 0 - 1
libs/common/src/config/pino.config.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"pino.config.js","sourceRoot":"","sources":["pino.config.ts"],"names":[],"mappings":";;;;;AACA,gDAAwB;AACxB,+BAA4B;AAE5B,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;AAE3C,kBAAe;IACb,QAAQ,EAAE;QACR,MAAM,EAAE,cAAI,CAAC,WAAW,CAAC;YAEvB,cAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;oBACd,aAAa,EAAE,2BAA2B;oBAC1C,MAAM,EAAE,8BAA8B;oBACtC,aAAa,EAAE,oCAAoC;iBACpD;aACF,CAAC;YAGF,cAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE;oBACP,WAAW,EAAE,IAAA,WAAI,EAAC,MAAM,EAAE,UAAU,CAAC;oBACrC,KAAK,EAAE,IAAI;iBACZ;gBACD,KAAK,EAAE,MAAM;aACd,CAAC;YAGF,cAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE;oBACP,QAAQ,EAAE,KAAK;oBACf,aAAa,EAAE,2BAA2B;oBAC1C,aAAa,EAAE,2BAA2B;oBAC1C,MAAM,EAAE,sBAAsB;oBAC9B,WAAW,EAAE,IAAA,WAAI,EAAC,MAAM,EAAE,WAAW,CAAC;oBACtC,MAAM,EAAE,IAAI;oBACZ,KAAK,EAAE,IAAI;iBACZ;gBACD,KAAK,EAAE,OAAO;aACf,CAAC;SACH,CAAC;QACF,WAAW,EAAE,KAAK;KACnB;CACF,CAAC"}

+ 0 - 2
libs/common/src/crypto/aes-gcm.d.ts

@@ -1,2 +0,0 @@
-export declare function aesGcmEncrypt(plaintext: string): string;
-export declare function aesGcmDecrypt(payloadB64: string): string;

+ 0 - 40
libs/common/src/crypto/aes-gcm.js

@@ -1,40 +0,0 @@
-"use strict";
-var __importDefault = (this && this.__importDefault) || function (mod) {
-    return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.aesGcmEncrypt = aesGcmEncrypt;
-exports.aesGcmDecrypt = aesGcmDecrypt;
-const crypto_1 = __importDefault(require("crypto"));
-function getKey() {
-    var _a;
-    const keyB64 = (_a = process.env.TWOFA_ENC_KEY) !== null && _a !== void 0 ? _a : '';
-    if (!keyB64) {
-        throw new Error('TWOFA_ENC_KEY is required');
-    }
-    const buf = Buffer.from(keyB64, 'base64');
-    if (buf.length !== 32) {
-        throw new Error('TWOFA_ENC_KEY must be 32 bytes when decoded from base64');
-    }
-    return buf;
-}
-function aesGcmEncrypt(plaintext) {
-    const KEY = getKey();
-    const iv = crypto_1.default.randomBytes(12);
-    const cipher = crypto_1.default.createCipheriv('aes-256-gcm', KEY, iv);
-    const enc = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
-    const tag = cipher.getAuthTag();
-    return Buffer.concat([iv, tag, enc]).toString('base64');
-}
-function aesGcmDecrypt(payloadB64) {
-    const KEY = getKey();
-    const buf = Buffer.from(payloadB64, 'base64');
-    const iv = buf.subarray(0, 12);
-    const tag = buf.subarray(12, 28);
-    const enc = buf.subarray(28);
-    const decipher = crypto_1.default.createDecipheriv('aes-256-gcm', KEY, iv);
-    decipher.setAuthTag(tag);
-    const dec = Buffer.concat([decipher.update(enc), decipher.final()]);
-    return dec.toString('utf8');
-}
-//# sourceMappingURL=aes-gcm.js.map

+ 0 - 1
libs/common/src/crypto/aes-gcm.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["aes-gcm.ts"],"names":[],"mappings":";;;;;AAcA,sCAOC;AAED,sCAUC;AAjCD,oDAA4B;AAE5B,SAAS,MAAM;;IACb,MAAM,MAAM,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,aAAa,mCAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,aAAa,CAAC,SAAiB;IAC7C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,GAAG,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,gBAAM,CAAC,cAAc,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7D,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC9E,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC1D,CAAC;AAED,SAAgB,aAAa,CAAC,UAAkB;IAC9C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9C,MAAM,EAAE,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAC7B,MAAM,QAAQ,GAAG,gBAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACjE,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACpE,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}

+ 0 - 1
libs/common/src/decorators/auth-user.decorator.d.ts

@@ -1 +0,0 @@
-export declare const AuthUser: (...dataOrPipes: any[]) => ParameterDecorator;

+ 0 - 9
libs/common/src/decorators/auth-user.decorator.js

@@ -1,9 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.AuthUser = void 0;
-const common_1 = require("@nestjs/common");
-exports.AuthUser = (0, common_1.createParamDecorator)((_data, ctx) => {
-    const req = ctx.switchToHttp().getRequest();
-    return req.user;
-});
-//# sourceMappingURL=auth-user.decorator.js.map

+ 0 - 1
libs/common/src/decorators/auth-user.decorator.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"auth-user.decorator.js","sourceRoot":"","sources":["auth-user.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AAQ3D,QAAA,QAAQ,GAAG,IAAA,6BAAoB,EAC1C,CAAC,KAAK,EAAE,GAAqB,EAAQ,EAAE;IACrC,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAwB,CAAC;IAClE,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC,CACF,CAAC"}

+ 0 - 10
libs/common/src/decorators/operation-log.decorator.d.ts

@@ -1,10 +0,0 @@
-import { OperationType } from '@prisma/mysql/client';
-export declare const OPERATION_LOG_KEY = "operationLog";
-export interface OperationLogOptions {
-    description: string;
-    type: OperationType;
-    frontendAuth: string;
-    isSaveRequest: boolean;
-    isSaveResponse: boolean;
-}
-export declare const OperationLog: (description: string, type: OperationType, frontendAuth: string, isSaveRequest?: boolean, isSaveResponse?: boolean) => import("@nestjs/common").CustomDecorator<string>;

+ 0 - 16
libs/common/src/decorators/operation-log.decorator.js

@@ -1,16 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.OperationLog = exports.OPERATION_LOG_KEY = void 0;
-const common_1 = require("@nestjs/common");
-exports.OPERATION_LOG_KEY = 'operationLog';
-const OperationLog = (description, type, frontendAuth, isSaveRequest = true, isSaveResponse = true) => {
-    return (0, common_1.SetMetadata)(exports.OPERATION_LOG_KEY, {
-        description,
-        type,
-        frontendAuth,
-        isSaveRequest,
-        isSaveResponse,
-    });
-};
-exports.OperationLog = OperationLog;
-//# sourceMappingURL=operation-log.decorator.js.map

+ 0 - 1
libs/common/src/decorators/operation-log.decorator.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"operation-log.decorator.js","sourceRoot":"","sources":["operation-log.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAGhC,QAAA,iBAAiB,GAAG,cAAc,CAAC;AAkBzC,MAAM,YAAY,GAAG,CAC1B,WAAmB,EACnB,IAAmB,EACnB,YAAoB,EACpB,aAAa,GAAG,IAAI,EACpB,cAAc,GAAG,IAAI,EACrB,EAAE;IACF,OAAO,IAAA,oBAAW,EAAC,yBAAiB,EAAE;QACpC,WAAW;QACX,IAAI;QACJ,YAAY;QACZ,aAAa;QACb,cAAc;KACQ,CAAC,CAAC;AAC5B,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB"}

+ 0 - 4
libs/common/src/dto/page-list.dto.d.ts

@@ -1,4 +0,0 @@
-export declare class PageListDto {
-    page: number;
-    size: number;
-}

+ 0 - 38
libs/common/src/dto/page-list.dto.js

@@ -1,38 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-var __metadata = (this && this.__metadata) || function (k, v) {
-    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.PageListDto = void 0;
-const swagger_1 = require("@nestjs/swagger");
-const class_validator_1 = require("class-validator");
-class PageListDto {
-}
-exports.PageListDto = PageListDto;
-__decorate([
-    (0, swagger_1.ApiProperty)({
-        description: 'Page number (starts from 1)',
-        example: 1,
-        default: 1,
-    }),
-    (0, class_validator_1.IsInt)(),
-    (0, class_validator_1.Min)(1),
-    __metadata("design:type", Number)
-], PageListDto.prototype, "page", void 0);
-__decorate([
-    (0, swagger_1.ApiProperty)({
-        description: 'Number of records per page',
-        example: 10,
-        default: 10,
-    }),
-    (0, class_validator_1.IsInt)(),
-    (0, class_validator_1.Min)(1),
-    __metadata("design:type", Number)
-], PageListDto.prototype, "size", void 0);
-//# sourceMappingURL=page-list.dto.js.map

+ 0 - 1
libs/common/src/dto/page-list.dto.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"page-list.dto.js","sourceRoot":"","sources":["page-list.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA8C;AAC9C,qDAA6C;AAE7C,MAAa,WAAW;CAkBvB;AAlBD,kCAkBC;AAVC;IAPC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,6BAA6B;QAC1C,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX,CAAC;IACD,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;yCACM;AASb;IAPC,IAAA,qBAAW,EAAC;QACX,WAAW,EAAE,4BAA4B;QACzC,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACZ,CAAC;IACD,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;yCACM"}

+ 0 - 6
libs/common/src/filters/http-exception.filter.d.ts

@@ -1,6 +0,0 @@
-import { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
-export declare class HttpExceptionFilter implements ExceptionFilter {
-    private readonly logger;
-    catch(exception: unknown, host: ArgumentsHost): void;
-    private mapStatusToCode;
-}

+ 0 - 81
libs/common/src/filters/http-exception.filter.js

@@ -1,81 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-var HttpExceptionFilter_1;
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.HttpExceptionFilter = void 0;
-const common_1 = require("@nestjs/common");
-let HttpExceptionFilter = HttpExceptionFilter_1 = class HttpExceptionFilter {
-    constructor() {
-        this.logger = new common_1.Logger(HttpExceptionFilter_1.name);
-    }
-    catch(exception, host) {
-        const ctx = host.switchToHttp();
-        const response = ctx.getResponse();
-        const request = ctx.getRequest();
-        const status = exception instanceof common_1.HttpException
-            ? exception.getStatus()
-            : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
-        const exceptionResponse = exception instanceof common_1.HttpException ? exception.getResponse() : null;
-        let message;
-        let code;
-        if (typeof exceptionResponse === 'object' && exceptionResponse !== null) {
-            const responseObj = exceptionResponse;
-            if (Array.isArray(responseObj.message)) {
-                message = responseObj.message.join(', ');
-            }
-            else if (typeof responseObj.message === 'string') {
-                message = responseObj.message;
-            }
-            else {
-                message = exception.message || 'Unknown error';
-            }
-            code = responseObj.code || this.mapStatusToCode(status);
-        }
-        else {
-            message =
-                exception instanceof Error
-                    ? exception.message
-                    : 'Internal server error';
-            code = this.mapStatusToCode(status);
-        }
-        const apiResponse = {
-            error: message,
-            status: 0,
-            code,
-            data: null,
-            timestamp: new Date().toISOString(),
-        };
-        if (status >= 500) {
-            this.logger.error(`${request.method} ${request.url} - ${status} - ${message}`, exception instanceof Error ? exception.stack : undefined);
-        }
-        else {
-            this.logger.warn(`${request.method} ${request.url} - ${status} - ${message}`);
-        }
-        response.status(200).send(apiResponse);
-    }
-    mapStatusToCode(status) {
-        const codeMap = {
-            400: 'BAD_REQUEST',
-            401: 'UNAUTHORIZED',
-            403: 'FORBIDDEN',
-            404: 'NOT_FOUND',
-            409: 'CONFLICT',
-            422: 'UNPROCESSABLE_ENTITY',
-            429: 'RATE_LIMITED',
-            500: 'INTERNAL_ERROR',
-            502: 'BAD_GATEWAY',
-            503: 'SERVICE_UNAVAILABLE',
-        };
-        return codeMap[status] || `HTTP_${status}`;
-    }
-};
-exports.HttpExceptionFilter = HttpExceptionFilter;
-exports.HttpExceptionFilter = HttpExceptionFilter = HttpExceptionFilter_1 = __decorate([
-    (0, common_1.Catch)()
-], HttpExceptionFilter);
-//# sourceMappingURL=http-exception.filter.js.map

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
libs/common/src/filters/http-exception.filter.js.map


+ 0 - 13
libs/common/src/guards/rate-limit.guard.d.ts

@@ -1,13 +0,0 @@
-import { CanActivate, ExecutionContext } from '@nestjs/common';
-export declare class RateLimitGuard implements CanActivate {
-    private readonly logger;
-    private readonly buckets;
-    private readonly limit;
-    private readonly windowMs;
-    private readonly cleanupInterval;
-    constructor();
-    canActivate(context: ExecutionContext): boolean;
-    private getClientIp;
-    private cleanup;
-    onModuleDestroy(): void;
-}

+ 0 - 89
libs/common/src/guards/rate-limit.guard.js

@@ -1,89 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-var __metadata = (this && this.__metadata) || function (k, v) {
-    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
-};
-var RateLimitGuard_1;
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.RateLimitGuard = void 0;
-const common_1 = require("@nestjs/common");
-let RateLimitGuard = RateLimitGuard_1 = class RateLimitGuard {
-    constructor() {
-        this.logger = new common_1.Logger(RateLimitGuard_1.name);
-        this.buckets = new Map();
-        this.limit = 10;
-        this.windowMs = 60000;
-        this.cleanupInterval = setInterval(() => {
-            this.cleanup();
-        }, 5 * 60000);
-    }
-    canActivate(context) {
-        const request = context.switchToHttp().getRequest();
-        const ip = this.getClientIp(request);
-        const endpoint = `${request.method}:${request.url.split('?')[0]}`;
-        const key = `${ip}:${endpoint}`;
-        const now = Date.now();
-        let bucket = this.buckets.get(key);
-        if (!bucket || now > bucket.resetAt) {
-            bucket = {
-                count: 1,
-                resetAt: now + this.windowMs,
-            };
-            this.buckets.set(key, bucket);
-            return true;
-        }
-        bucket.count++;
-        if (bucket.count > this.limit) {
-            const retryAfter = Math.ceil((bucket.resetAt - now) / 1000);
-            this.logger.warn(`Rate limit exceeded for ${ip} on ${endpoint} (${bucket.count}/${this.limit})`);
-            throw new common_1.HttpException({
-                statusCode: 429,
-                message: `Too many requests. Please try again in ${retryAfter} seconds.`,
-                code: 'RATE_LIMITED',
-                retryAfter,
-            }, common_1.HttpStatus.TOO_MANY_REQUESTS);
-        }
-        return true;
-    }
-    getClientIp(request) {
-        const forwardedFor = request.headers['x-forwarded-for'];
-        if (forwardedFor) {
-            const ips = Array.isArray(forwardedFor) ? forwardedFor[0] : forwardedFor;
-            return ips.split(',')[0].trim();
-        }
-        const realIp = request.headers['x-real-ip'];
-        if (realIp) {
-            return Array.isArray(realIp) ? realIp[0] : realIp;
-        }
-        return request.ip || 'unknown';
-    }
-    cleanup() {
-        const now = Date.now();
-        let cleaned = 0;
-        for (const [key, bucket] of this.buckets.entries()) {
-            if (now > bucket.resetAt) {
-                this.buckets.delete(key);
-                cleaned++;
-            }
-        }
-        if (cleaned > 0) {
-            this.logger.debug(`Cleaned up ${cleaned} expired rate limit buckets`);
-        }
-    }
-    onModuleDestroy() {
-        if (this.cleanupInterval) {
-            clearInterval(this.cleanupInterval);
-        }
-    }
-};
-exports.RateLimitGuard = RateLimitGuard;
-exports.RateLimitGuard = RateLimitGuard = RateLimitGuard_1 = __decorate([
-    (0, common_1.Injectable)(),
-    __metadata("design:paramtypes", [])
-], RateLimitGuard);
-//# sourceMappingURL=rate-limit.guard.js.map

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
libs/common/src/guards/rate-limit.guard.js.map


+ 0 - 13
libs/common/src/interfaces/api-response.interface.d.ts

@@ -1,13 +0,0 @@
-export interface ApiResponse<T = unknown> {
-    error: string;
-    status: 1 | 0;
-    code: string;
-    data: T;
-    timestamp: string;
-}
-export interface PaginatedApiResponse<T = unknown> extends ApiResponse<T[]> {
-    data: T[];
-    total: number;
-    page: number;
-    size: number;
-}

+ 0 - 3
libs/common/src/interfaces/api-response.interface.js

@@ -1,3 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-//# sourceMappingURL=api-response.interface.js.map

+ 0 - 1
libs/common/src/interfaces/api-response.interface.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"api-response.interface.js","sourceRoot":"","sources":["api-response.interface.ts"],"names":[],"mappings":""}

+ 0 - 7
libs/common/src/interfaces/operation-logger.interface.d.ts

@@ -1,7 +0,0 @@
-import type { FastifyRequest } from 'fastify';
-import type { OperationLogOptions } from '../decorators/operation-log.decorator';
-import type { ApiResponse } from './api-response.interface';
-export interface IOperationLogger {
-    createLog(req: FastifyRequest, options: OperationLogOptions, data: ApiResponse<unknown>, callMethod: string, status: boolean): Promise<void>;
-}
-export declare const OPERATION_LOGGER: unique symbol;

+ 0 - 5
libs/common/src/interfaces/operation-logger.interface.js

@@ -1,5 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.OPERATION_LOGGER = void 0;
-exports.OPERATION_LOGGER = Symbol('OPERATION_LOGGER');
-//# sourceMappingURL=operation-logger.interface.js.map

+ 0 - 1
libs/common/src/interfaces/operation-logger.interface.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"operation-logger.interface.js","sourceRoot":"","sources":["operation-logger.interface.ts"],"names":[],"mappings":";;;AAkBa,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}

+ 0 - 8
libs/common/src/services/exception.service.d.ts

@@ -1,8 +0,0 @@
-import { ApiResponse } from '../interfaces/api-response.interface';
-export declare class ExceptionService {
-    getHttpResponse(exception: unknown): ApiResponse<null>;
-    private handleHttpException;
-    private isClassValidatorException;
-    private handleUnknownException;
-    private getExceptionCode;
-}

+ 0 - 78
libs/common/src/services/exception.service.js

@@ -1,78 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.ExceptionService = void 0;
-const common_1 = require("@nestjs/common");
-const class_validator_1 = require("class-validator");
-let ExceptionService = class ExceptionService {
-    getHttpResponse(exception) {
-        let message;
-        let code = 'INTERNAL_ERROR';
-        if (exception instanceof common_1.HttpException) {
-            message = this.handleHttpException(exception);
-            code = this.getExceptionCode(exception);
-        }
-        else {
-            message = this.handleUnknownException(exception);
-        }
-        return {
-            error: message,
-            status: 0,
-            code,
-            data: null,
-            timestamp: new Date().toISOString(),
-        };
-    }
-    handleHttpException(exception) {
-        if (this.isClassValidatorException(exception)) {
-            const exceptionResponse = exception.getResponse();
-            return exceptionResponse.message.join(', ');
-        }
-        else {
-            return exception.message;
-        }
-    }
-    isClassValidatorException(exception) {
-        if (!(exception instanceof common_1.BadRequestException))
-            return false;
-        const exceptionResponse = exception.getResponse();
-        return (typeof exceptionResponse === 'object' &&
-            'message' in exceptionResponse &&
-            (0, class_validator_1.isArray)(exceptionResponse.message));
-    }
-    handleUnknownException(exception) {
-        return exception instanceof Error
-            ? exception.message
-            : 'Internal server error';
-    }
-    getExceptionCode(exception) {
-        const status = exception.getStatus();
-        const response = exception.getResponse();
-        if (typeof response === 'object' &&
-            response !== null &&
-            'code' in response) {
-            return response.code;
-        }
-        const codeMap = {
-            400: 'BAD_REQUEST',
-            401: 'UNAUTHORIZED',
-            403: 'FORBIDDEN',
-            404: 'NOT_FOUND',
-            409: 'CONFLICT',
-            422: 'UNPROCESSABLE_ENTITY',
-            429: 'RATE_LIMITED',
-            500: 'INTERNAL_ERROR',
-        };
-        return codeMap[status] || `HTTP_${status}`;
-    }
-};
-exports.ExceptionService = ExceptionService;
-exports.ExceptionService = ExceptionService = __decorate([
-    (0, common_1.Injectable)()
-], ExceptionService);
-//# sourceMappingURL=exception.service.js.map

+ 0 - 1
libs/common/src/services/exception.service.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"exception.service.js","sourceRoot":"","sources":["exception.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAKwB;AACxB,qDAA0C;AAInC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,eAAe,CAAC,SAAkB;QAChC,IAAI,OAAe,CAAC;QACpB,IAAI,IAAI,GAAG,gBAAgB,CAAC;QAE5B,IAAI,SAAS,YAAY,sBAAa,EAAE,CAAC;YACvC,OAAO,GAAG,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAC9C,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;QACnD,CAAC;QAED,OAAO;YACL,KAAK,EAAE,OAAO;YACd,MAAM,EAAE,CAAC;YACT,IAAI;YACJ,IAAI,EAAE,IAAI;YACV,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC;IACJ,CAAC;IAEO,mBAAmB,CAAC,SAAwB;QAClD,IAAI,IAAI,CAAC,yBAAyB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9C,MAAM,iBAAiB,GAAG,SAAS,CAAC,WAAW,EAE9C,CAAC;YACF,OAAO,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC,OAAO,CAAC;QAC3B,CAAC;IACH,CAAC;IAEO,yBAAyB,CAAC,SAAwB;QACxD,IAAI,CAAC,CAAC,SAAS,YAAY,4BAAmB,CAAC;YAAE,OAAO,KAAK,CAAC;QAE9D,MAAM,iBAAiB,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAClD,OAAO,CACL,OAAO,iBAAiB,KAAK,QAAQ;YACrC,SAAS,IAAI,iBAAiB;YAC9B,IAAA,yBAAO,EAAC,iBAAiB,CAAC,OAAO,CAAC,CACnC,CAAC;IACJ,CAAC;IAEO,sBAAsB,CAAC,SAAkB;QAC/C,OAAO,SAAS,YAAY,KAAK;YAC/B,CAAC,CAAC,SAAS,CAAC,OAAO;YACnB,CAAC,CAAC,uBAAuB,CAAC;IAC9B,CAAC;IAEO,gBAAgB,CAAC,SAAwB;QAC/C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAGzC,IACE,OAAO,QAAQ,KAAK,QAAQ;YAC5B,QAAQ,KAAK,IAAI;YACjB,MAAM,IAAI,QAAQ,EAClB,CAAC;YACD,OAAQ,QAAgB,CAAC,IAAI,CAAC;QAChC,CAAC;QAGD,MAAM,OAAO,GAA2B;YACtC,GAAG,EAAE,aAAa;YAClB,GAAG,EAAE,cAAc;YACnB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,WAAW;YAChB,GAAG,EAAE,UAAU;YACf,GAAG,EAAE,sBAAsB;YAC3B,GAAG,EAAE,cAAc;YACnB,GAAG,EAAE,gBAAgB;SACtB,CAAC;QAEF,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,QAAQ,MAAM,EAAE,CAAC;IAC7C,CAAC;CACF,CAAA;AA5EY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CA4E5B"}

+ 0 - 6
libs/db/src/prisma/mongo-prisma.service.d.ts

@@ -1,6 +0,0 @@
-import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
-import { PrismaClient as MongoPrismaClient } from '@prisma/mongo/client';
-export declare class MongoPrismaService extends MongoPrismaClient implements OnModuleInit, OnModuleDestroy {
-    onModuleInit(): Promise<void>;
-    onModuleDestroy(): Promise<void>;
-}

+ 0 - 24
libs/db/src/prisma/mongo-prisma.service.js

@@ -1,24 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.MongoPrismaService = void 0;
-const common_1 = require("@nestjs/common");
-const client_1 = require("@prisma/mongo/client");
-let MongoPrismaService = class MongoPrismaService extends client_1.PrismaClient {
-    async onModuleInit() {
-        await this.$connect();
-    }
-    async onModuleDestroy() {
-        await this.$disconnect();
-    }
-};
-exports.MongoPrismaService = MongoPrismaService;
-exports.MongoPrismaService = MongoPrismaService = __decorate([
-    (0, common_1.Injectable)()
-], MongoPrismaService);
-//# sourceMappingURL=mongo-prisma.service.js.map

+ 0 - 1
libs/db/src/prisma/mongo-prisma.service.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"mongo-prisma.service.js","sourceRoot":"","sources":["mongo-prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,iDAAyE;AAGlE,IAAM,kBAAkB,GAAxB,MAAM,kBACX,SAAQ,qBAAiB;IAGzB,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAXY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAW9B"}

+ 16 - 0
libs/db/src/prisma/mongo-stats-prisma.service.ts

@@ -0,0 +1,16 @@
+import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
+import { PrismaClient as MongoPrismaClient } from '@prisma/mongo/client';
+
+@Injectable()
+export class MongoStatsPrismaService
+  extends MongoPrismaClient
+  implements OnModuleInit, OnModuleDestroy
+{
+  async onModuleInit() {
+    await this.$connect();
+  }
+
+  async onModuleDestroy() {
+    await this.$disconnect();
+  }
+}

+ 0 - 6
libs/db/src/prisma/mysql-prisma.service.d.ts

@@ -1,6 +0,0 @@
-import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
-import { PrismaClient as MysqlPrismaClient } from '@prisma/mysql/client';
-export declare class MysqlPrismaService extends MysqlPrismaClient implements OnModuleInit, OnModuleDestroy {
-    onModuleInit(): Promise<void>;
-    onModuleDestroy(): Promise<void>;
-}

+ 0 - 24
libs/db/src/prisma/mysql-prisma.service.js

@@ -1,24 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.MysqlPrismaService = void 0;
-const common_1 = require("@nestjs/common");
-const client_1 = require("@prisma/mysql/client");
-let MysqlPrismaService = class MysqlPrismaService extends client_1.PrismaClient {
-    async onModuleInit() {
-        await this.$connect();
-    }
-    async onModuleDestroy() {
-        await this.$disconnect();
-    }
-};
-exports.MysqlPrismaService = MysqlPrismaService;
-exports.MysqlPrismaService = MysqlPrismaService = __decorate([
-    (0, common_1.Injectable)()
-], MysqlPrismaService);
-//# sourceMappingURL=mysql-prisma.service.js.map

+ 0 - 1
libs/db/src/prisma/mysql-prisma.service.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"mysql-prisma.service.js","sourceRoot":"","sources":["mysql-prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAC3E,iDAAyE;AAGlE,IAAM,kBAAkB,GAAxB,MAAM,kBACX,SAAQ,qBAAiB;IAGzB,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AAXY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CAW9B"}

+ 0 - 2
libs/db/src/prisma/prisma.module.d.ts

@@ -1,2 +0,0 @@
-export declare class PrismaModule {
-}

+ 0 - 22
libs/db/src/prisma/prisma.module.js

@@ -1,22 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.PrismaModule = void 0;
-const common_1 = require("@nestjs/common");
-const mongo_prisma_service_1 = require("./mongo-prisma.service");
-const mysql_prisma_service_1 = require("./mysql-prisma.service");
-let PrismaModule = class PrismaModule {
-};
-exports.PrismaModule = PrismaModule;
-exports.PrismaModule = PrismaModule = __decorate([
-    (0, common_1.Module)({
-        providers: [mysql_prisma_service_1.MysqlPrismaService, mongo_prisma_service_1.MongoPrismaService],
-        exports: [mysql_prisma_service_1.MysqlPrismaService, mongo_prisma_service_1.MongoPrismaService],
-    })
-], PrismaModule);
-//# sourceMappingURL=prisma.module.js.map

+ 0 - 1
libs/db/src/prisma/prisma.module.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["prisma.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AAExC,iEAA4D;AAC5D,iEAA4D;AAMrD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IAJxB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,yCAAkB,EAAE,yCAAkB,CAAC;QACnD,OAAO,EAAE,CAAC,yCAAkB,EAAE,yCAAkB,CAAC;KAClD,CAAC;GACW,YAAY,CAAG"}

+ 3 - 2
libs/db/src/prisma/prisma.module.ts

@@ -1,10 +1,11 @@
 import { Module } from '@nestjs/common';
 
 import { MongoPrismaService } from './mongo-prisma.service';
+import { MongoStatsPrismaService } from './mongo-stats-prisma.service';
 import { MysqlPrismaService } from './mysql-prisma.service';
 
 @Module({
-  providers: [MysqlPrismaService, MongoPrismaService],
-  exports: [MysqlPrismaService, MongoPrismaService],
+  providers: [MysqlPrismaService, MongoPrismaService, MongoStatsPrismaService],
+  exports: [MysqlPrismaService, MongoPrismaService, MongoStatsPrismaService],
 })
 export class PrismaModule {}

+ 0 - 2
libs/db/src/shared.module.d.ts

@@ -1,2 +0,0 @@
-export declare class SharedModule {
-}

+ 0 - 25
libs/db/src/shared.module.js

@@ -1,25 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.SharedModule = void 0;
-const axios_1 = require("@nestjs/axios");
-const common_1 = require("@nestjs/common");
-const utils_service_1 = require("./utils.service");
-const prisma_module_1 = require("./prisma/prisma.module");
-let SharedModule = class SharedModule {
-};
-exports.SharedModule = SharedModule;
-exports.SharedModule = SharedModule = __decorate([
-    (0, common_1.Global)(),
-    (0, common_1.Module)({
-        imports: [prisma_module_1.PrismaModule, axios_1.HttpModule],
-        providers: [utils_service_1.UtilsService],
-        exports: [prisma_module_1.PrismaModule, axios_1.HttpModule, utils_service_1.UtilsService],
-    })
-], SharedModule);
-//# sourceMappingURL=shared.module.js.map

+ 0 - 1
libs/db/src/shared.module.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"shared.module.js","sourceRoot":"","sources":["shared.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yCAA2C;AAC3C,2CAAgD;AAChD,mDAA+C;AAC/C,0DAAsD;AAQ/C,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IANxB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,EAAE,kBAAU,CAAC;QACnC,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,EAAE,kBAAU,EAAE,4BAAY,CAAC;KAClD,CAAC;GACW,YAAY,CAAG"}

+ 0 - 7
libs/db/src/utils.service.d.ts

@@ -1,7 +0,0 @@
-import type { FastifyRequest } from 'fastify';
-export declare class UtilsService {
-    private qqwry;
-    getRealIp(req: FastifyRequest): string;
-    getIpRegion(ip: string): string;
-    getMd5(str: string): string;
-}

+ 0 - 49
libs/db/src/utils.service.js

@@ -1,49 +0,0 @@
-"use strict";
-var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
-    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
-    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
-    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
-    return c > 3 && r && Object.defineProperty(target, key, r), r;
-};
-var __importDefault = (this && this.__importDefault) || function (mod) {
-    return (mod && mod.__esModule) ? mod : { "default": mod };
-};
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.UtilsService = void 0;
-const common_1 = require("@nestjs/common");
-const crypto_1 = __importDefault(require("crypto"));
-const lib_qqwry_1 = __importDefault(require("lib-qqwry"));
-const lodash_1 = require("lodash");
-let UtilsService = class UtilsService {
-    constructor() {
-        this.qqwry = new lib_qqwry_1.default(true);
-    }
-    getRealIp(req) {
-        let clientIp = req.headers['x-forwarded-for'] || req.ip;
-        if ((0, lodash_1.isArray)(clientIp)) {
-            clientIp = clientIp[0];
-        }
-        clientIp = clientIp.split(',')[0];
-        return clientIp;
-    }
-    getIpRegion(ip) {
-        if (ip == null) {
-            return;
-        }
-        try {
-            const result = this.qqwry.searchIP(ip);
-            return result.Country;
-        }
-        catch (err) {
-            return '未知地区';
-        }
-    }
-    getMd5(str) {
-        return crypto_1.default.createHash('md5').update(str).digest('hex');
-    }
-};
-exports.UtilsService = UtilsService;
-exports.UtilsService = UtilsService = __decorate([
-    (0, common_1.Injectable)()
-], UtilsService);
-//# sourceMappingURL=utils.service.js.map

+ 0 - 1
libs/db/src/utils.service.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"utils.service.js","sourceRoot":"","sources":["utils.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,oDAA4B;AAE5B,0DAA8B;AAC9B,mCAAiC;AAG1B,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;QACG,UAAK,GAAG,IAAI,mBAAK,CAAC,IAAI,CAAC,CAAC;IA0BlC,CAAC;IAxBC,SAAS,CAAC,GAAmB;QAC3B,IAAI,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QACxD,IAAI,IAAA,gBAAO,EAAC,QAAQ,CAAC,EAAE,CAAC;YACtB,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;QACD,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,WAAW,CAAC,EAAU;QACpB,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QACD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YACvC,OAAO,MAAM,CAAC,OAAO,CAAC;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;CACF,CAAA;AA3BY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;GACA,YAAY,CA2BxB"}

+ 11 - 0
prisma/mongo_stats/schema/main.prisma

@@ -0,0 +1,11 @@
+// prisma/mongo/schema/main.schema
+generator client {
+  provider        = "prisma-client-js"
+  output          = "./../../../node_modules/@prisma/mongo/client"
+  previewFeatures = ["prismaSchemaFolder"]
+}
+
+datasource db {
+  provider = "mongodb"
+  url      = env("MONGO_STATS_URL")
+}

+ 23 - 0
prisma/mongo_stats/schema/user-login-history.prisma

@@ -0,0 +1,23 @@
+model UserLoginHistory {
+  id          String   @id @map("_id") @default(auto()) @db.ObjectId
+  
+  uid         String                          // 设备码
+  ip          String                          // 登录 IP
+  userAgent   String?                         // UA (optional but useful)
+  appVersion  String?                         // 客户端版本 (optional)
+  os          String?                         // iOS / Android / Browser
+
+  createAt    BigInt                          // 登录时间 (epoch)
+  
+  // Queries you will use a lot:
+  // 1. 查某设备所有登录记录
+  @@index([uid, createAt])
+  
+  // 2. 查某 IP 的登陆情况(反刷)
+  @@index([ip, createAt])
+  
+  // 3. 全局统计(按时间分片)
+  @@index([createAt])
+
+  @@map("userLoginHistory")
+}

+ 13 - 0
prisma/mongo_stats/schema/user-session-history.prisma

@@ -0,0 +1,13 @@
+model UserSessionHistory {
+  id          String   @id @map("_id") @default(auto()) @db.ObjectId
+
+  uid         String
+  ip          String
+  tokenId     String
+  startAt     BigInt
+  endAt       BigInt   @default(0)
+
+  @@index([uid, startAt])
+  @@index([tokenId])
+  @@map("userSessionHistory")
+}

+ 14 - 0
prisma/mongo_stats/schema/user.prisma

@@ -0,0 +1,14 @@
+model User {
+  id            String     @id @map("_id") @default(auto()) @db.ObjectId
+  uid           String     @unique          // 唯一设备码
+  ip            String                      // 最近登录 IP
+
+  createAt      BigInt     @default(0)      // 注册/创建时间
+  lastLoginAt   BigInt     @default(0)      // 最后登录时间
+
+  // create index on uid field for search
+  @@index([uid])
+  @@index([createAt])
+
+  @@map("user")
+}

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff