asv-hlps 1.0.12 → 1.0.15

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.
@@ -2,7 +2,8 @@ import { SteGrp } from './SteGrp';
2
2
  export interface Ste {
3
3
  id: number;
4
4
  name: string;
5
+ shortname?: string;
5
6
  isValided?: boolean;
6
7
  isActive?: boolean;
7
- grp: SteGrp;
8
+ grp?: SteGrp;
8
9
  }
@@ -1,3 +1,4 @@
1
+ import { Ste } from "./models/Ste";
1
2
  import { User } from "./models/User";
2
3
  export declare const inGrp: (grps: string[], user: User) => boolean;
3
4
  export declare const inSteGrp: (grps: string[], user: User) => boolean;
@@ -8,4 +9,7 @@ export declare const getFullname: (user: User) => string;
8
9
  export declare const entryDesignationUser: (user: User) => string;
9
10
  export declare const secureUser: (user: any, username: string, heads: any) => void;
10
11
  export declare const secureUserPassword: (user: any, heads: any) => void;
11
- export declare const getUserCode: (user: User) => string;
12
+ export declare const userGrpCode: (user: User) => string;
13
+ export declare const userCoef: (user: User) => number;
14
+ export declare const labelSteName: (ste: Ste, size?: number, tabs?: string[]) => string;
15
+ export declare const getSteShortname: (ste: Ste, [...steGrpNames]: Iterable<any>) => string;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getUserCode = exports.secureUserPassword = exports.secureUser = exports.entryDesignationUser = exports.getFullname = exports.isStaffSte = exports.isBillPeriod = exports.hasRole = exports.inSteGrp = exports.inGrp = void 0;
29
+ exports.getSteShortname = exports.labelSteName = exports.userCoef = exports.userGrpCode = exports.secureUserPassword = exports.secureUser = exports.entryDesignationUser = exports.getFullname = exports.isStaffSte = exports.isBillPeriod = exports.hasRole = exports.inSteGrp = exports.inGrp = void 0;
30
30
  const bcrypt = __importStar(require("bcryptjs"));
31
31
  const randomatic_1 = __importDefault(require("randomatic"));
32
32
  const shared_1 = require("../utils/shared");
@@ -49,7 +49,7 @@ const hasRole = (roles, user) => {
49
49
  };
50
50
  exports.hasRole = hasRole;
51
51
  const isBillPeriod = (user, period) => {
52
- return (user.periodBill.toLowerCase() === period) ? true : false;
52
+ return user.periodBill.toLowerCase() === period ? true : false;
53
53
  };
54
54
  exports.isBillPeriod = isBillPeriod;
55
55
  // export const isStaffSte = (user: User, steNames: string|string[]) => {
@@ -68,21 +68,21 @@ const getFullname = (user) => {
68
68
  const firstname = user.firstname ? user.firstname.trim() : "";
69
69
  const civil = titr ? titr : gender;
70
70
  // const fullname = Util.titleCase(civil)+' '+lastname.toUpperCase()+' '+Util.titleCase(firstname);
71
- return (0, shared_1.titleCase)(civil) + ' ' + lastname.toUpperCase() + ' ' + (0, shared_1.titleCase)(firstname);
71
+ return (0, shared_1.titleCase)(civil) + " " + lastname.toUpperCase() + " " + (0, shared_1.titleCase)(firstname);
72
72
  };
73
73
  exports.getFullname = getFullname;
