shuttlepro-shared 1.3.91 → 1.3.93
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/common/repositories/interactive.repository.js +124 -0
- package/models/Attribute.js +0 -5
- package/models/Automation.js +0 -3
- package/models/Category.js +0 -5
- package/models/Chatbot.js +1 -0
- package/models/Checkpoint.js +0 -5
- package/models/Customer.js +0 -5
- package/models/Interactive.js +70 -0
- package/models/Location.js +0 -5
- package/models/Order.js +0 -6
- package/models/OrderPdf.js +0 -5
- package/models/OrderProduct.js +0 -5
- package/models/Product.js +0 -5
- package/models/ProductAttachment.js +0 -5
- package/models/ProductAttribute.js +0 -5
- package/models/ProductCategory.js +0 -5
- package/models/ProductTag.js +0 -5
- package/models/ProductVariant.js +0 -5
- package/models/Tag.js +0 -5
- package/models/VariantLocation.js +0 -5
- package/package.json +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// repositories/interactive.repository.js
|
|
2
|
+
const Interactive = require("../../models/Interactive");
|
|
3
|
+
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
4
|
+
|
|
5
|
+
const CACHE_KEY_ALL = "interactive_all";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get cached interactive for all workspaces.
|
|
9
|
+
*/
|
|
10
|
+
const getCachedAllInteractive = async () => {
|
|
11
|
+
let interactive = await getRedisData(CACHE_KEY_ALL);
|
|
12
|
+
if (!interactive) {
|
|
13
|
+
interactive = await Interactive.find({}).lean().exec();
|
|
14
|
+
await setRedisData(CACHE_KEY_ALL, interactive);
|
|
15
|
+
}
|
|
16
|
+
return interactive;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Update cached interactive for all workspaces.
|
|
21
|
+
*/
|
|
22
|
+
const updateCachedAllInteractive = async () => {
|
|
23
|
+
const interactive = await Interactive.find({}).lean().exec();
|
|
24
|
+
await setRedisData(CACHE_KEY_ALL, interactive);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get interactive for a specific workspace from cache.
|
|
29
|
+
*/
|
|
30
|
+
const getWorkspaceInteractive = async (workspaceId) => {
|
|
31
|
+
if (!workspaceId) return [];
|
|
32
|
+
const allInteractive = await getCachedAllInteractive();
|
|
33
|
+
return allInteractive.filter(
|
|
34
|
+
(item) => item.workspaceId?.toString() === workspaceId.toString()
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Get interactive by ID (cache first).
|
|
39
|
+
*/
|
|
40
|
+
const getInteractiveById = async (id) => {
|
|
41
|
+
if (!id) return null;
|
|
42
|
+
|
|
43
|
+
const allInteractive = await getCachedAllInteractive();
|
|
44
|
+
let interactive = allInteractive.find(
|
|
45
|
+
(item) => item._id?.toString() === id.toString()
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// If not found in cache, fetch from DB and update cache
|
|
49
|
+
if (!interactive) {
|
|
50
|
+
interactive = await Interactive.findById(id).lean().exec();
|
|
51
|
+
if (interactive) {
|
|
52
|
+
await updateCachedAllInteractive();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return interactive || null;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create new interactive and refresh cache.
|
|
61
|
+
*/
|
|
62
|
+
const createInteractive = async (data) => {
|
|
63
|
+
const newInteractive = await Interactive.create(data);
|
|
64
|
+
if (newInteractive) {
|
|
65
|
+
await updateCachedAllInteractive();
|
|
66
|
+
}
|
|
67
|
+
return newInteractive;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Update interactive by ID and refresh cache.
|
|
72
|
+
*/
|
|
73
|
+
const updateInteractiveById = async (id, data) => {
|
|
74
|
+
const updated = await Interactive.findByIdAndUpdate(id, data, {
|
|
75
|
+
new: true,
|
|
76
|
+
}).exec();
|
|
77
|
+
if (updated) {
|
|
78
|
+
await updateCachedAllInteractive();
|
|
79
|
+
}
|
|
80
|
+
return updated;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Update interactive by filter and refresh cache.
|
|
85
|
+
*/
|
|
86
|
+
const updateSingleInteractiveByFilter = async (filter, data) => {
|
|
87
|
+
const updated = await Interactive.findOneAndUpdate(filter, data, {
|
|
88
|
+
new: true,
|
|
89
|
+
}).exec();
|
|
90
|
+
if (updated) {
|
|
91
|
+
await updateCachedAllInteractive();
|
|
92
|
+
}
|
|
93
|
+
return updated;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Delete interactive by ID and refresh cache.
|
|
98
|
+
*/
|
|
99
|
+
const deleteInteractiveById = async (id) => {
|
|
100
|
+
const deleted = await Interactive.findByIdAndDelete(id).exec();
|
|
101
|
+
if (deleted) {
|
|
102
|
+
await updateCachedAllInteractive();
|
|
103
|
+
}
|
|
104
|
+
return deleted;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delete interactive by filter and refresh cache.
|
|
109
|
+
*/
|
|
110
|
+
const deleteInteractiveByFilter = async (filter) => {
|
|
111
|
+
await Interactive.deleteMany(filter).exec();
|
|
112
|
+
await updateCachedAllInteractive();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
module.exports = {
|
|
116
|
+
updateCachedAllInteractive,
|
|
117
|
+
getWorkspaceInteractive,
|
|
118
|
+
createInteractive,
|
|
119
|
+
updateInteractiveById,
|
|
120
|
+
updateSingleInteractiveByFilter,
|
|
121
|
+
deleteInteractiveById,
|
|
122
|
+
deleteInteractiveByFilter,
|
|
123
|
+
getInteractiveById,
|
|
124
|
+
};
|
package/models/Attribute.js
CHANGED
|
@@ -10,11 +10,6 @@ const AttributeSchema = new Schema(
|
|
|
10
10
|
ref: "Workspace",
|
|
11
11
|
default: null,
|
|
12
12
|
},
|
|
13
|
-
websiteId: {
|
|
14
|
-
type: Schema.Types.ObjectId,
|
|
15
|
-
ref: "Website",
|
|
16
|
-
default: null,
|
|
17
|
-
},
|
|
18
13
|
oldId: { type: String, default: "" },
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
package/models/Automation.js
CHANGED
package/models/Category.js
CHANGED
|
@@ -11,11 +11,6 @@ const CategorySchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
oldId: { type: String, default: "" },
|
|
20
15
|
webCategoryId: { type: Number, default: null },
|
|
21
16
|
parentId: { type: Schema.Types.ObjectId, ref: "Category", default: null },
|
package/models/Chatbot.js
CHANGED
package/models/Checkpoint.js
CHANGED
|
@@ -14,11 +14,6 @@ const CheckpointSchema = new Schema(
|
|
|
14
14
|
ref: "Workspace",
|
|
15
15
|
default: null,
|
|
16
16
|
},
|
|
17
|
-
websiteId: {
|
|
18
|
-
type: Schema.Types.ObjectId,
|
|
19
|
-
ref: "Website",
|
|
20
|
-
default: null,
|
|
21
|
-
},
|
|
22
17
|
},
|
|
23
18
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
24
19
|
);
|
package/models/Customer.js
CHANGED
|
@@ -18,11 +18,6 @@ const CustomerSchema = new Schema(
|
|
|
18
18
|
ref: "Workspace",
|
|
19
19
|
default: null,
|
|
20
20
|
},
|
|
21
|
-
websiteId: {
|
|
22
|
-
type: Schema.Types.ObjectId,
|
|
23
|
-
ref: "Website",
|
|
24
|
-
default: null,
|
|
25
|
-
},
|
|
26
21
|
isBlackListed: { type: Boolean, default: false },
|
|
27
22
|
createdBy: {
|
|
28
23
|
type: Schema.Types.ObjectId,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const { Schema, Types, model } = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const ActionSchema = new Schema({
|
|
4
|
+
type: {
|
|
5
|
+
type: String,
|
|
6
|
+
default: "",
|
|
7
|
+
},
|
|
8
|
+
interactiveId: { type: Types.ObjectId, ref: "Interactive", default: null },
|
|
9
|
+
value: { type: Schema.Types.Mixed, default: "" },
|
|
10
|
+
});
|
|
11
|
+
const InteractiveSchema = new Schema({
|
|
12
|
+
name: { type: String, default: "" },
|
|
13
|
+
workspace: { type: Types.ObjectId, ref: "Workspace", default: null },
|
|
14
|
+
type: {
|
|
15
|
+
type: String,
|
|
16
|
+
enum: ["button", "list"],
|
|
17
|
+
default: "list",
|
|
18
|
+
},
|
|
19
|
+
header: {
|
|
20
|
+
type: {
|
|
21
|
+
type: String,
|
|
22
|
+
enum: ["text", "image", "video"],
|
|
23
|
+
default: "text",
|
|
24
|
+
},
|
|
25
|
+
value: { type: String, default: "" },
|
|
26
|
+
},
|
|
27
|
+
body: {
|
|
28
|
+
type: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: "text",
|
|
31
|
+
},
|
|
32
|
+
value: { type: String, default: "" },
|
|
33
|
+
},
|
|
34
|
+
footer: {
|
|
35
|
+
type: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: "text",
|
|
38
|
+
},
|
|
39
|
+
value: { type: String, default: "" },
|
|
40
|
+
},
|
|
41
|
+
buttonTitle: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: "Menu",
|
|
44
|
+
},
|
|
45
|
+
sections: [
|
|
46
|
+
{
|
|
47
|
+
title: { type: String, default: "" },
|
|
48
|
+
rows: [
|
|
49
|
+
{
|
|
50
|
+
id: { type: String, default: "" },
|
|
51
|
+
title: { type: String, default: "" },
|
|
52
|
+
description: { type: String, default: "" },
|
|
53
|
+
action: ActionSchema,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
buttons: [
|
|
59
|
+
{
|
|
60
|
+
type: { type: String, default: "reply" },
|
|
61
|
+
reply: {
|
|
62
|
+
id: { type: String, default: "" },
|
|
63
|
+
title: { type: String, default: "" },
|
|
64
|
+
action: ActionSchema,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
module.exports = model("Interactive", InteractiveSchema);
|
package/models/Location.js
CHANGED
|
@@ -14,11 +14,6 @@ const LocationSchema = new Schema(
|
|
|
14
14
|
oldId: { type: String, default: "" },
|
|
15
15
|
webLocationId: { type: Number, default: null },
|
|
16
16
|
bcLocationId: { type: String, default: "" },
|
|
17
|
-
websiteId: {
|
|
18
|
-
type: Schema.Types.ObjectId,
|
|
19
|
-
ref: "Website",
|
|
20
|
-
default: null,
|
|
21
|
-
},
|
|
22
17
|
workspaceId: {
|
|
23
18
|
type: Schema.Types.ObjectId,
|
|
24
19
|
ref: "Workspace",
|
package/models/Order.js
CHANGED
|
@@ -103,11 +103,6 @@ const OrderSchema = new Schema(
|
|
|
103
103
|
ref: "Workspace",
|
|
104
104
|
default: null,
|
|
105
105
|
},
|
|
106
|
-
websiteId: {
|
|
107
|
-
type: Schema.Types.ObjectId,
|
|
108
|
-
ref: "Website",
|
|
109
|
-
default: null,
|
|
110
|
-
},
|
|
111
106
|
orderType: { type: String, default: "" },
|
|
112
107
|
barCode: { type: String, default: "" },
|
|
113
108
|
quantity: { type: Number, default: 0 },
|
|
@@ -228,7 +223,6 @@ const markOrUnMarkOrderAsDuplicate = async (doc) => {
|
|
|
228
223
|
const phoneRegex = getPhoneRegex(doc?.customerPhone);
|
|
229
224
|
let orders = await Order.find({
|
|
230
225
|
workspaceId: doc?.workspaceId,
|
|
231
|
-
websiteId: doc?.websiteId,
|
|
232
226
|
isDeleted: false,
|
|
233
227
|
statusType: "pending",
|
|
234
228
|
customerPhone: phoneRegex,
|
package/models/OrderPdf.js
CHANGED
|
@@ -20,11 +20,6 @@ const OrderPdfScehma = new mongoose.Schema(
|
|
|
20
20
|
ref: "Workspace",
|
|
21
21
|
default: null,
|
|
22
22
|
},
|
|
23
|
-
websiteId: {
|
|
24
|
-
type: Schema.Types.ObjectId,
|
|
25
|
-
ref: "Website",
|
|
26
|
-
default: null,
|
|
27
|
-
},
|
|
28
23
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
29
24
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
30
25
|
},
|
package/models/OrderProduct.js
CHANGED
|
@@ -31,11 +31,6 @@ const OrderProductSchema = new Schema(
|
|
|
31
31
|
ref: "Workspace",
|
|
32
32
|
default: null,
|
|
33
33
|
},
|
|
34
|
-
websiteId: {
|
|
35
|
-
type: Schema.Types.ObjectId,
|
|
36
|
-
ref: "Website",
|
|
37
|
-
default: null,
|
|
38
|
-
},
|
|
39
34
|
},
|
|
40
35
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
41
36
|
);
|
package/models/Product.js
CHANGED
|
@@ -31,11 +31,6 @@ const ProductSchema = new Schema(
|
|
|
31
31
|
type: Schema.Types.ObjectId,
|
|
32
32
|
ref: "Workspace",
|
|
33
33
|
default: null,
|
|
34
|
-
},
|
|
35
|
-
websiteId: {
|
|
36
|
-
type: Schema.Types.ObjectId,
|
|
37
|
-
ref: "Website",
|
|
38
|
-
default: null,
|
|
39
34
|
},
|
|
40
35
|
storeType: { type: String, default: "LOCAL" },
|
|
41
36
|
isDeleted: { type: Boolean, default: false },
|
|
@@ -22,11 +22,6 @@ const ProductAttachmentSchema = new Schema(
|
|
|
22
22
|
ref: "Workspace",
|
|
23
23
|
default: null,
|
|
24
24
|
},
|
|
25
|
-
websiteId: {
|
|
26
|
-
type: Schema.Types.ObjectId,
|
|
27
|
-
ref: "Website",
|
|
28
|
-
default: null,
|
|
29
|
-
},
|
|
30
25
|
height: { type: Number, default: 0 },
|
|
31
26
|
variantIds: [
|
|
32
27
|
{ type: Schema.Types.ObjectId, ref: "ProductVariant", default: null },
|
|
@@ -16,11 +16,6 @@ const ProductAttributeSchema = new mongoose.Schema(
|
|
|
16
16
|
ref: "Workspace",
|
|
17
17
|
default: null,
|
|
18
18
|
},
|
|
19
|
-
websiteId: {
|
|
20
|
-
type: Schema.Types.ObjectId,
|
|
21
|
-
ref: "Website",
|
|
22
|
-
default: null,
|
|
23
|
-
},
|
|
24
19
|
isDeleted: { type: Boolean, default: false },
|
|
25
20
|
position: { type: String, default: "1" },
|
|
26
21
|
},
|
|
@@ -11,11 +11,6 @@ const ProductCategorySchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
21
16
|
isDeleted: { type: Boolean, default: false },
|
package/models/ProductTag.js
CHANGED
|
@@ -11,11 +11,6 @@ const ProductTagSchema = new Schema(
|
|
|
11
11
|
ref: "Workspace",
|
|
12
12
|
default: null,
|
|
13
13
|
},
|
|
14
|
-
websiteId: {
|
|
15
|
-
type: Schema.Types.ObjectId,
|
|
16
|
-
ref: "Website",
|
|
17
|
-
default: null,
|
|
18
|
-
},
|
|
19
14
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
20
15
|
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
21
16
|
isDeleted: { type: Boolean, default: false },
|
package/models/ProductVariant.js
CHANGED
|
@@ -17,11 +17,6 @@ const ProductVariantSchema = new Schema(
|
|
|
17
17
|
ref: "Workspace",
|
|
18
18
|
default: null,
|
|
19
19
|
},
|
|
20
|
-
websiteId: {
|
|
21
|
-
type: Schema.Types.ObjectId,
|
|
22
|
-
ref: "Website",
|
|
23
|
-
default: null,
|
|
24
|
-
},
|
|
25
20
|
webVariantId: { type: Number, default: null },
|
|
26
21
|
inventoryPolicy: { type: String, default: "deny" }, //deny,continue
|
|
27
22
|
taxable: { type: Boolean, default: false },
|
package/models/Tag.js
CHANGED
|
@@ -8,11 +8,6 @@ const TagSchema = new Schema(
|
|
|
8
8
|
ref: "Workspace",
|
|
9
9
|
default: null,
|
|
10
10
|
},
|
|
11
|
-
websiteId: {
|
|
12
|
-
type: Schema.Types.ObjectId,
|
|
13
|
-
ref: "Website",
|
|
14
|
-
default: null,
|
|
15
|
-
},
|
|
16
11
|
oldId: { type: String, default: "" },
|
|
17
12
|
webTagId: { type: Number, default: "" },
|
|
18
13
|
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
@@ -13,11 +13,6 @@ const VariantLocationSchema = new Schema(
|
|
|
13
13
|
ref: "Workspace",
|
|
14
14
|
default: null,
|
|
15
15
|
},
|
|
16
|
-
websiteId: {
|
|
17
|
-
type: Schema.Types.ObjectId,
|
|
18
|
-
ref: "Website",
|
|
19
|
-
default: null,
|
|
20
|
-
},
|
|
21
16
|
productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
|
|
22
17
|
locationId: { type: Schema.Types.ObjectId, ref: "Location", default: null },
|
|
23
18
|
webVariantLocationId: { type: Number, default: null },
|