emilsoftware-utilities 1.3.143 → 1.3.145

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,19 +11,39 @@ exports.EmilsoftwareModule = void 0;
11
11
  const common_1 = require("@nestjs/common");
12
12
  const AccessiModule_1 = require("./accessi-module/AccessiModule");
13
13
  const AllegatiModule_1 = require("./allegati-module/AllegatiModule");
14
+ const Logger_1 = require("./Logger");
14
15
  /**
15
16
  * Unified module that combines user access management (Accessi) and file attachment management (Allegati)
16
17
  * into a single NestJS module with shared Swagger documentation
17
18
  */
18
19
  let EmilsoftwareModule = EmilsoftwareModule_1 = class EmilsoftwareModule {
19
20
  static forRoot(options) {
21
+ const logger = new Logger_1.Logger(EmilsoftwareModule_1.name);
22
+ let imports = [];
23
+ let exports = [];
24
+ if (!options) {
25
+ throw new Error("EmilsoftwareModule requires valid accessiOptions and allegatiOptions");
26
+ }
27
+ if (options.accessiOptions) {
28
+ logger.info("Initializing AccessiModule with provided options.");
29
+ imports.push(AccessiModule_1.AccessiModule.forRoot(options.accessiOptions));
30
+ exports.push(AccessiModule_1.AccessiModule);
31
+ }
32
+ else {
33
+ logger.warning("Accessi options are not provided. AccessiModule will not be initialized.");
34
+ }
35
+ if (options.allegatiOptions) {
36
+ logger.info("Initializing AllegatiModule with provided options.");
37
+ imports.push(AllegatiModule_1.AllegatiModule.forRoot(options.allegatiOptions));
38
+ exports.push(AllegatiModule_1.AllegatiModule);
39
+ }
40
+ else {
41
+ logger.warning("Allegati options are not provided. AllegatiModule will not be initialized.");
42
+ }
20
43
  return {
21
44
  module: EmilsoftwareModule_1,
22
- imports: [
23
- AccessiModule_1.AccessiModule.forRoot(options.accessiOptions),
24
- AllegatiModule_1.AllegatiModule.forRoot(options.allegatiOptions),
25
- ],
26
- exports: [AccessiModule_1.AccessiModule, AllegatiModule_1.AllegatiModule],
45
+ imports,
46
+ exports
27
47
  };
28
48
  }
29
49
  };
package/dist/Logger.js CHANGED
@@ -93,7 +93,6 @@ class Logger {
93
93
  ],
