@ejfdelgado/ejflab-back 1.28.0 → 1.30.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.28.0",
3
+ "version": "1.30.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -8,6 +8,7 @@ export class PostgresSrv {
8
8
  static pool = null;
9
9
  static {
10
10
  PostgresSrv.renderer.registerFunction("noQuotes", PostgresSrv.noQuotes);
11
+ PostgresSrv.renderer.registerFunction("singleWord", PostgresSrv.singleWord);
11
12
  PostgresSrv.renderer.registerFunction("sanitizeNumber", PostgresSrv.sanitizeNumber);
12
13
  PostgresSrv.renderer.registerFunction("sanitizeText", PostgresSrv.sanitizeText);
13
14
  PostgresSrv.renderer.registerFunction("sanitizeTextNull", PostgresSrv.sanitizeTextNull);
@@ -40,6 +41,9 @@ export class PostgresSrv {
40
41
  static noQuotes(val, ...args) {
41
42
  return val.replace(/'/g, "''");
42
43
  }
44
+ static singleWord(val, ...args) {
45
+ return val.split(/\s+/g)[0];
46
+ }
43
47
  static sanitizeText(val, ...args) {
44
48
  let text = val;
45
49
  if ([null, undefined].indexOf(text) >= 0) {
@@ -138,14 +142,21 @@ export class PostgresSrv {
138
142
  });
139
143
  }
140
144
 
141
- static async getPool() {
145
+ static async checkSelect1() {
142
146
  if (PostgresSrv.pool == null) {
143
147
  PostgresSrv.createPool();
144
148
  }
145
149
  try {
146
150
  await PostgresSrv.pool.query('SELECT 1;');
151
+ return true;
147
152
  } catch (err) {
148
- console.log(err);
153
+ return false;
154
+ }
155
+ }
156
+
157
+ static async getPool() {
158
+ const canSelect1 = await PostgresSrv.checkSelect1();
159
+ if (!canSelect1) {
149
160
  PostgresSrv.createPool();
150
161
  }
151
162
  return PostgresSrv.pool;
@@ -1,4 +1,5 @@
1
1
  import md5 from 'md5';
2
+ import { MalaPeticionException, ParametrosIncompletosException } from '../MyError.mjs';
2
3
 
3
4
  export class General {
4
5
  static PAGE_SIZE_DEFAULT = "20";
@@ -20,7 +21,7 @@ export class General {
20
21
  offset,
21
22
  };
22
23
  }
23
- static readParam(req, name, pred = null) {
24
+ static readParam(req, name, pred = null, complain = false) {
24
25
  const nameLower = name.toLowerCase();
25
26
  if (req.body && name in req.body) {
26
27
  return req.body[name];
@@ -37,6 +38,9 @@ export class General {
37
38
  return req.locals.extra[name];
38
39
  }
39
40
  }
41
+ if (complain) {
42
+ throw new ParametrosIncompletosException(`Parameter not found but required: ${name}`);
43
+ }
40
44
  return pred;
41
45
  }
42
46
  static getSuffixPath(keyName, suffix) {