@ejfdelgado/ejflab-back 1.24.1 → 1.25.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.24.1",
3
+ "version": "1.25.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -1,6 +1,9 @@
1
1
  import md5 from 'md5';
2
2
 
3
3
  export class General {
4
+ static PAGE_SIZE_DEFAULT = "20";
5
+ static PAGE_DIRECTION = "DESC";
6
+ static DIRECTION_CHOICES = ["asc", "desc"];
4
7
  static readMaxOffset(req, MAX_READ_SIZE) {
5
8
  const offsetR = parseInt(General.readParam(req, "offset"));
6
9
  const maxR = parseInt(General.readParam(req, "max"));
@@ -66,4 +69,27 @@ export class General {
66
69
  hash: md5(epochText),
67
70
  };
68
71
  }
72
+
73
+ static getPaginationArguments(req, orderColumnDef = null) {
74
+ const limit = parseInt(General.readParam(req, "limit", General.PAGE_SIZE_DEFAULT));
75
+ const orderColumn = General.readParam(req, "orderColumn", orderColumnDef);
76
+ const direction = General.readParam(req, "direction", General.PAGE_DIRECTION).toLowerCase();
77
+ const page = parseInt(General.readParam(req, "page", "0"));
78
+ if (!(typeof limit == "number")) {
79
+ throw new MalaPeticionException("limit is expected to be a number");
80
+ }
81
+ if (!(typeof page == "number")) {
82
+ throw new MalaPeticionException("page is expected to be a number");
83
+ }
84
+ if (General.DIRECTION_CHOICES.indexOf(direction) < 0) {
85
+ throw new MalaPeticionException(`direction is expected to be one of ${General.DIRECTION_CHOICES.join(', ')}`);
86
+ }
87
+ return {
88
+ limit,
89
+ orderColumn,
90
+ direction,
91
+ page,
92
+ offset: page * limit
93
+ };
94
+ }
69
95
  }
@@ -25,6 +25,9 @@ export class Usuario {
25
25
  if (AUTH_PROVIDER == "microsoft") {
26
26
  this.id = token.oid;
27
27
  this.email = token.preferred_username;
28
+ if (this.email) {
29
+ this.email = this.email.toLocaleLowerCase();
30
+ }
28
31
  if (token.groups instanceof Array) {
29
32
  this.groups = token.groups.map((idGroup) => {
30
33
  if (idGroup in groupIdMap) {