shuttlepro-shared 1.1.92 → 1.1.94
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/services/userRoleAndPermissions.js +82 -0
- package/constants/index.js +0 -15
- package/index.js +0 -8
- package/models/Role.js +40 -0
- package/models/UserPermission.js +5 -0
- package/models/UserRole.js +10 -3
- package/models.js +3 -50
- package/package.json +2 -13
- package/utils/index.js +23 -0
- package/common/repositories/descriptionTemplates.repository.js +0 -186
- package/common/repositories/index.js +0 -12
- package/common/repositories/integration.repository.js +0 -197
- package/common/repositories/label.repository.js +0 -85
- package/common/repositories/shipper.repository.js +0 -77
- package/common/repositories/workspace.repository.js +0 -95
- package/config/bull.js +0 -78
- package/config/config.js +0 -14
- package/config/database.js +0 -7
- package/config/index.js +0 -13
- package/config/redis.js +0 -160
- package/config/socket.js +0 -172
- package/models/AgentActivity.js +0 -189
- package/models/Assignment.js +0 -23
- package/models/BusinessDistribution.js +0 -23
- package/models/Card.js +0 -144
- package/models/CardComments.js +0 -33
- package/models/Chatbot.js +0 -16
- package/models/Checkpoint.js +0 -50
- package/models/City.js +0 -17
- package/models/Column.js +0 -28
- package/models/Conversation.js +0 -84
- package/models/Customer.js +0 -35
- package/models/DescriptionTemplate.js +0 -22
- package/models/Integration.js +0 -53
- package/models/Label.js +0 -42
- package/models/Message.js +0 -47
- package/models/Order.js +0 -131
- package/models/OrderProduct.js +0 -37
- package/models/Profile.js +0 -127
- package/models/Report.js +0 -27
- package/models/Shipper.js +0 -52
- package/models/Status.js +0 -58
- package/models/StatusType.js +0 -10
- package/models/Step.js +0 -50
- package/models/Type.js +0 -25
- package/models/Workspace.js +0 -190
- package/utils/decorator-factory.js +0 -264
- package/utils/logger.js +0 -41
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const UserRole = require("../../models/UserRole");
|
|
2
|
+
const { convertPermissionsArrayToObject } = require("../../utils");
|
|
3
|
+
|
|
4
|
+
exports.getUserRoleWithPermissions = async (workspaceId, userId) => {
|
|
5
|
+
try {
|
|
6
|
+
let data = await UserRole.findOne({
|
|
7
|
+
workspaceId: workspaceId,
|
|
8
|
+
userId: userId,
|
|
9
|
+
})
|
|
10
|
+
.populate({
|
|
11
|
+
path: "roleId",
|
|
12
|
+
select:
|
|
13
|
+
"id name userId userShift permissionId modulePermissions defaultModule",
|
|
14
|
+
populate: [{ path: "permissionId", select: "id name" }],
|
|
15
|
+
})
|
|
16
|
+
.lean()
|
|
17
|
+
.exec();
|
|
18
|
+
return {
|
|
19
|
+
...data,
|
|
20
|
+
roleId: data?.roleId?._id?.toString() || "",
|
|
21
|
+
role: data?.roleId?.name || "",
|
|
22
|
+
permissions:
|
|
23
|
+
convertPermissionsArrayToObject(
|
|
24
|
+
data?.roleId?.modulePermissions?.modules
|
|
25
|
+
) || [],
|
|
26
|
+
parentRole: data?.roleId?.permissionId?.name || "",
|
|
27
|
+
parentRoleId: data?.roleId?.permissionId?._id?.toString() || "",
|
|
28
|
+
defaultModule: data?.roleId?.defaultModule || "",
|
|
29
|
+
};
|
|
30
|
+
} catch (err) {
|
|
31
|
+
console.error("Error in getUserRole:", err);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.getUserPermissions = async (workspaceId, userId) => {
|
|
37
|
+
try {
|
|
38
|
+
let data = await UserRole.findOne({
|
|
39
|
+
workspaceId: workspaceId,
|
|
40
|
+
userId: userId,
|
|
41
|
+
})
|
|
42
|
+
.select("roleId userId")
|
|
43
|
+
.populate({
|
|
44
|
+
path: "roleId",
|
|
45
|
+
select: "modulePermissions",
|
|
46
|
+
})
|
|
47
|
+
.lean()
|
|
48
|
+
.exec();
|
|
49
|
+
return (
|
|
50
|
+
convertPermissionsArrayToObject(
|
|
51
|
+
data?.roleId?.modulePermissions?.modules
|
|
52
|
+
) || null
|
|
53
|
+
);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error("Error in getUserRole:", err);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.getChannelsPermissions = async (workspaceId, userId) => {
|
|
61
|
+
try {
|
|
62
|
+
let data = await UserRole.findOne({
|
|
63
|
+
workspaceId: workspaceId,
|
|
64
|
+
userId: userId,
|
|
65
|
+
})
|
|
66
|
+
.select("roleId userId")
|
|
67
|
+
.populate({
|
|
68
|
+
path: "roleId",
|
|
69
|
+
select: "modulePermissions",
|
|
70
|
+
})
|
|
71
|
+
.lean()
|
|
72
|
+
.exec();
|
|
73
|
+
return (
|
|
74
|
+
convertPermissionsArrayToObject(
|
|
75
|
+
data?.roleId?.modulePermissions?.modules
|
|
76
|
+
)?.["coversations"]?.["integrationPermissions"] || []
|
|
77
|
+
);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error("Error in getUserRole:", err);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
package/constants/index.js
CHANGED
|
@@ -23,18 +23,3 @@ exports.GenericMessages = {
|
|
|
23
23
|
URL_FETCH_SUCCESS: "Url Fetched successfully!",
|
|
24
24
|
WORKSPACE_NOT_FOUND: "Workspace not found!",
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
exports.DYNAMIC_FIELD_TYPES = [
|
|
28
|
-
"text",
|
|
29
|
-
"autocomplete",
|
|
30
|
-
"radio",
|
|
31
|
-
"text area",
|
|
32
|
-
"number",
|
|
33
|
-
"date",
|
|
34
|
-
"time",
|
|
35
|
-
"email",
|
|
36
|
-
"range",
|
|
37
|
-
"url",
|
|
38
|
-
"colour",
|
|
39
|
-
"file",
|
|
40
|
-
];
|
package/index.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
const sharedModels = require("./models");
|
|
2
2
|
const sharedFunctions = require("./functions");
|
|
3
|
-
const logger = require("./utils/logger");
|
|
4
|
-
const shuttlePro = require("./utils/decorator-factory");
|
|
5
|
-
const configs = require("./config");
|
|
6
|
-
const repositories = require("./common/repositories");
|
|
7
3
|
|
|
8
4
|
module.exports = {
|
|
9
5
|
sharedModels,
|
|
10
6
|
sharedFunctions,
|
|
11
|
-
logger,
|
|
12
|
-
shuttlePro,
|
|
13
|
-
configs,
|
|
14
|
-
repositories,
|
|
15
7
|
};
|
package/models/Role.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
|
|
4
|
+
const RoleSchema = new Schema(
|
|
5
|
+
{
|
|
6
|
+
name: {
|
|
7
|
+
type: String,
|
|
8
|
+
default: "",
|
|
9
|
+
},
|
|
10
|
+
workspaceId: {
|
|
11
|
+
type: Schema.Types.ObjectId,
|
|
12
|
+
ref: "Workspace",
|
|
13
|
+
default: null,
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: String,
|
|
17
|
+
default: "",
|
|
18
|
+
},
|
|
19
|
+
status: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: "active",
|
|
22
|
+
enum: ["active", "inactive"],
|
|
23
|
+
},
|
|
24
|
+
permissionId: {
|
|
25
|
+
type: Schema.Types.ObjectId,
|
|
26
|
+
ref: "Role",
|
|
27
|
+
default: null,
|
|
28
|
+
},
|
|
29
|
+
defaultModule: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: "conversation",
|
|
32
|
+
},
|
|
33
|
+
modulePermissions: {},
|
|
34
|
+
permissions: [],
|
|
35
|
+
logs: [],
|
|
36
|
+
},
|
|
37
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
module.exports = mongoose.model("Role", RoleSchema);
|
package/models/UserPermission.js
CHANGED
|
@@ -16,6 +16,11 @@ 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
|
+
},
|
|
19
24
|
},
|
|
20
25
|
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
21
26
|
);
|
package/models/UserRole.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
2
3
|
|
|
3
|
-
const daySchema = new
|
|
4
|
+
const daySchema = new Schema({
|
|
4
5
|
day: { type: String, required: true },
|
|
5
6
|
startTime: { type: String, required: false },
|
|
6
7
|
endTime: { type: String, required: false },
|
|
@@ -9,7 +10,7 @@ const daySchema = new mongoose.Schema({
|
|
|
9
10
|
lateThreshold: { type: String, required: false },
|
|
10
11
|
});
|
|
11
12
|
|
|
12
|
-
const userRoleSchema = new
|
|
13
|
+
const userRoleSchema = new Schema(
|
|
13
14
|
{
|
|
14
15
|
userId: {
|
|
15
16
|
type: mongoose.Schema.Types.ObjectId,
|
|
@@ -23,7 +24,12 @@ const userRoleSchema = new mongoose.Schema(
|
|
|
23
24
|
},
|
|
24
25
|
role: {
|
|
25
26
|
type: String,
|
|
26
|
-
|
|
27
|
+
default: "",
|
|
28
|
+
},
|
|
29
|
+
roleId: {
|
|
30
|
+
type: Schema.Types.ObjectId,
|
|
31
|
+
ref: "Role",
|
|
32
|
+
default: null,
|
|
27
33
|
},
|
|
28
34
|
isOwner: { type: Boolean, default: false },
|
|
29
35
|
userShift: {
|
|
@@ -45,6 +51,7 @@ const userRoleSchema = new mongoose.Schema(
|
|
|
45
51
|
);
|
|
46
52
|
|
|
47
53
|
const UserRole = mongoose.model("UserRole", userRoleSchema);
|
|
54
|
+
|
|
48
55
|
module.exports = {
|
|
49
56
|
UserRole,
|
|
50
57
|
};
|
package/models.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const Website = require("./models/Website");
|
|
2
|
-
const DescriptionTemplate = require("./models/DescriptionTemplate");
|
|
3
2
|
const ProductQueue = require("./models/ProductQueue");
|
|
4
3
|
const ColumnPreference = require("./models/ColumnPreference");
|
|
5
4
|
const UserPermission = require("./models/UserPermission");
|
|
@@ -13,30 +12,8 @@ const AutoSchedulerSchema = require("./models/AutoScheduler");
|
|
|
13
12
|
const ActivityLogs = require("./models/ActivityLogs");
|
|
14
13
|
const UserRole = require("./models/UserRole");
|
|
15
14
|
const OrderQueue = require("./models/OrderQueue");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const BusinessDistribution = require("./models/BusinessDistribution");
|
|
19
|
-
const CardComments = require("./models/CardComments");
|
|
20
|
-
const Checkpoint = require("./models/Checkpoint");
|
|
21
|
-
const City = require("./models/City");
|
|
22
|
-
const Column = require("./models/Column");
|
|
23
|
-
const Conversation = require("./models/Conversation");
|
|
24
|
-
const Customer = require("./models/Customer");
|
|
25
|
-
const Integration = require("./models/Integration");
|
|
26
|
-
const Label = require("./models/Label");
|
|
27
|
-
const Message = require("./models/Message");
|
|
28
|
-
const Order = require("./models/Order");
|
|
29
|
-
const OrderProduct = require("./models/OrderProduct");
|
|
30
|
-
const Report = require("./models/Report");
|
|
31
|
-
const Shipper = require("./models/Shipper");
|
|
32
|
-
const Status = require("./models/Status");
|
|
33
|
-
const StatusType = require("./models/StatusType");
|
|
34
|
-
const Type = require("./models/Type");
|
|
35
|
-
const Workspace = require("./models/Workspace");
|
|
36
|
-
const Card = require("./models/Card");
|
|
37
|
-
const Profile = require("./models/Profile");
|
|
38
|
-
const Chatbot = require("./models/Chatbot");
|
|
39
|
-
const Step = require("./models/Step");
|
|
15
|
+
const Role = require("./models/Role");
|
|
16
|
+
|
|
40
17
|
module.exports = {
|
|
41
18
|
Website,
|
|
42
19
|
ProductQueue,
|
|
@@ -52,29 +29,5 @@ module.exports = {
|
|
|
52
29
|
ActivityLogs,
|
|
53
30
|
UserRole,
|
|
54
31
|
OrderQueue,
|
|
55
|
-
|
|
56
|
-
Assignment,
|
|
57
|
-
BusinessDistribution,
|
|
58
|
-
CardComments,
|
|
59
|
-
Checkpoint,
|
|
60
|
-
Column,
|
|
61
|
-
Conversation,
|
|
62
|
-
City,
|
|
63
|
-
Customer,
|
|
64
|
-
Integration,
|
|
65
|
-
Label,
|
|
66
|
-
Message,
|
|
67
|
-
Order,
|
|
68
|
-
OrderProduct,
|
|
69
|
-
Report,
|
|
70
|
-
Shipper,
|
|
71
|
-
Status,
|
|
72
|
-
Type,
|
|
73
|
-
Workspace,
|
|
74
|
-
StatusType,
|
|
75
|
-
Card,
|
|
76
|
-
DescriptionTemplate,
|
|
77
|
-
Profile,
|
|
78
|
-
Chatbot,
|
|
79
|
-
Step,
|
|
32
|
+
Role,
|
|
80
33
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shuttlepro-shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.94",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,18 +11,7 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"access": "restricted",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@babel/core": "^7.22.5",
|
|
15
|
-
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
16
|
-
"@babel/plugin-proposal-decorators": "^7.22.5",
|
|
17
|
-
"@babel/preset-env": "^7.22.5",
|
|
18
|
-
"@babel/register": "^7.22.5",
|
|
19
|
-
"redis": "^4.6.14",
|
|
20
|
-
"express": "^4.17.1",
|
|
21
14
|
"jsonwebtoken": "^9.0.2",
|
|
22
|
-
"mongoose": "^8.7.1"
|
|
23
|
-
"cors": "^2.8.5",
|
|
24
|
-
"helmet": "^8.0.0",
|
|
25
|
-
"bull": "^4.10.4",
|
|
26
|
-
"socket.io": "^4.8.1"
|
|
15
|
+
"mongoose": "^8.7.1"
|
|
27
16
|
}
|
|
28
17
|
}
|
package/utils/index.js
CHANGED
|
@@ -22,3 +22,26 @@ exports.getModule = (obj, module) => {
|
|
|
22
22
|
null
|
|
23
23
|
);
|
|
24
24
|
};
|
|
25
|
+
|
|
26
|
+
exports.convertPermissionsArrayToObject = (originalArray) => {
|
|
27
|
+
return originalArray?.reduce((acc, item) => {
|
|
28
|
+
const { id, actions, integrationPermissions, ...extras } = item;
|
|
29
|
+
const formattedExtras = {};
|
|
30
|
+
if (extras.deletable !== undefined) {
|
|
31
|
+
formattedExtras.deletable = extras.deletable;
|
|
32
|
+
}
|
|
33
|
+
if (extras.createUpdateable !== undefined) {
|
|
34
|
+
formattedExtras.createUpdateable = extras.createUpdateable;
|
|
35
|
+
}
|
|
36
|
+
acc[id] = {
|
|
37
|
+
actions: Object.keys(actions).filter((action) => actions[action]),
|
|
38
|
+
...formattedExtras,
|
|
39
|
+
...(integrationPermissions && {
|
|
40
|
+
integrationPermissions: Object.entries(integrationPermissions)
|
|
41
|
+
.filter(([_, allowed]) => allowed)
|
|
42
|
+
.map(([key]) => key),
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
};
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
// const DescriptionTemplate = require("../../../models/DescriptionTemplate");
|
|
3
|
-
const DescriptionTemplate = require("../../models/DescriptionTemplate");
|
|
4
|
-
|
|
5
|
-
const CACHE_KEY_ALL = "description_templates_all";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get cached descriptionTemplates for all workspaces.
|
|
9
|
-
*/
|
|
10
|
-
const getCachedAllDescriptionTemplates = async () => {
|
|
11
|
-
let descriptionTemplates = await getRedisData(CACHE_KEY_ALL);
|
|
12
|
-
if (!descriptionTemplates) {
|
|
13
|
-
descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
14
|
-
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
15
|
-
}
|
|
16
|
-
return descriptionTemplates;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Update cached descriptionTemplates for all workspaces.
|
|
21
|
-
*/
|
|
22
|
-
const updateCachedAllDescriptionTemplates = async () => {
|
|
23
|
-
const descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
24
|
-
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Get cached descriptionTemplates for a specific workspace.
|
|
29
|
-
* Now uses the all descriptionTemplates cache and filters by workspaceId.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create a new DescriptionTemplate and update cache.
|
|
34
|
-
*/
|
|
35
|
-
const createTemplate = async (data) => {
|
|
36
|
-
const newTemplate = new DescriptionTemplate(data);
|
|
37
|
-
const saveDescriptionTemplate = await newTemplate.save();
|
|
38
|
-
|
|
39
|
-
// Update only the main cache
|
|
40
|
-
await updateCachedAllDescriptionTemplates();
|
|
41
|
-
|
|
42
|
-
return saveDescriptionTemplate;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Find an DescriptionTemplate by ID.
|
|
47
|
-
*/
|
|
48
|
-
const findTemplatesByWorkspaceId = async (workspaceId) => {
|
|
49
|
-
const allDescriptionTemplates = await getCachedAllDescriptionTemplates();
|
|
50
|
-
return allDescriptionTemplates.filter(
|
|
51
|
-
(desc) => desc.workspaceId === workspaceId
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Find DescriptionTemplate by filter (supports both workspace & non-workspace).
|
|
57
|
-
*/
|
|
58
|
-
const findTemplateByFilter = async (
|
|
59
|
-
filter,
|
|
60
|
-
bodyFilter = {},
|
|
61
|
-
workspaceId = null
|
|
62
|
-
) => {
|
|
63
|
-
const allTemplates = await getCachedAllDescriptionTemplates();
|
|
64
|
-
|
|
65
|
-
// Filter by workspaceId if provided
|
|
66
|
-
let filteredTemplates = workspaceId
|
|
67
|
-
? allTemplates.filter((desc) => desc.workspaceId === workspaceId)
|
|
68
|
-
: allTemplates;
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
filteredTemplates.find(
|
|
72
|
-
(item) =>
|
|
73
|
-
// Check direct properties of item
|
|
74
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
75
|
-
// If bodyFilter is provided, check inside item.body
|
|
76
|
-
Object.entries(bodyFilter).every(
|
|
77
|
-
([key, value]) => item.body?.[key] === value
|
|
78
|
-
)
|
|
79
|
-
) || null
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
const createOrUpdateTemplate = async (filter, data) => {
|
|
83
|
-
const template = await DescriptionTemplate.findOneAndUpdate(filter, data, {
|
|
84
|
-
upsert: true,
|
|
85
|
-
new: true,
|
|
86
|
-
});
|
|
87
|
-
if (template) {
|
|
88
|
-
// Update only the main cache
|
|
89
|
-
await updateCachedAllDescriptionTemplates();
|
|
90
|
-
}
|
|
91
|
-
return template;
|
|
92
|
-
};
|
|
93
|
-
const updateTemplateById = async (id, data) => {
|
|
94
|
-
const updatedTemplate = await DescriptionTemplate.findByIdAndUpdate(
|
|
95
|
-
id,
|
|
96
|
-
data,
|
|
97
|
-
{
|
|
98
|
-
new: true,
|
|
99
|
-
}
|
|
100
|
-
).exec();
|
|
101
|
-
|
|
102
|
-
if (updatedTemplate) {
|
|
103
|
-
// Update only the main cache
|
|
104
|
-
await updateCachedAllDescriptionTemplates();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return updatedTemplate;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Update an DescriptionTemplate by filter.
|
|
112
|
-
*/
|
|
113
|
-
const updateTemplateByFilter = async (filter, data, workspaceId = null) => {
|
|
114
|
-
// Add workspace filter if provided
|
|
115
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
116
|
-
|
|
117
|
-
const updatedTemplate = await DescriptionTemplate.findOneAndUpdate(
|
|
118
|
-
queryFilter,
|
|
119
|
-
data,
|
|
120
|
-
{
|
|
121
|
-
new: true,
|
|
122
|
-
}
|
|
123
|
-
).exec();
|
|
124
|
-
|
|
125
|
-
if (updatedTemplate) {
|
|
126
|
-
// Update only the main cache
|
|
127
|
-
await updateCachedAllDescriptionTemplates();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return updatedTemplate;
|
|
131
|
-
};
|
|
132
|
-
const updateManyTemplates = async (filter, data) => {
|
|
133
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
134
|
-
|
|
135
|
-
const updatedTemplate = await DescriptionTemplate.updateMany(
|
|
136
|
-
queryFilter,
|
|
137
|
-
{ $set: { ...data } },
|
|
138
|
-
{
|
|
139
|
-
new: true,
|
|
140
|
-
}
|
|
141
|
-
).exec();
|
|
142
|
-
|
|
143
|
-
if (updatedTemplate) {
|
|
144
|
-
// Update only the main cache
|
|
145
|
-
await updateCachedAllDescriptionTemplates();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return updatedTemplate;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Delete an DescriptionTemplate by ID.
|
|
152
|
-
*/
|
|
153
|
-
const deleteTemplate = async (id) => {
|
|
154
|
-
const deletedTemplate = await DescriptionTemplate.findByIdAndDelete(
|
|
155
|
-
id
|
|
156
|
-
).exec();
|
|
157
|
-
|
|
158
|
-
if (deletedTemplate) {
|
|
159
|
-
// Update only the main cache
|
|
160
|
-
await updateCachedAllDescriptionTemplates();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return deletedTemplate;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Delete all descriptionTemplates for a specific workspace.
|
|
168
|
-
*/
|
|
169
|
-
const deleteAllTemplatesByWorkspace = async (workspaceId) => {
|
|
170
|
-
await DescriptionTemplate.deleteMany({ workspaceId }).exec();
|
|
171
|
-
|
|
172
|
-
// Update only the main cache
|
|
173
|
-
await updateCachedAllDescriptionTemplates();
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
module.exports = {
|
|
177
|
-
createTemplate,
|
|
178
|
-
createOrUpdateTemplate,
|
|
179
|
-
findTemplateByFilter,
|
|
180
|
-
findTemplatesByWorkspaceId,
|
|
181
|
-
updateTemplateById,
|
|
182
|
-
updateTemplateByFilter,
|
|
183
|
-
updateManyTemplates,
|
|
184
|
-
deleteTemplate,
|
|
185
|
-
deleteAllTemplatesByWorkspace,
|
|
186
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const workspaceRepository = require("./workspace.repository");
|
|
2
|
-
const integrationRepository = require("./integration.repository");
|
|
3
|
-
const descriptionTemplateRepository = require("./descriptionTemplates.repository");
|
|
4
|
-
const shipperRepository = require("./shipper.repository");
|
|
5
|
-
const labelRepository = require("./label.repository");
|
|
6
|
-
exports.module = {
|
|
7
|
-
workspaceRepository,
|
|
8
|
-
integrationRepository,
|
|
9
|
-
descriptionTemplateRepository,
|
|
10
|
-
shipperRepository,
|
|
11
|
-
labelRepository,
|
|
12
|
-
};
|