shuttlepro-shared 1.1.58 → 1.1.59

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.
@@ -0,0 +1,189 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const breakSchema = new mongoose.Schema({
5
+ refId: { type: String, required: true },
6
+ breakId: { type: String, required: false },
7
+ startTime: { type: Date, required: true },
8
+ endTime: { type: Date, required: false },
9
+ });
10
+
11
+ const responseSchema = new mongoose.Schema({
12
+ queryMessageId: { type: [String], default: [] },
13
+ responseMessageId: { type: [String], default: [] },
14
+ responseTime: { type: Number, required: false },
15
+ accuracy: { type: Number, required: false, default: 10 },
16
+ });
17
+
18
+ const activitySchema = new mongoose.Schema({
19
+ refId: { type: String, required: true },
20
+ type: {
21
+ type: String,
22
+ required: true,
23
+ default: "other",
24
+ enum: ["conversation", "ticket", "order", "other"],
25
+ },
26
+ platformName: { type: String, required: false },
27
+ platformType: { type: String, required: false },
28
+ customerName: { type: String, default: "", required: false },
29
+ conversationId: { type: String, default: "", required: false },
30
+ profileId: { type: String, required: false },
31
+ conversationType: {
32
+ type: String,
33
+ enum: ["email", "comment", "message", ""],
34
+ default: "",
35
+ required: false,
36
+ },
37
+ status: { type: String, required: false, default: "unassigned" },
38
+ labels: [{ type: Schema.Types.ObjectId, ref: "Label" }],
39
+ platformId: { type: String, required: false },
40
+ assignTime: { type: Date, required: false },
41
+ qaScore: { type: Number, required: false, default: 10 },
42
+ startTime: { type: String, required: false },
43
+ endTime: { type: String, required: false },
44
+ resolutionTime: { type: String, required: false },
45
+ responses: { type: [responseSchema], default: [] },
46
+ remarks: { type: String, required: false },
47
+ avgAccuracy: { type: Number, required: false, default: 10 },
48
+ });
49
+
50
+ const totalActivitySchema = new mongoose.Schema({
51
+ type: { type: String, required: true },
52
+ platformType: { type: String, required: false },
53
+ count: { type: Number, required: true },
54
+ });
55
+
56
+ const agentActivitySchema = new mongoose.Schema(
57
+ {
58
+ _id: {
59
+ type: mongoose.Schema.Types.ObjectId,
60
+ default: mongoose.Types.ObjectId,
61
+ },
62
+ agentId: { type: String, required: true },
63
+ agentRole: { type: String, default: "" },
64
+ agentName: { type: String, required: false },
65
+ agentShift: { type: Object, default: {}, required: false },
66
+ workspaceId: {
67
+ type: mongoose.Schema.Types.ObjectId,
68
+ required: true,
69
+ ref: "Workspace",
70
+ },
71
+ date: { type: String, required: true },
72
+ lateMinutes: {
73
+ type: Number,
74
+ default: 0,
75
+ },
76
+ earlyLeaveMinutes: {
77
+ type: Number,
78
+ default: 0,
79
+ },
80
+ shiftStartTime: { type: [Date], default: [] },
81
+ shiftEndTime: { type: [Date], default: [] },
82
+ shifts: [
83
+ {
84
+ shiftStartTime: { type: Date, required: true, default: null },
85
+ shiftEndTime: { type: Date, required: false, default: null },
86
+ },
87
+ ],
88
+ isLate: { type: Boolean, required: true, default: false },
89
+ isEarlyLeave: { type: Boolean, required: true, default: false },
90
+ breaks: { type: [breakSchema], default: [] },
91
+ activities: { type: [activitySchema], default: [] },
92
+ totalPsc: { type: Number, required: false, default: 0 },
93
+ totalQa: { type: Number, required: false, default: 0 },
94
+ weightedQa: { type: Number, required: false, default: 0 },
95
+ weightedPsc: { type: Number, required: false, default: 0 },
96
+ kpiScore: { type: Number, required: false, default: 0 },
97
+ totalActivities: { type: [totalActivitySchema], default: [] },
98
+ totalWorkTime: { type: Number, required: false, default: 0 },
99
+ totalBreakTime: { type: Number, required: false, default: 0 },
100
+ totalIdleTime: { type: Number, required: false, default: 0 },
101
+ },
102
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
103
+ );
104
+
105
+ agentActivitySchema.index({ workspaceId: 1 });
106
+ agentActivitySchema.index({ date: 1 });
107
+ agentActivitySchema.index({ agentId: 1 });
108
+ agentActivitySchema.index({ "activities.platformId": 1 });
109
+ agentActivitySchema.index({ "activities.labels": 1 });
110
+ agentActivitySchema.index({ workspaceId: 1, date: 1, agentId: 1 });
111
+ agentActivitySchema.index({
112
+ workspaceId: 1,
113
+ date: 1,
114
+ agentId: 1,
115
+ "activities.platformId": 1,
116
+ "activities.labels": 1,
117
+ });
118
+ agentActivitySchema.index({
119
+ workspaceId: 1,
120
+ date: 1,
121
+ agentId: 1,
122
+ "activities.platformId": 1,
123
+ });
124
+ agentActivitySchema.index({
125
+ workspaceId: 1,
126
+ date: 1,
127
+ agentId: 1,
128
+ "activities.labels": 1,
129
+ });
130
+ agentActivitySchema.index(
131
+ { "activities.platformId": 1, "activities.labels": 1 },
132
+ {
133
+ partialFilterExpression: {
134
+ "activities.platformId": { $exists: true },
135
+ "activities.labels": { $exists: true },
136
+ },
137
+ }
138
+ );
139
+ const AgentActivity = mongoose.model("AgentActivity", agentActivitySchema);
140
+
141
+ const findOneAndUpdateAgentActivity = async (
142
+ findQuery = {},
143
+ updateQuery = null
144
+ ) => {
145
+ try {
146
+ if (!findQuery || Object.values(findQuery).length === 0) {
147
+ console.log("Find Query is required.");
148
+ return null;
149
+ }
150
+
151
+ const agentActivityForActivitiesUpdated = await AgentActivity.findOne(
152
+ findQuery
153
+ ).sort({ createdAt: -1 });
154
+
155
+ if (!agentActivityForActivitiesUpdated) {
156
+ console.log("No matching record found.");
157
+ return null;
158
+ }
159
+
160
+ const bsonSize = require("bson").calculateObjectSize(
161
+ agentActivityForActivitiesUpdated
162
+ );
163
+
164
+ if (bsonSize <= 1000000) {
165
+ return await AgentActivity.findOneAndUpdate(findQuery, updateQuery);
166
+ } else {
167
+ const { breaks, activities, totalActivities, ...restData } =
168
+ agentActivityForActivitiesUpdated.toObject();
169
+
170
+ const newAgentActivity = await AgentActivity.create({
171
+ ...restData,
172
+ });
173
+
174
+ const agentActivityRecord = await AgentActivity.findOneAndUpdate(
175
+ { ...findQuery, _id: newAgentActivity._id },
176
+ updateQuery
177
+ );
178
+
179
+ return agentActivityRecord;
180
+ }
181
+ } catch (err) {
182
+ console.error("Error:", err);
183
+ return null;
184
+ }
185
+ };
186
+ module.exports = {
187
+ AgentActivity,
188
+ findOneAndUpdateAgentActivity,
189
+ };
@@ -0,0 +1,23 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const assignmentSchema = new mongoose.Schema({
4
+ cardId: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ ref: "Card",
7
+ required: true,
8
+ },
9
+ id: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ name: {
14
+ type: String,
15
+ },
16
+ email: {
17
+ type: String,
18
+ },
19
+ });
20
+
21
+ const Assignment = mongoose.model("Assignment", assignmentSchema);
22
+
23
+ module.exports = Assignment;
@@ -0,0 +1,23 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const businessDistributionSchema = new mongoose.Schema(
5
+ {
6
+ name: { type: String, default: "" },
7
+ deliveryCharges: { type: String, default: "" },
8
+ shippers: [],
9
+ type: {
10
+ type: String,
11
+ enum: ["default", "cities"],
12
+ required: true,
13
+ },
14
+ index: { type: String, default: "" },
15
+ workspaceId: { type: String, default: "" },
16
+ },
17
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
18
+ );
19
+
20
+ module.exports = mongoose.model(
21
+ "BusinessDistribution",
22
+ businessDistributionSchema
23
+ );
package/models/Card.js ADDED
@@ -0,0 +1,144 @@
1
+ const mongoose = require("mongoose");
2
+ const { DYNAMIC_FIELD_TYPES } = require("../constants");
3
+
4
+ const cardSchema = new mongoose.Schema(
5
+ {
6
+ cardId: { type: String, required: true },
7
+ columnId: {
8
+ type: mongoose.Schema.Types.ObjectId,
9
+ ref: "Column",
10
+ required: false,
11
+ default: null,
12
+ set: (v) => (v === "" ? null : v),
13
+ },
14
+ title: {
15
+ type: String,
16
+ default: "",
17
+ // required: true,
18
+ },
19
+ description: {
20
+ type: String,
21
+ },
22
+ priority: {
23
+ type: String,
24
+ enum: ["high", "medium", "low"],
25
+ },
26
+ typeId: [
27
+ {
28
+ type: mongoose.Schema.Types.ObjectId,
29
+ ref: "Label",
30
+ },
31
+ ],
32
+ type: {
33
+ type: String,
34
+ required: true,
35
+ },
36
+ assignedBy: {
37
+ type: Object,
38
+ },
39
+ attachmentId: {
40
+ type: mongoose.Schema.Types.ObjectId,
41
+ ref: "Attachment",
42
+ },
43
+ attachments: {
44
+ type: [String],
45
+ default: [],
46
+ },
47
+ product: {
48
+ type: Object,
49
+ },
50
+ courierId: {
51
+ type: String,
52
+ },
53
+ orderId: {
54
+ type: Object,
55
+ },
56
+ conversation: {
57
+ type: Object,
58
+ },
59
+ deleted: {
60
+ type: Boolean,
61
+ default: false,
62
+ },
63
+ isExpired: {
64
+ type: Boolean,
65
+ default: false,
66
+ },
67
+ isUpdated: {
68
+ type: Boolean,
69
+ default: false,
70
+ },
71
+ completionDate: {
72
+ type: String,
73
+ },
74
+ updatedDate: {
75
+ type: Date,
76
+ default: Date.now,
77
+ },
78
+ ticketId: {
79
+ type: Number,
80
+ },
81
+ category: {
82
+ type: String,
83
+ default: "ticket",
84
+ enum: ["ticket", "conversation"],
85
+ },
86
+ dynamicFieldValue: [
87
+ {
88
+ dynamicFieldId: {
89
+ type: String,
90
+ default: "",
91
+ },
92
+ fieldType: {
93
+ type: String,
94
+ enum: DYNAMIC_FIELD_TYPES,
95
+ },
96
+ fieldValueId: {
97
+ type: mongoose.Schema.Types.Mixed,
98
+ },
99
+ },
100
+ ],
101
+ workspaceId: { type: String, default: "" },
102
+ activities: [
103
+ {
104
+ data: {
105
+ type: mongoose.Schema.Types.Mixed,
106
+ default: {},
107
+ },
108
+ },
109
+ ],
110
+ },
111
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
112
+ );
113
+
114
+ cardSchema.index({ workspaceId: 1, createdAt: 1 }); // Common filter
115
+
116
+ // Virtual for the assignedTo user
117
+ cardSchema.virtual("assignedToUser", {
118
+ ref: "User",
119
+ localField: "assignedTo",
120
+ foreignField: "_id",
121
+ });
122
+
123
+ // Virtual for the attachment
124
+ cardSchema.virtual("attachment", {
125
+ ref: "Attachment",
126
+ localField: "attachmentId",
127
+ foreignField: "_id",
128
+ });
129
+
130
+ // Virtual for the comment
131
+ cardSchema.virtual("comments", {
132
+ ref: "CardComment",
133
+ localField: "_id",
134
+ foreignField: "cardId",
135
+ });
136
+
137
+ // Virtual for the assignmentList
138
+ cardSchema.virtual("assignedTo", {
139
+ ref: "Assignment",
140
+ localField: "_id", // Change to 'cardId' to match the 'cardId' field in the Assignment model
141
+ foreignField: "cardId",
142
+ });
143
+
144
+ module.exports = mongoose.model("Card", cardSchema);
@@ -0,0 +1,33 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const cardCommentSchema = new mongoose.Schema(
4
+ {
5
+ cardId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: "Card",
8
+ required: true,
9
+ },
10
+ commentText: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ createdBy: {
15
+ type: Object,
16
+ required: true,
17
+ },
18
+ readers: {
19
+ type: [],
20
+ default: [],
21
+ },
22
+ deleted: {
23
+ type: Boolean,
24
+ default: false,
25
+ },
26
+ updatedDate: {
27
+ type: Date,
28
+ },
29
+ },
30
+ { timestamps: true }
31
+ );
32
+
33
+ module.exports = mongoose.model("CardComment", cardCommentSchema);
@@ -0,0 +1,50 @@
1
+ const { Schema, model } = require("mongoose");
2
+ const Order = require("./Order");
3
+ const CheckpointSchema = new Schema(
4
+ {
5
+ bookingDate: { type: String, default: "" },
6
+ shipperType: { type: String, default: "" },
7
+ statusTime: { type: String, default: "" },
8
+ orderId: { type: Schema.Types.ObjectId, default: null, ref: "Order" },
9
+ statusId: { type: Schema.Types.ObjectId, default: null, ref: "Status" },
10
+ statusValue: { type: String, default: "" },
11
+ description: { type: String, default: "" },
12
+ workspaceId: {
13
+ type: Schema.Types.ObjectId,
14
+ ref: "Workspace",
15
+ default: null,
16
+ },
17
+ },
18
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
19
+ );
20
+
21
+ const initialStatuses = {
22
+ POSTEX: "departed to postex. warehouse",
23
+ DAEWOO: "booking",
24
+ TRAX: "shipment - arrived at origin",
25
+ };
26
+
27
+ CheckpointSchema.post("save", async function (doc) {
28
+ try {
29
+ if (
30
+ doc?.shipperType &&
31
+ doc?.statusValue.toLowerCase() === initialStatuses[doc?.shipperType]
32
+ ) {
33
+ let order = await Order.findOneAndUpdate(
34
+ {
35
+ _id: doc.orderId,
36
+ workspaceId: doc.workspaceId,
37
+ },
38
+ { $set: { statusUpdatedAt: doc.bookingDate } },
39
+ { new: true }
40
+ );
41
+ console.log(order, "initial status from shipper");
42
+ }
43
+ return { code: 200 };
44
+ } catch (err) {
45
+ console.log("err", err);
46
+ return { code: 400 };
47
+ }
48
+ });
49
+
50
+ module.exports = model("Checkpoint", CheckpointSchema);
package/models/City.js ADDED
@@ -0,0 +1,17 @@
1
+ const { Schema, model } = require("mongoose");
2
+
3
+ const CitySchema = new Schema(
4
+ {
5
+ cityName: { type: String, default: "" },
6
+ correctedCityName: { type: String, default: "" },
7
+ cityCode: { type: String, default: "" },
8
+ area: { type: String, default: "" },
9
+ shipperType: { type: String, default: "" },
10
+ webCityId: { type: String, default: "" },
11
+ hubId: { type: String, default: "" },
12
+ body: {},
13
+ },
14
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
15
+ );
16
+
17
+ module.exports = model("City", CitySchema);
@@ -0,0 +1,28 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const columnSchema = new mongoose.Schema(
4
+ {
5
+ title: {
6
+ type: String,
7
+ required: true,
8
+ },
9
+ position: {
10
+ type: Number,
11
+ required: true,
12
+ },
13
+ deleted: {
14
+ type: Boolean,
15
+ default: false,
16
+ },
17
+ workspaceId: { type: String, default: "" },
18
+ },
19
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
20
+ );
21
+
22
+ columnSchema.virtual("cardList", {
23
+ ref: "Card",
24
+ localField: "_id", // Change to '_id' to match the column's '_id'
25
+ foreignField: "columnId",
26
+ });
27
+
28
+ module.exports = mongoose.model("Column", columnSchema);
@@ -0,0 +1,84 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const draftSchema = new mongoose.Schema({
5
+ _id: {
6
+ type: Schema.Types.ObjectId,
7
+ default: () => new mongoose.Types.ObjectId(),
8
+ },
9
+ messageBody: {},
10
+ createdBy: { type: Schema.Types.ObjectId, ref: "User" },
11
+ });
12
+
13
+ const conversationSchema = new mongoose.Schema(
14
+ {
15
+ platformType: {
16
+ type: String,
17
+ enum: [
18
+ "gmail",
19
+ "instagram",
20
+ "whatsapp",
21
+ "linkedin",
22
+ "facebook",
23
+ "tiktok",
24
+ "webChat",
25
+ "smtp_gmail",
26
+ ],
27
+ required: true,
28
+ },
29
+ members: [{ type: Schema.Types.ObjectId, ref: "User" }],
30
+ conversationType: {
31
+ type: String,
32
+ enum: ["comment", "message", "email"],
33
+ required: true,
34
+ },
35
+ messageCount: { type: Number, default: 0 },
36
+ conversationStatus: {
37
+ type: String,
38
+ enum: ["assigned", "unassigned", "archived"],
39
+ required: true,
40
+ default: "unassigned",
41
+ },
42
+ assignId: { type: Schema.Types.ObjectId, ref: "User", default: null },
43
+ platformId: {
44
+ type: Schema.Types.ObjectId,
45
+ ref: "Integration",
46
+ default: null,
47
+ },
48
+ labels: [{ type: Schema.Types.ObjectId, ref: "Label" }],
49
+ title: { type: String },
50
+ platformTimestamp: { type: String, default: "" },
51
+ status: {
52
+ type: String,
53
+ enum: ["open", "processing", "hold", "closed"],
54
+ required: true,
55
+ default: "open",
56
+ },
57
+ isSpam: { type: Boolean, default: false },
58
+ threadId: { type: String, default: "" },
59
+ messageId: { type: String, default: "" },
60
+ profileId: { type: Schema.Types.ObjectId, ref: "Profile" },
61
+ conversationCloseTime: { type: String },
62
+ workspaceId: { type: Schema.Types.ObjectId, ref: "Workspace" },
63
+ postId: { type: String, default: "" },
64
+ postUrl: { type: String, default: "" },
65
+ sender: { type: String, default: "" },
66
+ reasonForClosing: {
67
+ reason: { type: String, default: "" },
68
+ closedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
69
+ },
70
+ integratedAccount: { type: String, default: "" },
71
+ isRead: { type: Boolean, default: false },
72
+ ticketId: { type: String, default: "" },
73
+ draft: [draftSchema],
74
+ isWebchatTicket: { type: Boolean, default: false },
75
+ webchatComplaintType: { type: String, default: null },
76
+ isComposed: { type: Boolean, default: false },
77
+ utilityMessage: [],
78
+ orderId: [],
79
+ isFetch: { type: Boolean, default: true },
80
+ },
81
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
82
+ );
83
+
84
+ module.exports = mongoose.model("Conversation", conversationSchema);
@@ -0,0 +1,35 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const CustomerSchema = new Schema(
5
+ {
6
+ name: { type: String, default: "" },
7
+ email: { type: String, default: "" },
8
+ phone: { type: String, default: "" },
9
+ city: { type: String, default: "" },
10
+ defaultAddress: { type: String, default: "" },
11
+ currentShippingAddress: {},
12
+ addresses: [],
13
+ workspaceId: {
14
+ type: Schema.Types.ObjectId,
15
+ ref: "Workspace",
16
+ default: null,
17
+ },
18
+ phone1: { type: String, default: "" },
19
+ isBlackListed: { type: Boolean, default: false },
20
+ createdBy: {
21
+ type: Schema.Types.ObjectId,
22
+ ref: "User",
23
+ },
24
+ updatedBy: {
25
+ type: Schema.Types.ObjectId,
26
+ ref: "User",
27
+ },
28
+ isDeleted: { type: Boolean, default: false },
29
+ },
30
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
31
+ );
32
+
33
+ const Customer = mongoose.model("Customer", CustomerSchema);
34
+
35
+ module.exports = Customer;
@@ -0,0 +1,53 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const IntegrationSchema = new mongoose.Schema(
5
+ {
6
+ workspaceId: {
7
+ type: Schema.Types.ObjectId,
8
+ ref: "Workspace",
9
+ default: null,
10
+ },
11
+ type: {
12
+ type: String,
13
+ enum: [
14
+ "socialPlatforms",
15
+ "whatsapp",
16
+ "gmail",
17
+ "sms",
18
+ "map",
19
+ "facebook",
20
+ "instagram",
21
+ "webChat",
22
+ "smtp_gmail",
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: { type: Schema.Types.ObjectId, ref: "Chatbot", default: null },
36
+ members: [
37
+ {
38
+ type: Schema.Types.ObjectId,
39
+ ref: "User",
40
+ },
41
+ ],
42
+ body: {},
43
+ },
44
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
45
+ );
46
+
47
+ IntegrationSchema.virtual("conversations", {
48
+ ref: "Conversation",
49
+ localField: "_id",
50
+ foreignField: "platformId",
51
+ });
52
+
53
+ module.exports = mongoose.model("Integration", IntegrationSchema);