shuttlepro-shared 1.3.36 → 1.3.37
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.
- package/models/Workspace.js +26 -0
- package/package.json +1 -1
package/models/Workspace.js
CHANGED
|
@@ -3,6 +3,15 @@ const SettingModel = require("./Setting");
|
|
|
3
3
|
const SocialMediaSettingModel = require("./SocialMediaSetting");
|
|
4
4
|
const { Schema } = mongoose;
|
|
5
5
|
|
|
6
|
+
const generateSlug = (input) => {
|
|
7
|
+
return input
|
|
8
|
+
.trim()
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
11
|
+
.replace(/\s+/g, "-")
|
|
12
|
+
.replace(/-+/g, "-");
|
|
13
|
+
};
|
|
14
|
+
|
|
6
15
|
//TODO: task manager and default location creation
|
|
7
16
|
const shiftSchema = new mongoose.Schema(
|
|
8
17
|
{
|
|
@@ -364,5 +373,22 @@ workspaceSchema.add({
|
|
|
364
373
|
chatGptApiKey: commonOptions,
|
|
365
374
|
});
|
|
366
375
|
|
|
376
|
+
workspaceSchema.pre("save", async function (next) {
|
|
377
|
+
if (this.isModified("name")) {
|
|
378
|
+
let slug = generateSlug(this.name);
|
|
379
|
+
let slugExists = await mongoose.models.Workspace.findOne({ slug });
|
|
380
|
+
|
|
381
|
+
let counter = 1;
|
|
382
|
+
while (slugExists) {
|
|
383
|
+
slug = `${slug}-${counter}`;
|
|
384
|
+
slugExists = await mongoose.models.Workspace.findOne({ slug });
|
|
385
|
+
counter++;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this.slug = slug;
|
|
389
|
+
}
|
|
390
|
+
next();
|
|
391
|
+
});
|
|
392
|
+
|
|
367
393
|
const Workspace = mongoose.model("Workspace", workspaceSchema);
|
|
368
394
|
module.exports = Workspace;
|