shuttlepro-shared 1.3.14 → 1.3.15

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 (65) hide show
  1. package/common/repositories/chatMember.repository.js +9 -0
  2. package/common/repositories/customerProfile.repository.js +147 -0
  3. package/common/repositories/customerTimeline.repository.js +78 -0
  4. package/common/repositories/descriptionTemplates.repository.js +229 -0
  5. package/common/repositories/index.js +34 -0
  6. package/common/repositories/integration.repository.js +210 -0
  7. package/common/repositories/label.repository.js +95 -0
  8. package/common/repositories/notificationSettings.repository.js +95 -0
  9. package/common/repositories/role.repository.js +333 -0
  10. package/common/repositories/settings.repository.js +32 -0
  11. package/common/repositories/shipper.repository.js +77 -0
  12. package/common/repositories/socialMediaSetting.repository.js +33 -0
  13. package/common/repositories/user.repository.js +150 -0
  14. package/common/repositories/userPermission.repository.js +228 -0
  15. package/common/repositories/userRepository.js +31 -0
  16. package/common/repositories/userRole.repository.js +235 -0
  17. package/common/repositories/userRolePermission.repository.js +59 -0
  18. package/common/repositories/workspace.repository.js +147 -0
  19. package/config/bull.js +78 -0
  20. package/config/config.js +14 -0
  21. package/config/database.js +4 -0
  22. package/config/index.js +13 -0
  23. package/config/redis.js +196 -0
  24. package/config/socket.js +172 -0
  25. package/constants/index.js +15 -0
  26. package/index.js +8 -0
  27. package/models/AgentActivity.js +192 -0
  28. package/models/Assignment.js +23 -0
  29. package/models/BusinessDistribution.js +23 -0
  30. package/models/Card.js +144 -0
  31. package/models/CardComments.js +33 -0
  32. package/models/ChatMember.js +17 -0
  33. package/models/Chatbot.js +20 -0
  34. package/models/Checkpoint.js +50 -0
  35. package/models/City.js +17 -0
  36. package/models/Column.js +28 -0
  37. package/models/Conversation.js +87 -0
  38. package/models/Customer.js +36 -0
  39. package/models/CustomerProfile.js +30 -0
  40. package/models/CustomerTimeline.js +28 -0
  41. package/models/DefaultRolePermission.js +34 -0
  42. package/models/DescriptionTemplate.js +22 -0
  43. package/models/Integration.js +51 -0
  44. package/models/Label.js +42 -0
  45. package/models/Message.js +47 -0
  46. package/models/NewProduct.js +71 -0
  47. package/models/NotificationSettings.js +130 -0
  48. package/models/Order.js +254 -0
  49. package/models/OrderProduct.js +37 -0
  50. package/models/Profile.js +127 -0
  51. package/models/Report.js +27 -0
  52. package/models/Setting.js +18 -0
  53. package/models/Shipper.js +62 -0
  54. package/models/SocialMediaSetting.js +28 -0
  55. package/models/Status.js +58 -0
  56. package/models/StatusType.js +10 -0
  57. package/models/Step.js +50 -0
  58. package/models/Type.js +25 -0
  59. package/models/UserRole.js +1 -119
  60. package/models/UserWorkflow.js +46 -0
  61. package/models/Workspace.js +308 -0
  62. package/models.js +62 -1
  63. package/package.json +13 -2
  64. package/utils/decorator-factory.js +264 -0
  65. package/utils/logger.js +41 -0
