orbitx-core-models 1.0.0 → 1.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"user.model.d.ts","sourceRoot":"","sources":["../../src/models/user.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAkBrD,wBAAgB,eAAe,CAC7B,gBAAgB,EAAE,cAAc,UAAU,CAAC,GAC1C,KAAK,CAAC,KAAK,CAAC,CAKd"}
1
+ {"version":3,"file":"user.model.d.ts","sourceRoot":"","sources":["../../src/models/user.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAqCrD,wBAAgB,eAAe,CAC7B,gBAAgB,EAAE,cAAc,UAAU,CAAC,GAC1C,KAAK,CAAC,KAAK,CAAC,CAKd"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.createUserModel = createUserModel;
4
7
  const mongoose_1 = require("mongoose");
8
+ const argon2_1 = __importDefault(require("argon2"));
5
9
  const userSchema = new mongoose_1.Schema({
6
10
  name: String,
7
11
  email: String,
@@ -17,6 +21,20 @@ const userSchema = new mongoose_1.Schema({
17
21
  currentStatus: { type: String, default: "Offline" },
18
22
  lastLogin: Date,
19
23
  });
24
+ userSchema.pre("save", async function (next) {
25
+ if (!this.isModified("password") || !this.password)
26
+ return next();
27
+ this.password = await argon2_1.default.hash(this.password, {
28
+ type: argon2_1.default.argon2i,
29
+ timeCost: 2,
30
+ });
31
+ next();
32
+ });
33
+ userSchema.methods.compare = async function (userPassword, inputPassword) {
34
+ if (!this.password)
35
+ return false;
36
+ return await argon2_1.default.verify(userPassword, inputPassword);
37
+ };
20
38
  function createUserModel(mongooseInstance) {
21
39
  return (mongooseInstance.models.User ||
22
40
  mongooseInstance.model("User", userSchema));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orbitx-core-models",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Shared Mongoose models and interfaces for OrbitX services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",