shuttlepro-shared 1.4.71 → 1.4.72

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.
Files changed (2) hide show
  1. package/models/Shipper.js +31 -0
  2. package/package.json +2 -2
package/models/Shipper.js CHANGED
@@ -41,6 +41,7 @@ const shipperInformationSchema = new Schema({
41
41
  const shipperSchema = new mongoose.Schema(
42
42
  {
43
43
  type: { type: String, default: "" },
44
+ name: { type: String, default: "" },
44
45
  userName: { type: String, default: "" },
45
46
  password: { type: String, default: "" },
46
47
  clientId: { type: String, default: "" },
@@ -64,4 +65,34 @@ const shipperSchema = new mongoose.Schema(
64
65
  { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
65
66
  );
66
67
 
68
+ /**
69
+ * Auto-generate shipper name if not provided
70
+ * Format: "{TYPE} {NUMBER}" e.g., "DAEWOO 1", "DAEWOO 2", etc.
71
+ */
72
+ shipperSchema.pre("save", async function (next) {
73
+ // Only auto-generate if name is empty or not provided
74
+ if (!this.name || this.name.trim() === "") {
75
+ if (this.type && this.workspaceId) {
76
+ try {
77
+ // Count existing shippers of the same type in the same workspace (including deleted ones for numbering)
78
+ const ShipperModel = this.constructor;
79
+ const count = await ShipperModel.countDocuments({
80
+ type: this.type,
81
+ workspaceId: this.workspaceId,
82
+ });
83
+
84
+ // Generate name: "TYPE NUMBER" (starting from 1)
85
+ this.name = `${this.type} ${count + 1}`;
86
+ } catch (error) {
87
+ // If counting fails, use a simple fallback
88
+ this.name = `${this.type} 1`;
89
+ }
90
+ } else {
91
+ // Fallback if type or workspaceId is missing
92
+ this.name = this.type || "Shipper";
93
+ }
94
+ }
95
+ next();
96
+ });
97
+
67
98
  module.exports = mongoose.model("shipper", shipperSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.4.71",
3
+ "version": "1.4.72",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,4 +26,4 @@
26
26
  "redis": "^4.6.14",
27
27
  "socket.io": "^4.8.1"
28
28
  }
29
- }
29
+ }