@dynamatix/gb-schemas 0.21.0 → 0.21.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,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const applicationAuditSchema = new mongoose.Schema({
5
5
  auditId: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const checkListItemSchema = new mongoose.Schema({
5
5
  additionalOfferConditions: { type: String, default: "" },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const companySchema = new mongoose.Schema({
5
5
  addressCity: { type: String, default: "" },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const documentSchema = new mongoose.Schema({
5
5
  applicationId: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const fieldConfigSchema = new mongoose.Schema({
5
5
  fieldName: { type: String, required: true, unique: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const mortgageSchema = new mongoose.Schema({
5
5
  depositComeFrom: { type: String, required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const noteSchema = new mongoose.Schema({
5
5
  applicationId: { type: mongoose.Schema.Types.ObjectId, ref: "Application", required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const onboardingSchema = new mongoose.Schema({
5
5
  errors: { type: String, default: "" },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const rationaleSchema = new mongoose.Schema({
5
5
  applicationId: { type: mongoose.Schema.Types.ObjectId, ref: "Application", required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from 'mongoose';
2
- import mongooseEncryption from '../utils/encryption.middleware';
2
+ import mongooseEncryption from '../utils/encryption.middleware.js';
3
3
 
4
4
  const applicantionRiskNarrativeSchema = new mongoose.Schema({
5
5
  call1RequestedOn: { type: String },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const brokerSchema = new mongoose.Schema({
5
5
  brokerId: { type: Number },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const documentSchema = new mongoose.Schema({
5
5
  applicationId: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const feeSchema = new mongoose.Schema({
5
5
  feeType: { type: String, required: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "0.21.0",
3
+ "version": "0.21.2",
4
4
  "description": "All the schemas for gatehouse bank back-end.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const productCatalogueSchema = new mongoose.Schema({
5
5
  productCatalogueId: { type: String, required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const ruleSchema = new mongoose.Schema({
5
5
  ruleId: { type: String, required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const productVariantSchema = new mongoose.Schema({
5
5
  productCatalogueId: { ref: "ProductCatalogue", type: mongoose.Schema.Types.ObjectId, required: true },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const dataStreetSchema = new mongoose.Schema({
5
5
  floorArea: { type: String, default: '' },
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const alertSchema = new mongoose.Schema({
5
5
  alertTypeLid: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const checklistSchema = new mongoose.Schema({
5
5
  checkTypeLid: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const lookupGroupSchema = new mongoose.Schema({
5
5
  name: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const lookupSchema = new mongoose.Schema({
5
5
  name: {
@@ -1,5 +1,5 @@
1
1
  import mongoose from 'mongoose';
2
- import mongooseEncryption from '../utils/encryption.middleware';
2
+ import mongooseEncryption from '../utils/encryption.middleware.js';
3
3
 
4
4
  // Define the schema for TaskDocumentType
5
5
  const taskDocumentTypeSchema = new mongoose.Schema({
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const { Schema } = mongoose;
5
5
 
@@ -1,5 +1,5 @@
1
1
  import mongoose from "mongoose";
2
- import mongooseEncryption from "../utils/encryption.middleware";
2
+ import mongooseEncryption from "../utils/encryption.middleware.js";
3
3
 
4
4
  const ClaimSchema = new mongoose.Schema({
5
5
  key: { type: String, required: true },
@@ -37,6 +37,16 @@ export default function mongooseEncryption(schema, options) {
37
37
  }
38
38
  });
39
39
 
40
+
41
+ // Encrypt before update operations (single or multiple documents)
42
+ schema.pre("update", function (result) {
43
+ if (Array.isArray(result)) {
44
+ result.forEach(doc => doc.set(decryptObject(doc.toObject(), collectionName)));
45
+ } else {
46
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
47
+ }
48
+ });
49
+
40
50
  // Decrypt after update operations (single or multiple documents)
41
51
  schema.post("update", function (result) {
42
52
  if (Array.isArray(result)) {
@@ -46,6 +56,13 @@ export default function mongooseEncryption(schema, options) {
46
56
  }
47
57
  });
48
58
 
59
+ // Encrypt after updateOne operations
60
+ schema.pre("updateOne", function (result) {
61
+ if (result && result.toObject) {
62
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
63
+ }
64
+ });
65
+
49
66
  // Decrypt after updateOne operations
50
67
  schema.post("updateOne", function (result) {
51
68
  if (result && result.toObject) {
@@ -53,6 +70,12 @@ export default function mongooseEncryption(schema, options) {
53
70
  }
54
71
  });
55
72
 
73
+ schema.pre("findOneAndUpdate", function (result) {
74
+ if (result && result.toObject) {
75
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
76
+ }
77
+ });
78
+
56
79
  // Decrypt after find operations (e.g., find, findMany)
57
80
  schema.post("find", function (docs) {
58
81
  console.log("find", docs);
@@ -73,6 +96,7 @@ export default function mongooseEncryption(schema, options) {
73
96
  if (doc) doc.set(decryptObject(doc.toObject(), collectionName)); // Decrypt single document
74
97
  });
75
98
 
99
+
76
100
  // Decrypt after findOneAndUpdate operations
77
101
  schema.post("findOneAndUpdate", function (doc) {
78
102
  console.log("findOneAndUpdate", doc);