shuttlepro-shared 1.3.14 → 1.3.16
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/chatMember.repository.js +9 -0
- package/common/repositories/customerProfile.repository.js +147 -0
- package/common/repositories/descriptionTemplates.repository.js +229 -0
- package/common/repositories/index.js +32 -0
- package/common/repositories/integration.repository.js +210 -0
- package/common/repositories/label.repository.js +95 -0
- package/common/repositories/notificationSettings.repository.js +95 -0
- package/common/repositories/role.repository.js +333 -0
- package/common/repositories/settings.repository.js +32 -0
- package/common/repositories/shipper.repository.js +77 -0
- package/common/repositories/socialMediaSetting.repository.js +33 -0
- package/common/repositories/user.repository.js +150 -0
- package/common/repositories/userPermission.repository.js +228 -0
- package/common/repositories/userRepository.js +31 -0
- package/common/repositories/userRole.repository.js +235 -0
- package/common/repositories/userRolePermission.repository.js +59 -0
- package/common/repositories/workspace.repository.js +147 -0
- package/config/bull.js +78 -0
- package/config/config.js +14 -0
- package/config/database.js +4 -0
- package/config/index.js +13 -0
- package/config/redis.js +212 -0
- package/config/socket.js +172 -0
- package/constants/index.js +15 -0
- package/index.js +8 -0
- package/models/AgentActivity.js +192 -0
- package/models/Assignment.js +23 -0
- package/models/BusinessDistribution.js +23 -0
- package/models/Card.js +144 -0
- package/models/CardComments.js +33 -0
- package/models/ChatMember.js +17 -0
- package/models/Chatbot.js +20 -0
- package/models/Checkpoint.js +50 -0
- package/models/City.js +17 -0
- package/models/Column.js +28 -0
- package/models/Conversation.js +87 -0
- package/models/Customer.js +36 -0
- package/models/CustomerProfile.js +27 -0
- package/models/DefaultRolePermission.js +34 -0
- package/models/DescriptionTemplate.js +22 -0
- package/models/Integration.js +51 -0
- package/models/Label.js +42 -0
- package/models/Message.js +47 -0
- package/models/NewProduct.js +71 -0
- package/models/NotificationSettings.js +130 -0
- package/models/Order.js +236 -0
- package/models/OrderProduct.js +37 -0
- package/models/Profile.js +127 -0
- package/models/Report.js +27 -0
- package/models/Setting.js +18 -0
- package/models/Shipper.js +62 -0
- package/models/SocialMediaSetting.js +28 -0
- package/models/Status.js +58 -0
- package/models/StatusType.js +10 -0
- package/models/Step.js +50 -0
- package/models/Type.js +25 -0
- package/models/UserRole.js +1 -119
- package/models/UserWorkflow.js +46 -0
- package/models/Website.js +0 -1
- package/models/Workspace.js +318 -0
- package/models.js +62 -1
- package/package.json +13 -2
- package/utils/decorator-factory.js +264 -0
- package/utils/logger.js +41 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
const CustomerProfileSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
name: { type: String, default: "" },
|
|
6
|
+
email: { type: String, default: "" },
|
|
7
|
+
contact: { type: String, default: "" },
|
|
8
|
+
picture: { type: String, default: "" },
|
|
9
|
+
fbId: { type: String, default: "" },
|
|
10
|
+
igId: { type: String, default: "" },
|
|
11
|
+
blackList: { type: Boolean, default: false },
|
|
12
|
+
workspaceId: {
|
|
13
|
+
type: Schema.Types.ObjectId,
|
|
14
|
+
ref: "Workspace",
|
|
15
|
+
default: null,
|
|
16
|
+
},
|
|
17
|
+
mergedId: {
|
|
18
|
+
type: Schema.Types.ObjectId,
|
|
19
|
+
ref: "CustomerProfile",
|
|
20
|
+
default: null,
|
|
21
|
+
},
|
|
22
|
+
body: {},
|
|
23
|
+
},
|
|
24
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
module.exports = mongoose.model("CustomerProfile", CustomerProfileSchema);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const DefaultRolePermissionSchema = new Schema(
|
|
5
|
+
{
|
|
6
|
+
type: {
|
|
7
|
+
type: String,
|
|
8
|
+
default: "",
|
|
9
|
+
},
|
|
10
|
+
roleId: {
|
|
11
|
+
type: Schema.Types.ObjectId,
|
|
12
|
+
ref: "Role",
|
|
13
|
+
default: null,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const fields = ["role", "module", "action", "value"];
|
|
20
|
+
|
|
21
|
+
fields.forEach((field) => {
|
|
22
|
+
DefaultRolePermissionSchema.add({
|
|
23
|
+
[field]: {
|
|
24
|
+
type: String,
|
|
25
|
+
required: true,
|
|
26
|
+
default: "",
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
module.exports = mongoose.model(
|
|
32
|
+
"DefaultRolePermission",
|
|
33
|
+
DefaultRolePermissionSchema
|
|
34
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
const DescriptionTemplateSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
name: { type: String, default: "" },
|
|
6
|
+
subject: { type: String, default: "" },
|
|
7
|
+
format: { type: String, default: "" },
|
|
8
|
+
workspaceId: { type: String, default: "" },
|
|
9
|
+
businessId: { type: String, default: "" },
|
|
10
|
+
integrationId: { type: String, default: "" },
|
|
11
|
+
type: { type: String, default: "" },
|
|
12
|
+
body: {},
|
|
13
|
+
arbitraryValues: {},
|
|
14
|
+
moduleType: { type: String, default: "" },
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
17
|
+
);
|
|
18
|
+
const DescriptionTemplate =
|
|
19
|
+
mongoose.models.DescriptionTemplate ||
|
|
20
|
+
mongoose.model("DescriptionTemplate", DescriptionTemplateSchema);
|
|
21
|
+
|
|
22
|
+
module.exports = DescriptionTemplate;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const IntegrationSchema = new mongoose.Schema(
|
|
3
|
+
{
|
|
4
|
+
workspaceId: {
|
|
5
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
6
|
+
ref: "Workspace",
|
|
7
|
+
default: null,
|
|
8
|
+
},
|
|
9
|
+
type: {
|
|
10
|
+
type: String,
|
|
11
|
+
enum: [
|
|
12
|
+
"socialPlatforms",
|
|
13
|
+
"whatsapp",
|
|
14
|
+
"gmail",
|
|
15
|
+
"sms",
|
|
16
|
+
"map",
|
|
17
|
+
"facebook",
|
|
18
|
+
"instagram",
|
|
19
|
+
"webChat",
|
|
20
|
+
"smtp_gmail",
|
|
21
|
+
"outlook",
|
|
22
|
+
"business_central",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
chatbot: { type: Boolean, default: false },
|
|
26
|
+
isNlp: { type: Boolean, default: false },
|
|
27
|
+
autoTicket: {
|
|
28
|
+
enabled: { type: Boolean, default: false },
|
|
29
|
+
},
|
|
30
|
+
signature: {
|
|
31
|
+
type: Map,
|
|
32
|
+
of: mongoose.Schema.Types.Mixed,
|
|
33
|
+
default: {},
|
|
34
|
+
},
|
|
35
|
+
chatbotId: {
|
|
36
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
37
|
+
ref: "Chatbot",
|
|
38
|
+
default: null,
|
|
39
|
+
},
|
|
40
|
+
members: [
|
|
41
|
+
{
|
|
42
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
43
|
+
ref: "User",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
body: {},
|
|
47
|
+
},
|
|
48
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
module.exports = mongoose.model("Integration", IntegrationSchema);
|
package/models/Label.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const LabelSchema = new Schema(
|
|
5
|
+
{
|
|
6
|
+
color: { type: String },
|
|
7
|
+
title: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
type: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
default: "system",
|
|
15
|
+
enum: ["system", "custom", "escalation"],
|
|
16
|
+
},
|
|
17
|
+
workspaceId: {
|
|
18
|
+
type: Schema.Types.ObjectId,
|
|
19
|
+
ref: "Workspace",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
23
|
+
);
|
|
24
|
+
LabelSchema.virtual("conversationCount", {
|
|
25
|
+
ref: "Conversation",
|
|
26
|
+
localField: "_id",
|
|
27
|
+
foreignField: "labels",
|
|
28
|
+
count: true,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
LabelSchema.virtual("conversations", {
|
|
32
|
+
ref: "Conversation",
|
|
33
|
+
localField: "_id",
|
|
34
|
+
foreignField: "labels",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
LabelSchema.set("toObject", { virtuals: true });
|
|
38
|
+
LabelSchema.set("toJSON", { virtuals: true });
|
|
39
|
+
|
|
40
|
+
const Label = mongoose.model("Label", LabelSchema);
|
|
41
|
+
|
|
42
|
+
module.exports = Label;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const readBySchema = new Schema({
|
|
5
|
+
receiptTrigger: { type: Boolean, default: false },
|
|
6
|
+
readerId: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
7
|
+
readTime: { type: String, default: "" },
|
|
8
|
+
responseTime: { type: String, default: "" },
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const newMessageSchema = new mongoose.Schema(
|
|
12
|
+
{
|
|
13
|
+
workspaceId: {
|
|
14
|
+
type: Schema.Types.ObjectId,
|
|
15
|
+
ref: "Workspace",
|
|
16
|
+
default: null,
|
|
17
|
+
},
|
|
18
|
+
readBy: [readBySchema],
|
|
19
|
+
messageType: {
|
|
20
|
+
type: String,
|
|
21
|
+
enum: [
|
|
22
|
+
"system",
|
|
23
|
+
"user",
|
|
24
|
+
"internal",
|
|
25
|
+
"chatbot",
|
|
26
|
+
"auto-generated",
|
|
27
|
+
"facebook",
|
|
28
|
+
"instagram",
|
|
29
|
+
"webChat",
|
|
30
|
+
"chat-status",
|
|
31
|
+
],
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
conversationId: {
|
|
35
|
+
type: Schema.Types.ObjectId,
|
|
36
|
+
ref: "Conversation",
|
|
37
|
+
default: null,
|
|
38
|
+
},
|
|
39
|
+
conversationType: { type: String },
|
|
40
|
+
activityId: { type: String, default: "" },
|
|
41
|
+
|
|
42
|
+
body: {},
|
|
43
|
+
},
|
|
44
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
module.exports = mongoose.model("Message", newMessageSchema);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const NewProductSchema = new Schema(
|
|
5
|
+
{
|
|
6
|
+
id: {
|
|
7
|
+
type: Schema.Types.ObjectId,
|
|
8
|
+
ref: "Product",
|
|
9
|
+
default: null,
|
|
10
|
+
},
|
|
11
|
+
name: { type: String, default: "" },
|
|
12
|
+
description: { type: String, default: "" },
|
|
13
|
+
sku: { type: String, default: "" },
|
|
14
|
+
price: { type: String, default: 0 },
|
|
15
|
+
quantity: { type: Number, default: 0 },
|
|
16
|
+
imageUrl: { type: String, default: "" },
|
|
17
|
+
costPrice: { type: String, default: 0 },
|
|
18
|
+
salePrice: { type: String, default: 0 },
|
|
19
|
+
webProductId: { type: Number, default: null },
|
|
20
|
+
variants: [],
|
|
21
|
+
attachments: [],
|
|
22
|
+
workspaceId: {
|
|
23
|
+
type: Schema.Types.ObjectId,
|
|
24
|
+
ref: "Workspace",
|
|
25
|
+
default: null,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
timestamps: true,
|
|
30
|
+
toJSON: { virtuals: true },
|
|
31
|
+
toObject: { virtuals: true },
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Adding compound text index for name, sku, and variants
|
|
36
|
+
NewProductSchema.index({
|
|
37
|
+
name: "text",
|
|
38
|
+
sku: "text",
|
|
39
|
+
"variants.name": "text",
|
|
40
|
+
"variants.sku": "text",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Adding separate indexes for frequent query conditions
|
|
44
|
+
NewProductSchema.index({
|
|
45
|
+
workspaceId: 1,
|
|
46
|
+
name: 1,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
NewProductSchema.index({
|
|
50
|
+
workspaceId: 1,
|
|
51
|
+
sku: 1,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
NewProductSchema.index({
|
|
55
|
+
workspaceId: 1,
|
|
56
|
+
"variants.name": 1,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
NewProductSchema.index({
|
|
60
|
+
workspaceId: 1,
|
|
61
|
+
"variants.sku": 1,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Index for attachments existence check
|
|
65
|
+
NewProductSchema.index({
|
|
66
|
+
attachments: 1,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const NewProduct = mongoose.model("NewProduct", NewProductSchema);
|
|
70
|
+
|
|
71
|
+
module.exports = NewProduct;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const { model, Schema } = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const NotificationSettingsSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
workspaceId: {
|
|
6
|
+
type: Schema.Types.ObjectId,
|
|
7
|
+
ref: "Workspace",
|
|
8
|
+
default: null,
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
orders: {
|
|
12
|
+
type: {
|
|
13
|
+
createOrder: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: false,
|
|
16
|
+
},
|
|
17
|
+
orderAssign: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false,
|
|
20
|
+
},
|
|
21
|
+
orderComment: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
default: {
|
|
27
|
+
createOrder: false,
|
|
28
|
+
orderAssign: false,
|
|
29
|
+
orderComment: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
products: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
socialProfiles: {
|
|
39
|
+
type: {
|
|
40
|
+
socialProfileComment: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false,
|
|
43
|
+
},
|
|
44
|
+
story: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
default: {
|
|
50
|
+
socialProfileComment: false,
|
|
51
|
+
story: false,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
conversation: {
|
|
56
|
+
type: {
|
|
57
|
+
instaMessage: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false,
|
|
60
|
+
},
|
|
61
|
+
fbMessage: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false,
|
|
64
|
+
},
|
|
65
|
+
whatsapp: {
|
|
66
|
+
type: Boolean,
|
|
67
|
+
default: false,
|
|
68
|
+
},
|
|
69
|
+
instaComment: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false,
|
|
72
|
+
},
|
|
73
|
+
fbComment: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: false,
|
|
76
|
+
},
|
|
77
|
+
email: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
default: {
|
|
83
|
+
instaMessage: false,
|
|
84
|
+
fbMessage: false,
|
|
85
|
+
instaComment: false,
|
|
86
|
+
fbComment: false,
|
|
87
|
+
email: false,
|
|
88
|
+
whatsapp: false,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
taskManager: {
|
|
93
|
+
type: {
|
|
94
|
+
cardAssign: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: false,
|
|
97
|
+
},
|
|
98
|
+
cardMove: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: false,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
default: {
|
|
104
|
+
cardAssign: false,
|
|
105
|
+
cardMove: false,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
sound: {
|
|
110
|
+
type: {
|
|
111
|
+
play: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: true,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
default: {
|
|
117
|
+
play: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
default: {
|
|
122
|
+
type: Boolean,
|
|
123
|
+
default: true,
|
|
124
|
+
},
|
|
125
|
+
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
126
|
+
},
|
|
127
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
module.exports = model("NotificationSettings", NotificationSettingsSchema);
|
package/models/Order.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
const normalizePhoneNumber = (phone) => {
|
|
4
|
+
let normalized = phone.replace(/[^\d]/g, "");
|
|
5
|
+
if (normalized.startsWith("92")) {
|
|
6
|
+
normalized = normalized.replace(/^92/, "");
|
|
7
|
+
}
|
|
8
|
+
if (normalized.startsWith("0")) {
|
|
9
|
+
normalized = normalized.substring(1);
|
|
10
|
+
}
|
|
11
|
+
return normalized;
|
|
12
|
+
};
|
|
13
|
+
const getPhoneRegex = (phone) => {
|
|
14
|
+
const normalizedPhone = normalizePhoneNumber(phone);
|
|
15
|
+
return new RegExp(
|
|
16
|
+
`^0?${normalizedPhone}$|^\\+92${normalizedPhone}$|^${normalizedPhone}$`,
|
|
17
|
+
"i"
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
const _ = require("lodash");
|
|
21
|
+
|
|
22
|
+
const ShipperInformation = new Schema({
|
|
23
|
+
_id: false,
|
|
24
|
+
shipperType: { type: String, default: "" },
|
|
25
|
+
weight: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
26
|
+
fragile: { type: Boolean, default: false }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
27
|
+
serviceType: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
28
|
+
serviceTypeId: { type: String, default: 1 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
29
|
+
pieces: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
30
|
+
originCityName: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
31
|
+
remarks: { type: String, default: "" },
|
|
32
|
+
customer_note: { type: String, default: "" },
|
|
33
|
+
orderId: { type: Schema.Types.ObjectId, ref: "Order", default: null },
|
|
34
|
+
return_branch: { type: String, default: "" },
|
|
35
|
+
cityData: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
36
|
+
//TRAX
|
|
37
|
+
paymentMode: { type: Number, default: 0 },
|
|
38
|
+
addressId: { type: Number, default: 0 },
|
|
39
|
+
itemProductType: { type: Number, default: 0 },
|
|
40
|
+
shippingMode: { type: Number, default: 0 },
|
|
41
|
+
itemInsurance: { type: Boolean, default: false },
|
|
42
|
+
informationDisplay: { type: String, default: "" },
|
|
43
|
+
//Call Courier (CC)
|
|
44
|
+
shipperName: { type: String, default: "" },
|
|
45
|
+
shipperEmail: { type: String, default: "" },
|
|
46
|
+
shipperCellNo: { type: String, default: "" },
|
|
47
|
+
shipperLandlineNo: { type: String, default: "" },
|
|
48
|
+
shipperAddress: { type: String, default: "" },
|
|
49
|
+
shipperCityId: { type: Number, default: 0 },
|
|
50
|
+
shipperAreaId: { type: Number, default: 0 },
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const OrderSchema = new Schema(
|
|
54
|
+
{
|
|
55
|
+
webOrderId: { type: String, default: "" },
|
|
56
|
+
webOrderNumber: { type: String, default: "" },
|
|
57
|
+
orderNumber: { type: String, default: "" },
|
|
58
|
+
customerId: { type: Schema.Types.ObjectId, ref: "Customer", default: null },
|
|
59
|
+
customerName: { type: String, default: "" },
|
|
60
|
+
customerPhone: { type: String, default: "" },
|
|
61
|
+
customerAddress: { type: String, default: "" },
|
|
62
|
+
cityName: { type: String, default: "" },
|
|
63
|
+
trackingId: { type: String, default: "" },
|
|
64
|
+
shipperInformation: ShipperInformation,
|
|
65
|
+
isCnGenerated: { type: Boolean, default: false },
|
|
66
|
+
swap: { type: String, default: "" },
|
|
67
|
+
status: { type: String, default: "" },
|
|
68
|
+
lastStatusTime: { type: String, default: "" },
|
|
69
|
+
statusType: { type: String, default: "" },
|
|
70
|
+
returnOrder: {
|
|
71
|
+
received: { type: Boolean, default: false },
|
|
72
|
+
restocked: { type: Boolean, default: false },
|
|
73
|
+
remarks: { type: String, default: "" },
|
|
74
|
+
},
|
|
75
|
+
statusTypeId: {
|
|
76
|
+
type: Schema.Types.ObjectId,
|
|
77
|
+
ref: "StatusType",
|
|
78
|
+
default: null,
|
|
79
|
+
},
|
|
80
|
+
statusId: {
|
|
81
|
+
type: Schema.Types.ObjectId,
|
|
82
|
+
ref: "Status",
|
|
83
|
+
default: null,
|
|
84
|
+
},
|
|
85
|
+
totalAmount: { type: Number, default: 0 },
|
|
86
|
+
payableAmount: { type: Number, default: 0 },
|
|
87
|
+
parcelValue: { type: Number, default: 0 },
|
|
88
|
+
payableAmount: { type: Number, default: 0 },
|
|
89
|
+
discountPercentage: { type: Number, default: 0 },
|
|
90
|
+
discountValue: { type: Number, default: 0 },
|
|
91
|
+
productDetails: { type: String, default: "" },
|
|
92
|
+
webOrderId: { type: String, default: "" },
|
|
93
|
+
parentOrderId: { type: Schema.Types.ObjectId, ref: "Order", default: null },
|
|
94
|
+
webOrderNumber: { type: String, default: "" },
|
|
95
|
+
fulfillmentStatus: { type: String, default: "" },
|
|
96
|
+
webFulfillmentId: { type: String, default: "" },
|
|
97
|
+
platformFinancialStatus: { type: String, default: "pending" },
|
|
98
|
+
pinLocation: { type: String, default: "" },
|
|
99
|
+
deliveryCharges: { type: Number, default: 0 },
|
|
100
|
+
tax: { type: Number, default: 0 },
|
|
101
|
+
workspaceId: {
|
|
102
|
+
type: Schema.Types.ObjectId,
|
|
103
|
+
ref: "Workspace",
|
|
104
|
+
default: null,
|
|
105
|
+
},
|
|
106
|
+
orderType: { type: String, default: "" },
|
|
107
|
+
barCode: { type: String, default: "" },
|
|
108
|
+
quantity: { type: Number, default: 0 },
|
|
109
|
+
assignTo: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
110
|
+
isLoadSheetGenerated: { type: Boolean, default: false },
|
|
111
|
+
orderDate: { type: String, default: "" },
|
|
112
|
+
returnDate: { type: String, default: "" },
|
|
113
|
+
receivedDate: { type: String, default: "" },
|
|
114
|
+
published: { type: Boolean, default: false },
|
|
115
|
+
isFlagged: { type: Boolean, default: false },
|
|
116
|
+
publishedTime: { type: String, default: "" },
|
|
117
|
+
paymentType: { type: String, default: "COD" },
|
|
118
|
+
isDeleted: { type: Boolean, default: false },
|
|
119
|
+
isFake: { type: Boolean, default: false },
|
|
120
|
+
statusUpdatedAt: { type: String, default: "" },
|
|
121
|
+
invalidCity: { type: Boolean, default: false },
|
|
122
|
+
invalidCredentials: { type: Boolean, default: false },
|
|
123
|
+
isConfirmed: { type: Boolean, default: false },
|
|
124
|
+
confirmedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
125
|
+
priority: { type: String, default: "" },
|
|
126
|
+
isBulk: { type: String, default: "" },
|
|
127
|
+
conversationId: { type: String, default: "" },
|
|
128
|
+
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
129
|
+
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
130
|
+
publishedStatus: { type: String, default: "pending" },
|
|
131
|
+
isDuplicate: { type: Boolean, default: false },
|
|
132
|
+
ivrGenerated: { type: Boolean, default: false },
|
|
133
|
+
isActivityGenerated: { type: Boolean, default: false },
|
|
134
|
+
payment: {
|
|
135
|
+
isPaid: { type: Boolean, default: false },
|
|
136
|
+
paymentDate: { type: String, default: "" },
|
|
137
|
+
paymentDetails: {},
|
|
138
|
+
},
|
|
139
|
+
credentials: {},
|
|
140
|
+
ticketId: { type: String, default: "" },
|
|
141
|
+
sender: { type: String, default: "" },
|
|
142
|
+
orderName: { type: String, default: "" },
|
|
143
|
+
totalWeight: { type: String, default: "" },
|
|
144
|
+
},
|
|
145
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
OrderSchema.virtual("checkPoints", {
|
|
149
|
+
ref: "Checkpoint",
|
|
150
|
+
localField: "_id",
|
|
151
|
+
foreignField: "orderId",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
OrderSchema.virtual("orderProducts", {
|
|
155
|
+
ref: "OrderProduct",
|
|
156
|
+
localField: "_id",
|
|
157
|
+
foreignField: "orderId",
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
OrderSchema.post("save", async function (doc) {
|
|
161
|
+
try {
|
|
162
|
+
if (doc) {
|
|
163
|
+
markOrUnMarkOrderAsDuplicate(doc);
|
|
164
|
+
}
|
|
165
|
+
return { code: 200 };
|
|
166
|
+
} catch (err) {
|
|
167
|
+
console.log("err", err);
|
|
168
|
+
return { code: 400 };
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
OrderSchema.post("findOneAndUpdate", async function (doc) {
|
|
173
|
+
try {
|
|
174
|
+
if (doc) {
|
|
175
|
+
markOrUnMarkOrderAsDuplicate(doc);
|
|
176
|
+
}
|
|
177
|
+
return { code: 200 };
|
|
178
|
+
} catch (err) {
|
|
179
|
+
console.log("err", err);
|
|
180
|
+
return { code: 400 };
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const markOrUnMarkOrderAsDuplicate = async (doc) => {
|
|
185
|
+
try {
|
|
186
|
+
if (["pending", "cancelled", "published"].includes(doc?.statusType)) {
|
|
187
|
+
if (["cancelled"].includes(doc?.statusType)) {
|
|
188
|
+
await Order.updateOne(
|
|
189
|
+
{ _id: doc?._id },
|
|
190
|
+
{ $set: { isDuplicate: false } }
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const phoneRegex = getPhoneRegex(doc?.customerPhone);
|
|
194
|
+
let orders = await Order.find({
|
|
195
|
+
workspaceId: doc?.workspaceId,
|
|
196
|
+
isDeleted: false,
|
|
197
|
+
statusType: "pending",
|
|
198
|
+
customerPhone: phoneRegex,
|
|
199
|
+
})
|
|
200
|
+
.lean()
|
|
201
|
+
.exec();
|
|
202
|
+
if (orders?.length > 1) {
|
|
203
|
+
const ordersByCity = _.groupBy(orders, "cityName");
|
|
204
|
+
const bulkOps = [];
|
|
205
|
+
for (const cityName in ordersByCity) {
|
|
206
|
+
const cityOrders = ordersByCity[cityName];
|
|
207
|
+
const isDuplicate = cityOrders.length > 1;
|
|
208
|
+
const orderIds = cityOrders.map((order) => order?._id);
|
|
209
|
+
bulkOps.push({
|
|
210
|
+
updateMany: {
|
|
211
|
+
filter: { _id: { $in: orderIds } },
|
|
212
|
+
update: { $set: { isDuplicate } },
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (bulkOps.length > 0) {
|
|
217
|
+
await Order.bulkWrite(bulkOps);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
await Order.updateMany(
|
|
221
|
+
{ _id: { $in: orders.map((d) => d?._id?.toString()) } },
|
|
222
|
+
{ $set: { isDuplicate: false } }
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return { code: 200 };
|
|
226
|
+
}
|
|
227
|
+
return { code: 200 };
|
|
228
|
+
} catch (err) {
|
|
229
|
+
console.log("err", err);
|
|
230
|
+
return { code: 400 };
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const Order = mongoose.model("Order", OrderSchema);
|
|
235
|
+
|
|
236
|
+
module.exports = Order;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { Schema, model } = require("mongoose");
|
|
2
|
+
const OrderProductSchema = new Schema(
|
|
3
|
+
{
|
|
4
|
+
orderId: { type: Schema.Types.ObjectId, ref: "Order", default: null },
|
|
5
|
+
productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
|
|
6
|
+
variantId: {
|
|
7
|
+
type: Schema.Types.ObjectId,
|
|
8
|
+
ref: "ProductVariant",
|
|
9
|
+
default: null,
|
|
10
|
+
},
|
|
11
|
+
locationId: {
|
|
12
|
+
type: Schema.Types.ObjectId,
|
|
13
|
+
ref: "Location",
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
16
|
+
quantity: { type: Number, default: 0 },
|
|
17
|
+
price: { type: Number, default: 0 },
|
|
18
|
+
totalAmount: { type: Number, default: 0 },
|
|
19
|
+
discountPercentage: { type: Number, default: 0 },
|
|
20
|
+
webFulfillmentOrderId: { type: String, default: "" },
|
|
21
|
+
webFulfillmentId: { type: String, default: "" },
|
|
22
|
+
isFullfilled: { type: Boolean, default: false },
|
|
23
|
+
isDeleted: { type: Boolean, default: false },
|
|
24
|
+
discountValue: { type: Number, default: 0 },
|
|
25
|
+
webLineItemId: { type: String, default: "" },
|
|
26
|
+
status: { type: String, default: "open" },
|
|
27
|
+
hyperLink: { type: String, default: "" },
|
|
28
|
+
parentOrderProductId: { type: Schema.Types.ObjectId, default: null },
|
|
29
|
+
workspaceId: {
|
|
30
|
+
type: Schema.Types.ObjectId,
|
|
31
|
+
ref: "Workspace",
|
|
32
|
+
default: null,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
36
|
+
);
|
|
37
|
+
module.exports = model("OrderProduct", OrderProductSchema);
|