@@ -0,0 +1,254 @@
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
+ shipperAdvice: {
143
+ reAttempt: {
144
+ made: { type: Boolean, default: false },
145
+ details: {
146
+ attempt: { type: String, default: "0" },
147
+ remarks: { type: String, default: "" },
148
+ date: { type: String, default: "" },
149
+ },
150
+ },
151
+ return: {
152
+ made: { type: Boolean, default: false },
153
+ details: {
154
+ attempt: { type: String, default: "0" },
155
+ remarks: { type: String, default: "" },
156
+ date: { type: String, default: "" },
157
+ },
158
+ },
159
+ },
160
+ orderName: { type: String, default: "" },
161
+ totalWeight: { type: String, default: "" },
162
+ },
163
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
164
+ );
165
+
166
+ OrderSchema.virtual("checkPoints", {
167
+ ref: "Checkpoint",
168
+ localField: "_id",
169
+ foreignField: "orderId",
170
+ });
171
+
172
+ OrderSchema.virtual("orderProducts", {
173
+ ref: "OrderProduct",
174
+ localField: "_id",
175
+ foreignField: "orderId",
176
+ });
177
+
178
+ OrderSchema.post("save", async function (doc) {
179
+ try {
180
+ if (doc) {
181
+ markOrUnMarkOrderAsDuplicate(doc);
182
+ }
183
+ return { code: 200 };
184
+ } catch (err) {
185
+ console.log("err", err);
186
+ return { code: 400 };
187
+ }
188
+ });
189
+
190
+ OrderSchema.post("findOneAndUpdate", async function (doc) {
191
+ try {
192
+ if (doc) {
193
+ markOrUnMarkOrderAsDuplicate(doc);
194
+ }
195
+ return { code: 200 };
196
+ } catch (err) {
197
+ console.log("err", err);
198
+ return { code: 400 };
199
+ }
200
+ });
201
+
202
+ const markOrUnMarkOrderAsDuplicate = async (doc) => {
203
+ try {
204
+ if (["pending", "cancelled", "published"].includes(doc?.statusType)) {
205
+ if (["cancelled"].includes(doc?.statusType)) {
206
+ await Order.updateOne(
207
+ { _id: doc?._id },
208
+ { $set: { isDuplicate: false } }
209
+ );
210
+ }
211
+ const phoneRegex = getPhoneRegex(doc?.customerPhone);
212
+ let orders = await Order.find({
213
+ workspaceId: doc?.workspaceId,
214
+ isDeleted: false,
215
+ statusType: "pending",
216
+ customerPhone: phoneRegex,
217
+ })
218
+ .lean()
219
+ .exec();
220
+ if (orders?.length > 1) {
221
+ const ordersByCity = _.groupBy(orders, "cityName");
222
+ const bulkOps = [];
223
+ for (const cityName in ordersByCity) {
224
+ const cityOrders = ordersByCity[cityName];
225
+ const isDuplicate = cityOrders.length > 1;
226
+ const orderIds = cityOrders.map((order) => order?._id);
227
+ bulkOps.push({
228
+ updateMany: {
229
+ filter: { _id: { $in: orderIds } },
230
+ update: { $set: { isDuplicate } },
231
+ },
232
+ });
233
+ }
234
+ if (bulkOps.length > 0) {
235
+ await Order.bulkWrite(bulkOps);
236
+ }
237
+ } else {
238
+ await Order.updateMany(
239
+ { _id: { $in: orders.map((d) => d?._id?.toString()) } },
240
+ { $set: { isDuplicate: false } }
241
+ );
242
+ }
243
+ return { code: 200 };
244
+ }
245
+ return { code: 200 };
246
+ } catch (err) {
247
+ console.log("err", err);
248
+ return { code: 400 };
249
+ }
250
+ };
251
+
252
+ const Order = mongoose.model("Order", OrderSchema);
253
+
254
+ 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);
@@ -0,0 +1,127 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+ const { setRedisData, getRedisData } = require("../config/redis");
4
+
5
+ const ProfileSchema = new Schema(
6
+ {
7
+ name: { type: String, default: "" },
8
+ userName: { type: String, default: "" },
9
+ profilePicture: { type: String, default: "" },
10
+ profileId: { type: String, default: "" },
11
+ isSpam: { type: Boolean, default: false },
12
+ workspaceId: { type: String, default: "" },
13
+ email: { type: String, default: "" },
14
+ phoneNo: { type: String, default: "" },
15
+ },
16
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
17
+ );
18
+ const Profile = mongoose.model("Profile", ProfileSchema);
19
+
20
+ const addOrUpdateProfilesInRedis = async (profile) => {
21
+ try {
22
+ const docId = profile?._id.toString();
23
+ let profiles = await fetchProfiles(profile?.workspaceId);
24
+ const profilesMap = profiles.reduce((map, p) => {
25
+ map[p._id.toString()] = p;
26
+ return map;
27
+ }, {});
28
+ profilesMap[docId] = profile.toObject();
29
+ profiles = Object.values(profilesMap);
30
+ setRedisData(`${profile?.workspaceId}-profiles`, profiles);
31
+ return { code: 200 };
32
+ } catch (err) {
33
+ return { code: 400 };
34
+ }
35
+ };
36
+
37
+ const fetchProfiles = async (workspaceId) => {
38
+ try {
39
+ let profiles = await getRedisData(`${workspaceId}-profiles`);
40
+ if (!profiles || profiles.length === 0) {
41
+ profiles = await Profile.find({ workspaceId }).lean().exec();
42
+ setRedisData(`${workspaceId}-profiles`, profiles);
43
+ }
44
+ return profiles;
45
+ } catch (err) {
46
+ return [];
47
+ }
48
+ };
49
+
50
+ const fetchByProfileIdAndWorkspaceId = async (id, workspaceId) => {
51
+ try {
52
+ let profiles = await fetchProfiles(workspaceId);
53
+ let profile = profiles.find(
54
+ (p) =>
55
+ (p?.profileId === id || p._id.toString() === id.toString()) &&
56
+ p?.workspaceId.toString() === workspaceId.toString()
57
+ );
58
+ return profile || null;
59
+ } catch (err) {
60
+ return null;
61
+ }
62
+ };
63
+
64
+ const fetchProfileByEmailAndWorkspaceId = async (
65
+ workspaceId,
66
+ userName = ""
67
+ ) => {
68
+ try {
69
+ let profiles = await fetchProfiles(workspaceId);
70
+ let profile = profiles.find(
71
+ (p) => p?.userName === userName && p?.workspaceId === workspaceId
72
+ );
73
+ return profile || null;
74
+ } catch (err) {
75
+ console.log(err, "err");
76
+ return null;
77
+ }
78
+ };
79
+
80
+ const createProfile = async (obj) => {
81
+ try {
82
+ let profile = await Profile.create(obj);
83
+ await addOrUpdateProfilesInRedis(profile);
84
+ return profile;
85
+ } catch (err) {
86
+ console.log(err, "err");
87
+ return null;
88
+ }
89
+ };
90
+ const createUpdateProfileModified = async (filter, obj) => {
91
+ try {
92
+ let profile = await Profile.findOneAndUpdate(
93
+ filter,
94
+ { ...obj, ...filter },
95
+ {
96
+ new: true,
97
+ upsert: true,
98
+ }
99
+ );
100
+ await addOrUpdateProfilesInRedis(profile);
101
+ return profile;
102
+ } catch (err) {
103
+ console.log(err, "err");
104
+ return null;
105
+ }
106
+ };
107
+ const updateProfile = async (query, payload) => {
108
+ try {
109
+ const profile = await Profile.findOneAndUpdate(query, payload, {
110
+ new: true,
111
+ });
112
+ await addOrUpdateProfilesInRedis(profile);
113
+ return profile;
114
+ } catch (err) {
115
+ return null;
116
+ }
117
+ };
118
+
119
+ module.exports = {
120
+ fetchByProfileIdAndWorkspaceId,
121
+ fetchProfileByEmailAndWorkspaceId,
122
+ createProfile,
123
+ updateProfile,
124
+ fetchProfiles,
125
+ Profile,
126
+ createUpdateProfileModified,
127
+ };
@@ -0,0 +1,27 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const reportSchema = new mongoose.Schema(
4
+ {
5
+ workspaceId: { type: String, default: "" },
6
+ type: {
7
+ type: String,
8
+ default: "",
9
+ },
10
+ title: { type: String, default: "" },
11
+ mode: { type: String, default: "combined" },
12
+ displayType: { type: String, default: "table" },
13
+ filter: {},
14
+ dateRange: {
15
+ startDate: { type: String, default: "" },
16
+ endDate: { type: String, default: "" },
17
+ },
18
+ actions: [],
19
+ processedData: [],
20
+ },
21
+ { timestamps: true }
22
+ );
23
+
24
+ reportSchema.index({ type: 1, workspaceId: 1 });
25
+ reportSchema.index({ type: 1, workspaceId: 1, title: 1 });
26
+
27
+ module.exports = mongoose.model("Report", reportSchema);
@@ -0,0 +1,18 @@
1
+ const { model, Schema } = require("mongoose");
2
+
3
+ const SettingSchema = new Schema(
4
+ {
5
+ workspaceId: {
6
+ type: Schema.Types.ObjectId,
7
+ ref: "Workspace",
8
+ default: null,
9
+ },
10
+ settings: [{ module: { type: String, default: "" }, options: {} }],
11
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
12
+ updateBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
13
+ isDeleted: { type: Boolean, default: false },
14
+ },
15
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
16
+ );
17
+
18
+ module.exports = model("Setting", SettingSchema);
@@ -0,0 +1,62 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const shipperInformationSchema = new Schema({
5
+ weight: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
6
+ fragile: { type: Boolean, default: false }, //M&P, TRAX, INSTA, RIDER, TCS, CC
7
+ serviceType: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
8
+ serviceTypeId: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
9
+ pieces: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
10
+ originCityName: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
11
+ costCenterCode: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
12
+ remarks: { type: String, default: "" },
13
+ customer_note: { type: String, default: "" },
14
+ cityData: { type: String, default: "" },
15
+ return_branch: { type: String, default: "" },
16
+ //M&P, TRAX, INSTA, RIDER, TCS, CC
17
+ //TRAX
18
+ paymentMode: { type: Number, default: 0 },
19
+ addressId: { type: Number, default: 0 }, //this will not be shown
20
+ itemProductType: { type: Number, default: 0 },
21
+ shippingMode: { type: Number, default: 0 },
22
+ itemInsurance: { type: Boolean, default: false }, //this will not be shown
23
+ informationDisplay: { type: String, default: "" },
24
+ //Call Courier (CC)
25
+ shipperId: { type: Number, default: 0 }, //this will not be showm
26
+ shipperName: { type: String, default: "" }, //this will not be shown
27
+ shipperEmail: { type: String, default: "" }, //this will not be shown
28
+ shipperCellNo: { type: String, default: "" }, //this will not be shown
29
+ shipperLandlineNo: { type: String, default: "" }, //this will not be shown
30
+ shipperAddress: { type: String, default: "" }, //this will not be shown
31
+ shipperCityId: { type: Number, default: 0 }, //this will not be shown
32
+ shipperAreaId: { type: Number, default: 0 }, //this will not be shown
33
+ locationId: { type: Number, default: 0 }, //this will not be shown
34
+ });
35
+
36
+ const shipperSchema = new mongoose.Schema(
37
+ {
38
+ type: { type: String, default: "" },
39
+ userName: { type: String, default: "" },
40
+ password: { type: String, default: "" },
41
+ clientId: { type: String, default: "" },
42
+ clientSecret: { type: String, default: "" },
43
+ bearerToken: { type: String, default: "" },
44
+ accessToken: { type: String, default: "" },
45
+ accountNo: { type: String, default: "" },
46
+ businessName: { type: String, default: "" },
47
+ businessPhone: { type: String, default: "" },
48
+ businessAddress: { type: String, default: "" },
49
+ workspaceId: {
50
+ type: Schema.Types.ObjectId,
51
+ ref: "Workspace",
52
+ default: null,
53
+ },
54
+ shipperInformation: shipperInformationSchema,
55
+ isDeleted: { type: Boolean, default: false },
56
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
57
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
58
+ },
59
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
60
+ );
61
+
62
+ module.exports = mongoose.model("shipper", shipperSchema);
@@ -0,0 +1,28 @@
1
+ const { Schema, model } = require("mongoose");
2
+ const SocialMediaSettingSchema = new Schema(
3
+ {
4
+ workspaceId: {
5
+ type: Schema.Types.ObjectId,
6
+ ref: "Workspace",
7
+ default: null,
8
+ },
9
+ approvers: [
10
+ {
11
+ type: Schema.Types.ObjectId,
12
+ ref: "User",
13
+ default: null,
14
+ },
15
+ ],
16
+ publishers: [
17
+ {
18
+ type: Schema.Types.ObjectId,
19
+ ref: "User",
20
+ default: null,
21
+ },
22
+ ],
23
+ defaultApprove: { type: Boolean, default: true },
24
+ defaultPublish: { type: Boolean, default: true },
25
+ },
26
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
27
+ );
28
+ module.exports = model("SocialMediaSetting", SocialMediaSettingSchema);
@@ -0,0 +1,58 @@
1
+ const { Schema, model } = require("mongoose");
2
+ const { setRedisData, getRedisData } = require("../config/redis");
3
+
4
+ const StatusSchema = new Schema(
5
+ {
6
+ value: { type: String, default: "" },
7
+ description: { type: String, default: "" },
8
+ severity: { type: String, default: "1" },
9
+ shipperType: { type: String, default: "" },
10
+ internalValue: { type: String, default: "" },
11
+ statusTypeId: { type: Schema.Types.ObjectId, ref: "StatusType" },
12
+ type: { type: String, default: "" },
13
+ },
14
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
15
+ );
16
+
17
+ StatusSchema.post("save", async function (doc) {
18
+ try {
19
+ addOrUpdateStatusInCache(doc);
20
+ } catch (err) {
21
+ console.log("err", err);
22
+ }
23
+ });
24
+
25
+ StatusSchema.post("findOneAndUpdate", async function (doc) {
26
+ try {
27
+ addOrUpdateStatusInCache(doc);
28
+ } catch (err) {
29
+ console.log("err", err);
30
+ }
31
+ });
32
+
33
+ const addOrUpdateStatusInCache = async (doc) => {
34
+ try {
35
+ const docId = doc?._id.toString();
36
+ let statuses = (await getRedisData("statuses")) || [];
37
+ if (!statuses || statuses.length === 0) {
38
+ // Fetch all statuses from the database if not found in Redis
39
+ const allStatuses = await model("Status").find().lean().exec();
40
+ statuses = allStatuses;
41
+ await setRedisData("statuses", statuses);
42
+ } else {
43
+ const statusesMap = statuses.reduce((map, status) => {
44
+ map[status._id.toString()] = status;
45
+ return map;
46
+ }, {});
47
+ statusesMap[docId] = doc.toObject();
48
+ statuses = Object.values(statusesMap);
49
+ await setRedisData("statuses", statuses);
50
+ }
51
+ return { code: 200 };
52
+ } catch (err) {
53
+ console.log("Error in addOrUpdateOrderInCache:", err);
54
+ return { code: 400 };
55
+ }
56
+ };
57
+
58
+ module.exports = model("Status", StatusSchema);
@@ -0,0 +1,10 @@
1
+ const { Schema, model } = require("mongoose");
2
+
3
+ const StatusTypeSchema = new Schema(
4
+ {
5
+ name: { type: String, default: "" },
6
+ },
7
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
8
+ );
9
+
10
+ module.exports = model("StatusType", StatusTypeSchema);
package/models/Step.js ADDED
@@ -0,0 +1,50 @@
1
+ const { Schema, model } = require("mongoose");
2
+ const StepSchema = new Schema(
3
+ {
4
+ placeholder: {
5
+ type: String,
6
+ default: "",
7
+ },
8
+ input: {
9
+ isRequire: {
10
+ type: Boolean,
11
+ default: false,
12
+ },
13
+ hint: {
14
+ type: String,
15
+ default: "",
16
+ },
17
+ },
18
+ apiCall: {
19
+ type: String,
20
+ default: "",
21
+ },
22
+ templateId: {
23
+ type: Schema.Types.ObjectId,
24
+ ref: "DescriptionTemplate",
25
+ default: null,
26
+ },
27
+ // module: {
28
+ // type: String,
29
+ // enum: ["product", "order", "customer", "general"],
30
+ // default: "general",
31
+ // },
32
+ parentId: {
33
+ type: Schema.Types.ObjectId,
34
+ ref: "Step",
35
+ default: null,
36
+ },
37
+ sortNumber: {
38
+ type: Number,
39
+ default: 0,
40
+ },
41
+ workspaceId: {
42
+ type: Schema.Types.ObjectId,
43
+ ref: "Workspace",
44
+ default: null,
45
+ },
46
+ chatbotId: { type: Schema.Types.ObjectId, ref: "Chatbot", default: null },
47
+ },
48
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
49
+ );
50
+ module.exports = model("Step", StepSchema);