express-generator-typescript 2.3.4 → 2.3.6

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.
@@ -79,7 +79,7 @@ describe('UserRouter', () => {
79
79
  .end((_: Error, res: Response) => {
80
80
  expect(res.status).toBe(OK);
81
81
  for (let i = 0; i < res.body.users.length; i++) {
82
- const user = new User(res.body.users[i]);
82
+ const user = User.from(res.body.users[i]);
83
83
  expect(user).toEqual(DummyGetAllUsers[i]);
84
84
  }
85
85
  done();
@@ -37,35 +37,40 @@ class User implements IUser {
37
37
  public role?: UserRoles;
38
38
  public pwdHash?: string;
39
39
 
40
+ /**
41
+ * Constructor()
42
+ */
40
43
  constructor(
41
- nameOrObj: string | object,
44
+ name?: string,
42
45
  email?: string,
43
46
  role?: UserRoles,
44
47
  pwdHash?: string,
45
- id?: number,
48
+ id?: number, // id last cause usually set by db
46
49
  ) {
47
- if (typeof nameOrObj === 'string') {
48
- this.name = nameOrObj;
49
- this.email = (email ?? '');
50
- this.role = (role ?? UserRoles.Standard);
51
- this.pwdHash = (pwdHash ?? '');
52
- this.id = (id ?? -1);
53
- } else if (User.IsUserObj(nameOrObj)) {
54
- const o = nameOrObj as IUser;
55
- this.name = o.name;
56
- this.email = (o.email ?? '');
57
- this.role = (o.role ?? UserRoles.Standard);
58
- this.pwdHash = (o.pwdHash ?? '');
59
- this.id = (o.id ?? -1);
60
- } else {
50
+ this.name = (name ?? '');
51
+ this.email = (email ?? '');
52
+ this.role = (role ?? UserRoles.Standard);
53
+ this.pwdHash = (pwdHash ?? '');
54
+ this.id = (id ?? -1);
55
+ }
56
+
57
+ /**
58
+ * Get user instance from object.
59
+ */
60
+ public static from(param: object): User {
61
+ // Check is user
62
+ if (!User.isUser(param)) {
61
63
  throw new Error(INVALID_CONSTRUCTOR_PARAM);
62
64
  }
65
+ // Get user instance
66
+ const p = param as IUser;
67
+ return new User(p.name, p.email, p.role, p.pwdHash, p.id);
63
68
  }
64
69
 
65
70
  /**
66
71
  * Is this an object which contains all the user keys.
67
72
  */
68
- public static IsUserObj(this: void, arg: unknown): boolean {
73
+ public static isUser(this: void, arg: unknown): boolean {
69
74
  return (
70
75
  !!arg &&
71
76
  typeof arg === 'object' &&
@@ -48,14 +48,14 @@ userRouter.get(
48
48
  // Add one user
49
49
  userRouter.post(
50
50
  Paths.Users.Add,
51
- validate(['user', User.IsUserObj]),
51
+ validate(['user', User.isUser]),
52
52
  UserRoutes.add,
53
53
  );
54
54
 
55
55
  // Update one user
56
56
  userRouter.put(
57
57
  Paths.Users.Update,
58
- validate(['user', User.IsUserObj]),
58
+ validate(['user', User.isUser]),
59
59
  UserRoutes.update,
60
60
  );
61
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.3.4",
3
+ "version": "2.3.6",
4
4
  "description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
5
5
  "scripts": {
6
6
  "express-generator-typescript": "node bin/cli.js",