74
74
  const entryDesignationUser = (user) => {
75
75
  if (user.grp && user.ste) {
76
- if (!(user.grp.code === 'sf')) {
77
- return user.username.toUpperCase() + ' ' + user.ste.name.trim().replace(/ +/g, ' '); // remove more than 1 space
76
+ if (!(user.grp.code === "sf")) {
77
+ return user.username.toUpperCase() + " " + user.ste.name.trim().replace(/ +/g, " "); // remove more than 1 space
78
78
  }
79
- return user.username.toUpperCase() + ' ' + user.fullname.trim().replace(/ +/g, ' ');
79
+ return user.username.toUpperCase() + " " + user.fullname.trim().replace(/ +/g, " ");
80
80
  }
81
81
  return user.username.toUpperCase();
82
82
  };
83
83
  exports.entryDesignationUser = entryDesignationUser;
84
84
  const secureUser = (user, username, heads) => {
85
- user.password = (0, randomatic_1.default)('Aa0', 8);
85
+ user.password = (0, randomatic_1.default)("Aa0", 8);
86
86
  user.dns = heads.host;
87
87
  user.clp = user.password;
88
88
  user.password = bcrypt.hashSync(user.password, 8);
@@ -90,13 +90,46 @@ const secureUser = (user, username, heads) => {
90
90
  };
91
91
  exports.secureUser = secureUser;
92
92
  const secureUserPassword = (user, heads) => {
93
- user.password = (0, randomatic_1.default)('Aa0', 8);
93
+ user.password = (0, randomatic_1.default)("Aa0", 8);
94
94
  user.dns = heads.host;
95
95
  user.clp = user.password;
96
96
  user.password = bcrypt.hashSync(user.password, 8);
97
97
  };
98
98
  exports.secureUserPassword = secureUserPassword;
99
- const getUserCode = (user) => {
100
- return user.grp.code.toLowerCase() === 'st' ? user.ste.grp.code.toLowerCase() : user.grp.code.toLowerCase();
99
+ const userGrpCode = (user) => {
100
+ return user.grp.code.toLowerCase() === "st" ? user.ste.grp.code.toLowerCase() : user.grp.code.toLowerCase();
101
101
  };
102
- exports.getUserCode = getUserCode;
102
+ exports.userGrpCode = userGrpCode;
103
+ const userCoef = (user) => {
104
+ return user.grp.code.toLowerCase() === "st" ? user.ste.grp.coef : user.grp.coef;
105
+ };
106
+ exports.userCoef = userCoef;
107
+ const labelSteName = (ste, size = 20, tabs = ['pharmacie', 'clinique', 'hopital']) => {
108
+ const steNameLength = ste.name.length;
109
+ if (steNameLength > size) {
110
+ if (ste.shortname.length > size) {
111
+ const shortedName = (0, exports.getSteShortname)(ste, tabs);
112
+ if (shortedName.length > size) {
113
+ return (0, shared_1.limitTo)(shortedName, (size - 2), '..');
114
+ }
115
+ return shortedName;
116
+ }
117
+ return ste.shortname;
118
+ }
119
+ return ste.name;
120
+ };
121
+ exports.labelSteName = labelSteName;
122
+ const getSteShortname = (ste, [...steGrpNames]) => {
123
+ if (!ste) {
124
+ return null;
125
+ }
126
+ // const tabs = ['pharmacie', 'clinique', 'hopital'];
127
+ const name = ste.name.trimStart();
128
+ const firstWord = name.substring(0, name.indexOf(' '));
129
+ const restWords = name.substring(name.indexOf(' ') + 1);
130
+ return (steGrpNames.includes(firstWord.toLowerCase())) ?
131
+ // ste.grp.code.toLowerCase() + '. ' + restWords.trimLeft() :
132
+ ste.grp.code.toUpperCase() + '. ' + restWords.trimStart() :
133
+ name;
134
+ };
135
+ exports.getSteShortname = getSteShortname;
@@ -2,7 +2,8 @@ import { SteGrp } from './SteGrp';
2
2
  export interface Ste {
3
3
  id: number;
4
4
  name: string;
5
+ shortname?: string;
5
6
  isValided?: boolean;
6
7
  isActive?: boolean;
7
- grp: SteGrp;
8
+ grp?: SteGrp;
8
9
  }
@@ -1,3 +1,4 @@
1
+ import { Ste } from "./models/Ste";
1
2
  import { User } from "./models/User";
2
3
  export declare const inGrp: (grps: string[], user: User) => boolean;
3
4
  export declare const inSteGrp: (grps: string[], user: User) => boolean;
@@ -8,4 +9,7 @@ export declare const getFullname: (user: User) => string;
8
9
  export declare const entryDesignationUser: (user: User) => string;
9
10
  export declare const secureUser: (user: any, username: string, heads: any) => void;
10
11
  export declare const secureUserPassword: (user: any, heads: any) => void;
11
- export declare const getUserCode: (user: User) => string;
12
+ export declare const userGrpCode: (user: User) => string;
13
+ export declare const userCoef: (user: User) => number;
14
+ export declare const labelSteName: (ste: Ste, size?: number, tabs?: string[]) => string;
15
+ export declare const getSteShortname: (ste: Ste, [...steGrpNames]: Iterable<any>) => string;
@@ -1,6 +1,6 @@
1
- import * as bcrypt from 'bcryptjs';
2
- import randomatic from 'randomatic';
3
- import { titleCase } from "../utils/shared";
1
+ import * as bcrypt from "bcryptjs";
2
+ import randomatic from "randomatic";
3
+ import { limitTo, titleCase } from "../utils/shared";
4
4
  export const inGrp = (grps, user) => {
5
5
  return [...grps].includes(user.grp.code.toLowerCase()) ? true : false;
6
6
  };
@@ -17,7 +17,7 @@ export const hasRole = (roles, user) => {
17
17
  return [...roles].includes(user.role.code.toLowerCase()) ? true : false;
18
18
  };
19
19
  export const isBillPeriod = (user, period) => {
20
- return (user.periodBill.toLowerCase() === period) ? true : false;
20
+ return user.periodBill.toLowerCase() === period ? true : false;
21
21
  };
22
22
  // export const isStaffSte = (user: User, steNames: string|string[]) => {
23
23
  export const isStaffSte = (user, steNames) => {
@@ -34,30 +34,60 @@ export const getFullname = (user) => {
34
34
  const firstname = user.firstname ? user.firstname.trim() : "";
35
35
  const civil = titr ? titr : gender;
36
36
  // const fullname = Util.titleCase(civil)+' '+lastname.toUpperCase()+' '+Util.titleCase(firstname);
37
- return titleCase(civil) + ' ' + lastname.toUpperCase() + ' ' + titleCase(firstname);
37
+ return titleCase(civil) + " " + lastname.toUpperCase() + " " + titleCase(firstname);
38
38
  };
39
39
  export const entryDesignationUser = (user) => {
40
40
  if (user.grp && user.ste) {
41
- if (!(user.grp.code === 'sf')) {
42
- return user.username.toUpperCase() + ' ' + user.ste.name.trim().replace(/ +/g, ' '); // remove more than 1 space
41
+ if (!(user.grp.code === "sf")) {
42
+ return user.username.toUpperCase() + " " + user.ste.name.trim().replace(/ +/g, " "); // remove more than 1 space
43
43
  }
44
- return user.username.toUpperCase() + ' ' + user.fullname.trim().replace(/ +/g, ' ');
44
+ return user.username.toUpperCase() + " " + user.fullname.trim().replace(/ +/g, " ");
45
45
  }
46
46
  return user.username.toUpperCase();
47
47
  };
48
48
  export const secureUser = (user, username, heads) => {
49
- user.password = randomatic('Aa0', 8);
49
+ user.password = randomatic("Aa0", 8);
50
50
  user.dns = heads.host;
51
51
  user.clp = user.password;
52
52
  user.password = bcrypt.hashSync(user.password, 8);
53
53
  user.username = username;
54
54
  };
55
55
  export const secureUserPassword = (user, heads) => {
56
- user.password = randomatic('Aa0', 8);
56
+ user.password = randomatic("Aa0", 8);
57
57
  user.dns = heads.host;
58
58
  user.clp = user.password;
59
59
  user.password = bcrypt.hashSync(user.password, 8);
60
60
  };
61
- export const getUserCode = (user) => {
62
- return user.grp.code.toLowerCase() === 'st' ? user.ste.grp.code.toLowerCase() : user.grp.code.toLowerCase();
61
+ export const userGrpCode = (user) => {
62
+ return user.grp.code.toLowerCase() === "st" ? user.ste.grp.code.toLowerCase() : user.grp.code.toLowerCase();
63
+ };
64
+ export const userCoef = (user) => {
65
+ return user.grp.code.toLowerCase() === "st" ? user.ste.grp.coef : user.grp.coef;
66
+ };
67
+ export const labelSteName = (ste, size = 20, tabs = ['pharmacie', 'clinique', 'hopital']) => {
68
+ const steNameLength = ste.name.length;
69
+ if (steNameLength > size) {
70
+ if (ste.shortname.length > size) {
71
+ const shortedName = getSteShortname(ste, tabs);
72
+ if (shortedName.length > size) {
73
+ return limitTo(shortedName, (size - 2), '..');
74
+ }
75
+ return shortedName;
76
+ }
77
+ return ste.shortname;
78
+ }
79
+ return ste.name;
80
+ };
81
+ export const getSteShortname = (ste, [...steGrpNames]) => {
82
+ if (!ste) {
83
+ return null;
84
+ }
85
+ // const tabs = ['pharmacie', 'clinique', 'hopital'];
86
+ const name = ste.name.trimStart();
87
+ const firstWord = name.substring(0, name.indexOf(' '));
88
+ const restWords = name.substring(name.indexOf(' ') + 1);
89
+ return (steGrpNames.includes(firstWord.toLowerCase())) ?
90
+ // ste.grp.code.toLowerCase() + '. ' + restWords.trimLeft() :
91
+ ste.grp.code.toUpperCase() + '. ' + restWords.trimStart() :
92
+ name;
63
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.0.12",
3
+ "version": "1.0.15",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",