shuttlepro-shared 1.1.85 → 1.1.87
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/descriptionTemplates.repository.js +186 -0
- package/common/repositories/index.js +8 -0
- package/common/repositories/integration.repository.js +197 -0
- package/common/repositories/workspace.repository.js +95 -0
- package/config/bull.js +78 -0
- package/config/config.js +14 -0
- package/config/database.js +7 -0
- package/config/index.js +13 -0
- package/config/redis.js +160 -0
- package/config/socket.js +172 -0
- package/constants/index.js +15 -0
- package/index.js +8 -0
- package/models/AgentActivity.js +189 -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/Chatbot.js +16 -0
- package/models/Checkpoint.js +50 -0
- package/models/City.js +17 -0
- package/models/Column.js +28 -0
- package/models/Conversation.js +84 -0
- package/models/Customer.js +35 -0
- package/models/DescriptionTemplate.js +22 -0
- package/models/Integration.js +53 -0
- package/models/Label.js +42 -0
- package/models/Message.js +47 -0
- package/models/Order.js +131 -0
- package/models/OrderProduct.js +37 -0
- package/models/Profile.js +127 -0
- package/models/Report.js +27 -0
- package/models/Shipper.js +52 -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/UserPermission.js +0 -5
- package/models/UserRole.js +3 -10
- package/models/Workspace.js +190 -0
- package/models.js +50 -3
- package/package.json +13 -2
- package/utils/decorator-factory.js +264 -0
- package/utils/logger.js +41 -0
- package/models/Role.js +0 -35
package/models/Order.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const ShipperInformation = new Schema({
|
|
5
|
+
_id: false,
|
|
6
|
+
shipperType: { type: String, default: "" },
|
|
7
|
+
weight: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
8
|
+
fragile: { type: Boolean, default: false }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
9
|
+
serviceType: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
10
|
+
serviceTypeId: { type: String, default: 1 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
11
|
+
pieces: { type: Number, default: 0 }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
12
|
+
originCityName: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
13
|
+
remarks: { type: String, default: "" },
|
|
14
|
+
customer_note: { type: String, default: "" },
|
|
15
|
+
return_branch: { type: String, default: "" },
|
|
16
|
+
cityData: { type: String, default: "" }, //M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
17
|
+
//TRAX
|
|
18
|
+
paymentMode: { type: Number, default: 0 },
|
|
19
|
+
addressId: { type: Number, default: 0 },
|
|
20
|
+
itemProductType: { type: Number, default: 0 },
|
|
21
|
+
shippingMode: { type: Number, default: 0 },
|
|
22
|
+
itemInsurance: { type: Boolean, default: false },
|
|
23
|
+
informationDisplay: { type: String, default: "" },
|
|
24
|
+
//Call Courier (CC)
|
|
25
|
+
shipperName: { type: String, default: "" },
|
|
26
|
+
shipperEmail: { type: String, default: "" },
|
|
27
|
+
shipperCellNo: { type: String, default: "" },
|
|
28
|
+
shipperLandlineNo: { type: String, default: "" },
|
|
29
|
+
shipperAddress: { type: String, default: "" },
|
|
30
|
+
shipperCityId: { type: Number, default: 0 },
|
|
31
|
+
shipperAreaId: { type: Number, default: 0 },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const OrderSchema = new Schema(
|
|
35
|
+
{
|
|
36
|
+
customerId: { type: Schema.Types.ObjectId, ref: "Customer", default: null },
|
|
37
|
+
swap: { type: String, default: "" },
|
|
38
|
+
shipperInformation: ShipperInformation,
|
|
39
|
+
trackingId: { type: String, default: "" },
|
|
40
|
+
cityName: { type: String, default: "" },
|
|
41
|
+
status: { type: String, default: "" },
|
|
42
|
+
lastStatusTime: { type: String, default: "" },
|
|
43
|
+
statusType: { type: String, default: "" },
|
|
44
|
+
returnOrder: {
|
|
45
|
+
received: { type: Boolean, default: false },
|
|
46
|
+
restocked: { type: Boolean, default: false },
|
|
47
|
+
remarks: { type: String, default: "" },
|
|
48
|
+
},
|
|
49
|
+
statusTypeId: {
|
|
50
|
+
type: Schema.Types.ObjectId,
|
|
51
|
+
ref: "StatusType",
|
|
52
|
+
default: null,
|
|
53
|
+
},
|
|
54
|
+
statusId: {
|
|
55
|
+
type: Schema.Types.ObjectId,
|
|
56
|
+
ref: "Status",
|
|
57
|
+
default: null,
|
|
58
|
+
},
|
|
59
|
+
totalAmount: { type: Number, default: 0 },
|
|
60
|
+
payableAmount: { type: Number, default: 0 },
|
|
61
|
+
parcelValue: { type: Number, default: 0 },
|
|
62
|
+
payableAmount: { type: Number, default: 0 },
|
|
63
|
+
customerName: { type: String, default: "" },
|
|
64
|
+
customerPhone: { type: String, default: "" },
|
|
65
|
+
customerAddress: { type: String, default: "" },
|
|
66
|
+
discountPercentage: { type: Number, default: 0 },
|
|
67
|
+
discountValue: { type: Number, default: 0 },
|
|
68
|
+
productDetails: { type: String, default: "" },
|
|
69
|
+
webOrderId: { type: String, default: "" },
|
|
70
|
+
webOrderNumber: { type: String, default: "" },
|
|
71
|
+
fulfillmentStatus: { type: String, default: "" },
|
|
72
|
+
webFulfillmentId: { type: String, default: "" },
|
|
73
|
+
pinLocation: { type: String, default: "" },
|
|
74
|
+
deliveryCharges: { type: Number, default: 0 },
|
|
75
|
+
tax: { type: Number, default: 0 },
|
|
76
|
+
workspaceId: {
|
|
77
|
+
type: Schema.Types.ObjectId,
|
|
78
|
+
ref: "Workspace",
|
|
79
|
+
default: null,
|
|
80
|
+
},
|
|
81
|
+
orderType: { type: String, default: "" },
|
|
82
|
+
barCode: { type: String, default: "" },
|
|
83
|
+
quantity: { type: Number, default: 0 },
|
|
84
|
+
assignTo: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
85
|
+
isLoadSheetGenerated: { type: Boolean, default: false },
|
|
86
|
+
orderNumber: { type: String, default: "" },
|
|
87
|
+
orderDate: { type: String, default: "" },
|
|
88
|
+
returnDate: { type: String, default: "" },
|
|
89
|
+
receivedDate: { type: String, default: "" },
|
|
90
|
+
published: { type: Boolean, default: false },
|
|
91
|
+
isFlagged: { type: Boolean, default: false },
|
|
92
|
+
publishedTime: { type: String, default: "" },
|
|
93
|
+
paymentType: { type: String, default: "COD" },
|
|
94
|
+
isDeleted: { type: Boolean, default: false },
|
|
95
|
+
isFake: { type: Boolean, default: false },
|
|
96
|
+
statusUpdatedAt: { type: String, default: "" },
|
|
97
|
+
invalidCity: { type: Boolean, default: false },
|
|
98
|
+
invalidCredentials: { type: Boolean, default: false },
|
|
99
|
+
isConfirmed: { type: Boolean, default: false },
|
|
100
|
+
confirmedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
101
|
+
isBulk: { type: String, default: "" },
|
|
102
|
+
priority: { type: String, default: "" },
|
|
103
|
+
conversationId: { type: String, default: "" },
|
|
104
|
+
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
105
|
+
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
106
|
+
publishedStatus: { type: String, default: "pending" },
|
|
107
|
+
isDuplicate: { type: Boolean, default: false },
|
|
108
|
+
ivrGenerated: { type: Boolean, default: false },
|
|
109
|
+
isActivityGenerated: { type: Boolean, default: false },
|
|
110
|
+
platformFinancialStatus: { type: String, default: "pending" },
|
|
111
|
+
payment: {},
|
|
112
|
+
credentials: {},
|
|
113
|
+
},
|
|
114
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
OrderSchema.virtual("checkPoints", {
|
|
118
|
+
ref: "Checkpoint",
|
|
119
|
+
localField: "_id",
|
|
120
|
+
foreignField: "orderId",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
OrderSchema.virtual("orderProducts", {
|
|
124
|
+
ref: "OrderProduct",
|
|
125
|
+
localField: "_id",
|
|
126
|
+
foreignField: "orderId",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const Order = mongoose.model("Order", OrderSchema);
|
|
130
|
+
|
|
131
|
+
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("../utils");
|
|
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
|
+
};
|
package/models/Report.js
ADDED
|
@@ -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,52 @@
|
|
|
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
|
+
remarks: { type: String, default: "" },
|
|
12
|
+
customer_note: { type: String, default: "" },
|
|
13
|
+
cityData: { type: String, default: "" },
|
|
14
|
+
return_branch: { type: String, default: "" },
|
|
15
|
+
//M&P, TRAX, INSTA, RIDER, TCS, CC
|
|
16
|
+
//TRAX
|
|
17
|
+
paymentMode: { type: Number, default: 0 },
|
|
18
|
+
addressId: { type: Number, default: 0 }, //this will not be shown
|
|
19
|
+
itemProductType: { type: Number, default: 0 },
|
|
20
|
+
shippingMode: { type: Number, default: 0 },
|
|
21
|
+
itemInsurance: { type: Boolean, default: false }, //this will not be shown
|
|
22
|
+
informationDisplay: { type: String, default: "" },
|
|
23
|
+
//Call Courier (CC)
|
|
24
|
+
shipperName: { type: String, default: "" }, //this will not be shown
|
|
25
|
+
shipperEmail: { type: String, default: "" }, //this will not be shown
|
|
26
|
+
shipperCellNo: { type: String, default: "" }, //this will not be shown
|
|
27
|
+
shipperLandlineNo: { type: String, default: "" }, //this will not be shown
|
|
28
|
+
shipperAddress: { type: String, default: "" }, //this will not be shown
|
|
29
|
+
shipperCityId: { type: Number, default: 0 }, //this will not be shown
|
|
30
|
+
shipperAreaId: { type: Number, default: 0 }, //this will not be shown
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const shipperSchema = new mongoose.Schema(
|
|
34
|
+
{
|
|
35
|
+
type: { type: String, default: "" },
|
|
36
|
+
userName: { type: String, default: "" },
|
|
37
|
+
password: { type: String, default: "" },
|
|
38
|
+
clientId: { type: String, default: "" },
|
|
39
|
+
workspaceId: {
|
|
40
|
+
type: Schema.Types.ObjectId,
|
|
41
|
+
ref: "Workspace",
|
|
42
|
+
default: null,
|
|
43
|
+
},
|
|
44
|
+
shipperInformation: shipperInformationSchema,
|
|
45
|
+
isDeleted: { type: Boolean, default: false },
|
|
46
|
+
createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
47
|
+
updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
|
|
48
|
+
},
|
|
49
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
module.exports = mongoose.model("shipper", shipperSchema);
|
package/models/Status.js
ADDED
|
@@ -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);
|
package/models/Type.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const typeSchema = new mongoose.Schema(
|
|
4
|
+
{
|
|
5
|
+
title: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true,
|
|
8
|
+
},
|
|
9
|
+
deleted: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: false,
|
|
12
|
+
},
|
|
13
|
+
workspaceId: { type: String, default: "" },
|
|
14
|
+
color: { type: String, default: "#4a90e2", required: true },
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
typeSchema.virtual("cardList", {
|
|
20
|
+
ref: "Card",
|
|
21
|
+
localField: "_id",
|
|
22
|
+
foreignField: "typeId",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
module.exports = mongoose.model("Type", typeSchema);
|
package/models/UserPermission.js
CHANGED
|
@@ -16,11 +16,6 @@ const UserPermissionsSchema = new Schema(
|
|
|
16
16
|
type: String,
|
|
17
17
|
default: "",
|
|
18
18
|
},
|
|
19
|
-
roleId: {
|
|
20
|
-
type: Schema.Types.ObjectId,
|
|
21
|
-
ref: "Role",
|
|
22
|
-
default: null,
|
|
23
|
-
},
|
|
24
19
|
},
|
|
25
20
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
26
21
|
);
|
package/models/UserRole.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const mongoose = require("mongoose");
|
|
2
|
-
const { Schema } = mongoose;
|
|
3
2
|
|
|
4
|
-
const daySchema = new Schema({
|
|
3
|
+
const daySchema = new mongoose.Schema({
|
|
5
4
|
day: { type: String, required: true },
|
|
6
5
|
startTime: { type: String, required: false },
|
|
7
6
|
endTime: { type: String, required: false },
|
|
@@ -10,7 +9,7 @@ const daySchema = new Schema({
|
|
|
10
9
|
lateThreshold: { type: String, required: false },
|
|
11
10
|
});
|
|
12
11
|
|
|
13
|
-
const userRoleSchema = new Schema(
|
|
12
|
+
const userRoleSchema = new mongoose.Schema(
|
|
14
13
|
{
|
|
15
14
|
userId: {
|
|
16
15
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -24,12 +23,7 @@ const userRoleSchema = new Schema(
|
|
|
24
23
|
},
|
|
25
24
|
role: {
|
|
26
25
|
type: String,
|
|
27
|
-
|
|
28
|
-
},
|
|
29
|
-
roleId: {
|
|
30
|
-
type: Schema.Types.ObjectId,
|
|
31
|
-
ref: "Role",
|
|
32
|
-
default: null,
|
|
26
|
+
enum: ["admin", "agent", "storeManager", "socialMediaManager"],
|
|
33
27
|
},
|
|
34
28
|
isOwner: { type: Boolean, default: false },
|
|
35
29
|
userShift: {
|
|
@@ -51,7 +45,6 @@ const userRoleSchema = new Schema(
|
|
|
51
45
|
);
|
|
52
46
|
|
|
53
47
|
const UserRole = mongoose.model("UserRole", userRoleSchema);
|
|
54
|
-
|
|
55
48
|
module.exports = {
|
|
56
49
|
UserRole,
|
|
57
50
|
};
|