94
94
  levels: {
95
95
  error: 1,
96
- warn: 2,
97
96
  warning: 2,
98
97
  info: 3,
99
98
  http: 4,
@@ -185,6 +184,9 @@ class Logger {
185
184
  case LogLevels.DEBUG:
186
185
  console.debug((0, colorette_1.magenta)(`[DEBUG][${now}][${fileName}]`), logEntry.message);
187
186
  break;
187
+ case LogLevels.WARNING:
188
+ console.debug((0, colorette_1.yellow)(`[WARNING][${now}][${fileName}]`), logEntry.message);
189
+ break;
188
190
  case LogLevels.LOG:
189
191
  console.log((0, colorette_1.cyan)(`[LOG][${now}][${fileName}]`), logEntry.message);
190
192
  break;
@@ -11,7 +11,7 @@ export declare class UserController {
11
11
  private readonly logger;
12
12
  constructor(userService: UserService, emailService: EmailService, options: AccessiOptions);
13
13
  serveResetPasswordPage(res: Response, token: string): Promise<void>;
14
- getUsers(res: Response): Promise<Response<any, Record<string, any>>>;
14
+ getUsers(res: Response, email?: string): Promise<Response<any, Record<string, any>>>;
15
15
  deleteUser(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
16
16
  register(request: Request, registrationData: RegisterRequest, res: Response): Promise<Response<any, Record<string, any>>>;
17
17
  updateUtente(codiceUtente: number, user: UserDto, res: Response): Promise<Response<any, Record<string, any>>>;
@@ -46,10 +46,10 @@ let UserController = UserController_1 = class UserController {
46
46
  return res.sendFile((0, path_1.join)(__dirname, '..', 'Views', 'reset-password.html'));
47
47
  });
48
48
  }
49
- getUsers(res) {
49
+ getUsers(res, email) {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  try {
52
- const users = yield this.userService.getUsers();
52
+ const users = yield this.userService.getUsers(email);
53
53
  return Utilities_1.RestUtilities.sendBaseResponse(res, users);
54
54
  }
55
55
  catch (error) {
@@ -127,8 +127,9 @@ __decorate([
127
127
  (0, swagger_1.ApiResponse)({ status: 401, description: 'Credenziali non valide' }),
128
128
  (0, common_1.Get)('get-users'),
129
129
  __param(0, (0, common_1.Res)()),
130
+ __param(1, (0, common_1.Query)('email')),
130
131
  __metadata("design:type", Function),
131
- __metadata("design:paramtypes", [Object]),
132
+ __metadata("design:paramtypes", [Object, String]),
132
133
  __metadata("design:returntype", Promise)
133
134
  ], UserController.prototype, "getUsers", null);
134
135
  __decorate([
@@ -10,7 +10,7 @@ export declare class UserService {
10
10
  private readonly emailService;
11
11
  private readonly permissionService;
12
12
  constructor(accessiOptions: AccessiOptions, emailService: EmailService, permissionService: PermissionService);
13
- getUsers(): Promise<GetUsersResult[]>;
13
+ getUsers(email?: string): Promise<GetUsersResult[]>;
14
14
  getCodiceUtenteByEmail(email: string): Promise<{
15
15
  codiceUtente: number;
16
16
  }>;
@@ -35,10 +35,10 @@ let UserService = class UserService {
35
35
  this.emailService = emailService;
36
36
  this.permissionService = permissionService;
37
37
  }
38
- getUsers() {
38
+ getUsers(email) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  try {
41
- const query = `
41
+ let query = `
42
42
  SELECT
43
43
  U.CODUTE as codice_utente,
44
44
  U.USRNAME as email,
@@ -66,10 +66,17 @@ let UserService = class UserService {
66
66
  F.CODCLIENTI AS codice_clienti,
67
67
  F.TIPFIL AS tip_fil
68
68
  FROM UTENTI U
69
- INNER JOIN UTENTI_CONFIG G ON U.CODUTE = G.CODUTE
69
+ WHERE 1=1
70
+ `;
71
+ let queryParams = [];
72
+ if (email) {
73
+ query += ` AND LOWER(U.USRNAME) = ? `;
74
+ queryParams.push(email.trim().toLowerCase());
75
+ }
76
+ query += `INNER JOIN UTENTI_CONFIG G ON U.CODUTE = G.CODUTE
70
77
  LEFT JOIN FILTRI F ON F.CODUTE = U.CODUTE
71
78
  ORDER BY U.CODUTE`;
72
- let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query);
79
+ let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams);
73
80
  users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
74
81
  let usersResponse = [];
75
82
  for (const user of users) {
@@ -127,7 +127,18 @@
127
127
  const urlParams = new URLSearchParams(window.location.search);
128
128
  const token = window.location.pathname.split("/").pop();
129
129
  const returnUrl = urlParams.get("returnUrl") || "/";
130
- const prefix = urlParams.get("prefix") || "";
130
+ let prefix = urlParams.get("prefix") || "";
131
+
132
+ if (prefix !== "") {
133
+ if (!prefix.startsWith("/")) {
134
+ prefix = "/" + prefix;
135
+ }
136
+
137
+ if(prefix.endsWith("/")) {
138
+ prefix = prefix.slice(0, -1);
139
+ }
140
+ }
141
+
131
142
 
132
143
  document.getElementById("token").value = token;
133
144
  document.getElementById("returnUrl").value = returnUrl;
@@ -181,4 +192,4 @@
181
192
  </script>
182
193
  </body>
183
194
 
184
- </html>
195
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.3.143",
3
+ "version": "1.3.145",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "build": "tsc && npm run copy-views",
11
11
  "copy-views": "node copy-views.js",
12
12
  "prepublishOnly": "npm run build",
13
- "test:allegati": "ts-node src/tests/allegati/allegati.ts"
13
+ "test:allegati": "ts-node src/tests/allegati/allegati.ts",
14
+ "test:accessi": "npm run build && ts-node test/index.js"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",