shuttlepro-shared 1.1.89 → 1.1.91
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.
|
@@ -10,7 +10,7 @@ const CACHE_KEY_ALL = "description_templates_all";
|
|
|
10
10
|
const getCachedAllDescriptionTemplates = async () => {
|
|
11
11
|
let descriptionTemplates = await getRedisData(CACHE_KEY_ALL);
|
|
12
12
|
if (!descriptionTemplates) {
|
|
13
|
-
descriptionTemplates = await DescriptionTemplate.find({}).exec();
|
|
13
|
+
descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
14
14
|
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
15
15
|
}
|
|
16
16
|
return descriptionTemplates;
|
|
@@ -20,7 +20,7 @@ const getCachedAllDescriptionTemplates = async () => {
|
|
|
20
20
|
* Update cached descriptionTemplates for all workspaces.
|
|
21
21
|
*/
|
|
22
22
|
const updateCachedAllDescriptionTemplates = async () => {
|
|
23
|
-
const descriptionTemplates = await DescriptionTemplate.find({}).exec();
|
|
23
|
+
const descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
24
24
|
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const workspaceRepository = require("./workspace.repository");
|
|
2
2
|
const integrationRepository = require("./integration.repository");
|
|
3
3
|
const descriptionTemplateRepository = require("./descriptionTemplates.repository");
|
|
4
|
+
const shipperRepository = require("./shipper.repository");
|
|
4
5
|
exports.module = {
|
|
5
6
|
workspaceRepository,
|
|
6
7
|
integrationRepository,
|
|
7
8
|
descriptionTemplateRepository,
|
|
9
|
+
shipperRepository,
|
|
8
10
|
};
|
|
@@ -9,7 +9,7 @@ const CACHE_KEY_ALL = "integrations_all";
|
|
|
9
9
|
const getCachedAllIntegrations = async () => {
|
|
10
10
|
let integrations = await getRedisData(CACHE_KEY_ALL);
|
|
11
11
|
if (!integrations) {
|
|
12
|
-
integrations = await Integration.find({}).exec();
|
|
12
|
+
integrations = await Integration.find({}).lean().exec();
|
|
13
13
|
await setRedisData(CACHE_KEY_ALL, integrations);
|
|
14
14
|
}
|
|
15
15
|
return integrations;
|
|
@@ -19,7 +19,7 @@ const getCachedAllIntegrations = async () => {
|
|
|
19
19
|
* Update cached integrations for all workspaces.
|
|
20
20
|
*/
|
|
21
21
|
const updateCachedAllIntegrations = async () => {
|
|
22
|
-
const integrations = await Integration.find({}).exec();
|
|
22
|
+
const integrations = await Integration.find({}).lean().exec();
|
|
23
23
|
await setRedisData(CACHE_KEY_ALL, integrations);
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
+
const Shipper = require("../../models/Shipper");
|
|
3
|
+
|
|
4
|
+
const CACHE_KEY_ALL = "shippers_all";
|
|
5
|
+
|
|
6
|
+
const getCachedShippers = async () => {
|
|
7
|
+
let shippers = await getRedisData(CACHE_KEY_ALL);
|
|
8
|
+
if (!shippers) {
|
|
9
|
+
shippers = await Shipper.find().lean().exec();
|
|
10
|
+
await setRedisData(CACHE_KEY_ALL, JSON.stringify(shippers));
|
|
11
|
+
} else {
|
|
12
|
+
shippers = JSON.parse(shippers);
|
|
13
|
+
}
|
|
14
|
+
return shippers;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const updateCachedShippers = async () => {
|
|
18
|
+
const shippers = await Shipper.find().lean().exec();
|
|
19
|
+
await setRedisData(CACHE_KEY_ALL, JSON.stringify(shippers));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const createShipper = async (data) => {
|
|
23
|
+
const newShipper = new Shipper(data);
|
|
24
|
+
const savedShipper = await newShipper.save();
|
|
25
|
+
await updateCachedShippers();
|
|
26
|
+
return savedShipper;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const findShipperById = async (id) => {
|
|
30
|
+
const shippers = await getCachedShippers();
|
|
31
|
+
const shipper = shippers.find((s) => s._id.toString() === id) || null;
|
|
32
|
+
|
|
33
|
+
return shipper;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const findShipper = async (filter) => {
|
|
37
|
+
const shippers = await getCachedShippers();
|
|
38
|
+
return (
|
|
39
|
+
shippers.find((s) =>
|
|
40
|
+
Object.entries(filter).every(([key, value]) => s[key] === value)
|
|
41
|
+
) || null
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const findAllShippers = async (filter = {}) => {
|
|
46
|
+
const shippers = await getCachedShippers();
|
|
47
|
+
return shippers.filter((s) =>
|
|
48
|
+
Object.entries(filter).every(([key, value]) => s[key] === value)
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const updateShipper = async (id, data) => {
|
|
53
|
+
const updatedShipper = await Shipper.findByIdAndUpdate(id, data, {
|
|
54
|
+
new: true,
|
|
55
|
+
}).exec();
|
|
56
|
+
if (updatedShipper) {
|
|
57
|
+
await updateCachedShippers();
|
|
58
|
+
}
|
|
59
|
+
return updatedShipper;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const deleteShipper = async (id) => {
|
|
63
|
+
const deletedShipper = await Shipper.findByIdAndDelete(id).exec();
|
|
64
|
+
if (deletedShipper) {
|
|
65
|
+
await updateCachedShippers();
|
|
66
|
+
}
|
|
67
|
+
return deletedShipper;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
createShipper,
|
|
72
|
+
findShipperById,
|
|
73
|
+
findShipper,
|
|
74
|
+
findAllShippers,
|
|
75
|
+
updateShipper,
|
|
76
|
+
deleteShipper,
|
|
77
|
+
};
|