shuttlepro-shared 1.3.40 → 1.3.42

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 (73) hide show
  1. package/common/repositories/customerProfile.repository.js +83 -14
  2. package/common/repositories/userRole.repository.js +5 -2
  3. package/config/redis.js +72 -73
  4. package/middlewares/checkPermission/index.js +36 -23
  5. package/models/Activity.js +28 -0
  6. package/models/ActivityLogs.js +1 -0
  7. package/models/AgentActivity.js +5 -4
  8. package/models/Attribute.js +130 -0
  9. package/models/Automation.js +242 -0
  10. package/models/BusinessRule.js +16 -0
  11. package/models/BusinessRuleHelper.js +13 -0
  12. package/models/Card.js +50 -1
  13. package/models/Catalogue.js +22 -0
  14. package/models/Category.js +129 -0
  15. package/models/ChatMemberSession.js +21 -0
  16. package/models/ChatMessage.js +43 -0
  17. package/models/Chatbot.js +1 -1
  18. package/models/Color.js +10 -0
  19. package/models/Column.js +6 -0
  20. package/models/Conversation.js +40 -0
  21. package/models/Customer.js +2 -1
  22. package/models/CustomerCheckpoint.js +21 -0
  23. package/models/DeviceInfo.js +13 -0
  24. package/models/Email.js +21 -0
  25. package/models/EmailMessage.js +30 -0
  26. package/models/EmailNotification.js +17 -0
  27. package/models/EscalationConfiguration.js +123 -0
  28. package/models/EscalationManager.js +50 -0
  29. package/models/Faq.js +29 -0
  30. package/models/FeedbackResponse.js +72 -0
  31. package/models/FormTemplate.js +27 -0
  32. package/models/Integration.js +6 -0
  33. package/models/InternalComments.js +27 -0
  34. package/models/InternalThreads.js +20 -0
  35. package/models/JobDesign.js +32 -0
  36. package/models/JobQueue.js +17 -0
  37. package/models/LabelsPdf.js +12 -0
  38. package/models/Layout.js +12 -0
  39. package/models/LoadSheet.js +31 -0
  40. package/models/Location.js +148 -0
  41. package/models/Logo.js +11 -0
  42. package/models/MailGroup.js +21 -0
  43. package/models/Notification.js +32 -0
  44. package/models/Order.js +11 -0
  45. package/models/OrderPdf.js +29 -0
  46. package/models/PostsAutomation.js +66 -0
  47. package/models/Product.js +337 -0
  48. package/models/ProductAttachment.js +158 -0
  49. package/models/ProductAttribute.js +140 -0
  50. package/models/ProductCategory.js +128 -0
  51. package/models/ProductLabels.js +11 -0
  52. package/models/ProductShopify.js +13 -0
  53. package/models/ProductTag.js +124 -0
  54. package/models/ProductVariant.js +157 -0
  55. package/models/Profile.js +3 -1
  56. package/models/ServiceUsage.js +26 -0
  57. package/models/ShipperSetting.js +24 -0
  58. package/models/SocialGroup.js +127 -0
  59. package/models/SocialPost.js +40 -0
  60. package/models/SocialProfile.js +56 -0
  61. package/models/Story.js +86 -0
  62. package/models/Tag.js +77 -0
  63. package/models/Template.js +76 -0
  64. package/models/TemplateFrame.js +55 -0
  65. package/models/TemplateTag.js +10 -0
  66. package/models/UserGuide.js +21 -0
  67. package/models/UserSession.js +47 -0
  68. package/models/VariantLocation.js +145 -0
  69. package/models/WhatsappFlow.js +29 -0
  70. package/models/Workflow.js +34 -0
  71. package/models/Workspace.js +78 -4
  72. package/models.js +168 -49
  73. package/package.json +1 -1
package/models/Logo.js ADDED
@@ -0,0 +1,11 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const logoSchema = new mongoose.Schema(
4
+ {
5
+ url: { type: String, default: "" },
6
+ workspaceId: { type: String, default: "" },
7
+ },
8
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
9
+ );
10
+
11
+ module.exports = mongoose.model("Logo", logoSchema);
@@ -0,0 +1,21 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const MailGroupSchema = new Schema(
5
+ {
6
+ name: { type: String, default: "" },
7
+ emailIds: [
8
+ {
9
+ emailId: {
10
+ type: Schema.Types.ObjectId,
11
+ ref: "Email",
12
+ },
13
+ },
14
+ ],
15
+ workspaceId: { type: String, default: "" },
16
+ },
17
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
18
+ );
19
+
20
+ const MailGroup = mongoose.model("MailGroup", MailGroupSchema);
21
+ module.exports = MailGroup;
@@ -0,0 +1,32 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const NotificationSchema = new Schema(
5
+ {
6
+ type: { type: String, default: "" },
7
+ isRead: { type: Boolean, default: false },
8
+ operation: { type: String, default: "" },
9
+ actionId: { type: String, default: "" },
10
+ workspaceId: { type: String, default: "" },
11
+ workspaceName: { type: String, default: "" },
12
+ message: { type: String, default: "" },
13
+ email: { type: String, default: "" },
14
+ userId: { type: String, default: "" },
15
+ data: { type: mongoose.Schema.Types.Mixed },
16
+ isDeleted: { type: Boolean, default: false },
17
+ alertShow: { type: Boolean, default: false },
18
+ routes: {
19
+ routeType: { type: String, default: "" },
20
+ id: { type: String, default: "" },
21
+ query: { type: Boolean, default: false },
22
+ queryData: { type: String, default: "" },
23
+ },
24
+ permissions: [],
25
+ role: [String],
26
+ },
27
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
28
+ );
29
+
30
+ const Notification = mongoose.model("Notification", NotificationSchema);
31
+
32
+ module.exports = Notification;
package/models/Order.js CHANGED
@@ -136,6 +136,14 @@ const OrderSchema = new Schema(
136
136
  paymentDate: { type: String, default: "" },
137
137
  paymentDetails: {},
138
138
  },
139
+ merged: {
140
+ status: { type: String, default: "open" },
141
+ webOrderNumbers: [],
142
+ orderNumbers: [],
143
+ localOrderIds: [],
144
+ webOrderIds: [],
145
+ details: [],
146
+ },
139
147
  credentials: {},
140
148
  ticketId: { type: String, default: "" },
141
149
  sender: { type: String, default: "" },
@@ -159,6 +167,9 @@ const OrderSchema = new Schema(
159
167
  },
160
168
  orderName: { type: String, default: "" },
161
169
  totalWeight: { type: String, default: "" },
170
+ currency: {},
171
+ presentedCurrency: {},
172
+ exchangeRate: { type: Number, default: 0 },
162
173
  },
163
174
  { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
164
175
  );
@@ -0,0 +1,29 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const OrderPdfScehma = new mongoose.Schema(
5
+ {
6
+ orderNumber: {
7
+ type: {
8
+ localMin: { type: String, default: "" },
9
+ localMax: { type: String, default: "" },
10
+ storeMin: { type: String, default: "" },
11
+ storeMax: { type: String, default: "" },
12
+ },
13
+ },
14
+ ordersCount: { type: String, default: "" },
15
+ url: { type: String, default: "" },
16
+ key: { type: String, default: "" },
17
+ status: { type: String, default: "" },
18
+ workspaceId: {
19
+ type: Schema.Types.ObjectId,
20
+ ref: "Workspace",
21
+ default: null,
22
+ },
23
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
24
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
25
+ },
26
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
27
+ );
28
+
29
+ module.exports = mongoose.model("OrderPdf", OrderPdfScehma);
@@ -0,0 +1,66 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const PostsAutomation = new mongoose.Schema(
5
+ {
6
+ workspaceId: {
7
+ type: Schema.Types.ObjectId,
8
+ ref: "Workspace",
9
+ default: null,
10
+ },
11
+ platformType: {
12
+ type: String,
13
+ required: true,
14
+ enum: ["facebook", "instagram"],
15
+ },
16
+ attachments: [
17
+ {
18
+ type: String,
19
+ default: "",
20
+ },
21
+ ],
22
+ attachmentType: {
23
+ type: String,
24
+ default: "",
25
+ },
26
+ postId: {
27
+ type: String,
28
+ default: "",
29
+ },
30
+ verb: {
31
+ type: String,
32
+ default: "",
33
+ },
34
+ published: {
35
+ type: String,
36
+ default: "",
37
+ },
38
+ message: {
39
+ type: String,
40
+ default: "",
41
+ },
42
+ pageId: {
43
+ type: String,
44
+ default: "",
45
+ },
46
+ field: {
47
+ type: String,
48
+ default: "",
49
+ },
50
+ integratedAccount: {
51
+ type: Schema.Types.ObjectId,
52
+ ref: "Integration",
53
+ default: null,
54
+ },
55
+ status: {
56
+ type: String,
57
+ default: "",
58
+ emum: ["active", "pending", "removed"],
59
+ },
60
+ platformTimestamp: { type: String, default: "" },
61
+ body: [{}],
62
+ },
63
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
64
+ );
65
+
66
+ module.exports = mongoose.model("PostsAutomation", PostsAutomation);
@@ -0,0 +1,337 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+ const axios = require("axios");
4
+ const NewProduct = require("./NewProduct"); // Make sure to import NewProduct model
5
+
6
+ const categorySchema = new Schema({
7
+ _id: false,
8
+ categoryId: { type: String, default: "" },
9
+ name: { type: String, default: "" },
10
+ });
11
+
12
+ const ProductSchema = new Schema(
13
+ {
14
+ name: { type: String, default: "" },
15
+ description: { type: String, default: "" },
16
+ sku: { type: String, default: "" },
17
+ price: { type: String, default: 0 },
18
+ quantity: { type: Number, default: 0 },
19
+ imageUrl: { type: String, default: "" },
20
+ costPrice: { type: String, default: 0 },
21
+ salePrice: { type: String, default: 0 },
22
+ preference: { type: Number, default: 10 },
23
+ oldId: { type: String, default: "" },
24
+ webProductId: { type: Number, default: null },
25
+ publishedAt: { type: String, default: "" },
26
+ workspaceId: {
27
+ type: Schema.Types.ObjectId,
28
+ ref: "Workspace",
29
+ default: null,
30
+ },
31
+ storeType: { type: String, default: "LOCAL" },
32
+ isDeleted: { type: Boolean, default: false },
33
+ inventoryPolicy: { type: String, default: "deny" }, //deny,continue
34
+ inventoryManagement: { type: String, default: "shopify" }, //shopify, null, fulfillment_service
35
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
36
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
37
+ storeUrl: { type: String, default: "" },
38
+ status: { type: String, default: "active" }, //active, archived, draft
39
+ categories: [],
40
+ variantCount: { type: Number, default: 0 },
41
+ productType: { type: String, default: "" },
42
+ vendor: { type: String, default: "" },
43
+ handle: { type: String, default: "" },
44
+ isWebhookCase: { type: Boolean, default: false },
45
+ updating: { type: Boolean, default: false },
46
+ attributes: [],
47
+ bcProductId: { type: String, default: "" },
48
+ },
49
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
50
+ );
51
+
52
+ ProductSchema.virtual("productCategories", {
53
+ ref: "ProductCategory",
54
+ localField: "_id",
55
+ foreignField: "productId",
56
+ });
57
+ ProductSchema.virtual("productTags", {
58
+ ref: "ProductTag",
59
+ localField: "_id",
60
+ foreignField: "productId",
61
+ });
62
+ ProductSchema.virtual("productAttributes", {
63
+ ref: "ProductAttribute",
64
+ localField: "_id",
65
+ foreignField: "productId",
66
+ });
67
+ ProductSchema.virtual("productAttachments", {
68
+ ref: "ProductAttachment",
69
+ localField: "_id",
70
+ foreignField: "productId",
71
+ });
72
+ ProductSchema.virtual("productVariants", {
73
+ ref: "ProductVariant",
74
+ localField: "_id",
75
+ foreignField: "productId",
76
+ });
77
+ ProductSchema.virtual("variantLocations", {
78
+ ref: "VariantLocation",
79
+ localField: "_id",
80
+ foreignField: "productId",
81
+ });
82
+
83
+ const transformProductData = async (product) => {
84
+ if (!product) return null;
85
+
86
+ const populatedProduct = await mongoose.models.Product.findById(product._id)
87
+ .populate({
88
+ path: "productVariants",
89
+ match: { isDeleted: false },
90
+ })
91
+ .populate({
92
+ path: "productAttachments",
93
+ match: { isDeleted: false },
94
+ populate: {
95
+ path: "variantIds",
96
+ model: "ProductVariant",
97
+ match: { isDeleted: false },
98
+ },
99
+ })
100
+ .lean()
101
+ .exec();
102
+
103
+ if (!populatedProduct) return null;
104
+
105
+ return {
106
+ name: populatedProduct.name || "",
107
+ id: populatedProduct._id || "",
108
+ description: populatedProduct.description || "",
109
+ sku: populatedProduct.sku || "",
110
+ price: populatedProduct.price || "",
111
+ quantity: populatedProduct.quantity || 0,
112
+ imageUrl: populatedProduct.imageUrl || "",
113
+ costPrice: populatedProduct.costPrice || 0,
114
+ salePrice: populatedProduct.salePrice || 0,
115
+ webProductId: populatedProduct.webProductId || "",
116
+ variants:
117
+ populatedProduct.productVariants?.map((p) => ({
118
+ id: p?._id,
119
+ name: p?.name || "",
120
+ sku: p?.sku || "",
121
+ subSku: p?.subSku || "",
122
+ productId: p?.productId || "",
123
+ price: p?.price || "",
124
+ costPrice: p?.costPrice || 0,
125
+ salePrice: p?.salePrice || 0,
126
+ quantity: p?.quantity || 0,
127
+ })) || [],
128
+ attachments:
129
+ populatedProduct.productAttachments?.map((x) => ({
130
+ id: x?._id,
131
+ thumbUrl: x?.thumbUrl,
132
+ remoteUrl: x?.remoteUrl,
133
+ url: x?.url,
134
+ type: x?.type,
135
+ variants:
136
+ x?.variantIds?.length > 0
137
+ ? x.variantIds.map((p) => ({
138
+ id: p?._id,
139
+ name: p?.name || "",
140
+ sku: p?.sku || "",
141
+ subSku: p?.subSku || "",
142
+ productId: p?.productId || "",
143
+ price: p?.price || "",
144
+ costPrice: p?.costPrice || 0,
145
+ salePrice: p?.salePrice || 0,
146
+ quantity: p?.quantity || 0,
147
+ }))
148
+ : [],
149
+ })) || [],
150
+ workspaceId: populatedProduct.workspaceId,
151
+ };
152
+ };
153
+
154
+ // Middleware for various operations
155
+ const updateNewProduct = async (doc, next) => {
156
+ try {
157
+ // Skip if document is marked as deleted
158
+ if (doc.isDeleted) return;
159
+
160
+ // Transform and upsert product data
161
+ const newProductData = await transformProductData(doc);
162
+ if (newProductData) {
163
+ await NewProduct.findOneAndUpdate(
164
+ { id: newProductData.id },
165
+ newProductData,
166
+ { upsert: true, new: true }
167
+ );
168
+ }
169
+ } catch (error) {
170
+ console.error("Error updating NewProduct:", error);
171
+ // Call next with error if needed
172
+ next(error);
173
+ }
174
+ };
175
+
176
+ const deleteNewProduct = async (doc, next) => {
177
+ try {
178
+ if (doc) {
179
+ await NewProduct.deleteOne({ id: doc._id });
180
+ }
181
+ } catch (error) {
182
+ console.error("Error deleting from NewProduct:", error);
183
+ next(error);
184
+ }
185
+ };
186
+
187
+ // Post middleware for various Mongoose operations
188
+ ProductSchema.post("save", async function (doc, next) {
189
+ console.log(doc, "doc");
190
+ await updateNewProduct(doc, next);
191
+ });
192
+
193
+ ProductSchema.post("findOneAndUpdate", async function (doc, next) {
194
+ await updateNewProduct(doc, next);
195
+ });
196
+
197
+ ProductSchema.post("updateOne", async function (doc, next) {
198
+ console.log(doc, "doc called");
199
+ await updateNewProduct(doc, next);
200
+ });
201
+
202
+ ProductSchema.post("create", async function (doc, next) {
203
+ await updateNewProduct(doc, next);
204
+ });
205
+
206
+ ProductSchema.post("findOneAndDelete", async function (doc, next) {
207
+ await deleteNewProduct(doc, next);
208
+ });
209
+
210
+ ProductSchema.post("deleteOne", async function (doc, next) {
211
+ await deleteNewProduct(doc, next);
212
+ });
213
+
214
+ const Product = mongoose.model("Product", ProductSchema);
215
+
216
+ const newProductInstance = async (productData) => {
217
+ try {
218
+ return new Product(productData);
219
+ } catch (error) {
220
+ return null;
221
+ }
222
+ };
223
+
224
+ const createNewProduct = async (productData) => {
225
+ try {
226
+ return await Product.create(productData);
227
+ } catch (error) {
228
+ console.log(error);
229
+ return null;
230
+ }
231
+ };
232
+
233
+ const findProductById = async (productId) => {
234
+ try {
235
+ return await Product.findById(productId);
236
+ } catch (error) {
237
+ console.log(error);
238
+ return null;
239
+ }
240
+ };
241
+
242
+ const updateProductById = async (criteria, updateData, options) => {
243
+ try {
244
+ return await Product.findByIdAndUpdate(criteria, updateData, options);
245
+ } catch (error) {
246
+ console.log(error);
247
+ return null;
248
+ }
249
+ };
250
+
251
+ const updateProducts = async (criteria, updateData, options = {}) => {
252
+ try {
253
+ return await Product.updateMany(criteria, updateData, options);
254
+ } catch (error) {
255
+ console.log(error);
256
+ return [];
257
+ }
258
+ };
259
+
260
+ const deleteProductById = async (productId) => {
261
+ try {
262
+ return await Product.findByIdAndDelete(productId);
263
+ } catch (error) {
264
+ console.log(error);
265
+ return null;
266
+ }
267
+ };
268
+
269
+ const findProduct = async (criteria) => {
270
+ try {
271
+ return await Product.findOne(criteria);
272
+ } catch (error) {
273
+ console.log(error);
274
+ return null;
275
+ }
276
+ };
277
+
278
+ const findProducts = async (criteria) => {
279
+ try {
280
+ return await Product.find(criteria);
281
+ } catch (error) {
282
+ console.log(error);
283
+ return [];
284
+ }
285
+ };
286
+
287
+ const findSingleProduct = async (obj) => {
288
+ try {
289
+ let product = await Product.findOne(obj);
290
+ return product;
291
+ } catch (err) {
292
+ return null;
293
+ }
294
+ };
295
+
296
+ const countProductDocument = async (obj) => {
297
+ try {
298
+ let product = await Product.countDocuments(obj);
299
+ return product;
300
+ } catch (err) {
301
+ return 0;
302
+ }
303
+ };
304
+
305
+ const findProductWithPopulateAndPagination = async (
306
+ condition,
307
+ pop,
308
+ page,
309
+ limit
310
+ ) => {
311
+ try {
312
+ const products = await Product.find(condition)
313
+ .sort({ _id: -1 })
314
+ .skip((page - 1) * parseInt(limit))
315
+ .limit(parseInt(limit))
316
+ .populate(pop);
317
+ return products;
318
+ } catch (err) {
319
+ return 0;
320
+ }
321
+ };
322
+
323
+ module.exports = {
324
+ newProductInstance,
325
+ createNewProduct,
326
+ findProductById,
327
+ updateProductById,
328
+ updateProducts,
329
+ deleteProductById,
330
+ findProduct,
331
+ findProducts,
332
+ findSingleProduct,
333
+ countProductDocument,
334
+ findProductWithPopulateAndPagination,
335
+ Product,
336
+ ProductModel: Product,
337
+ };
@@ -0,0 +1,158 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+ const ProductAttachmentSchema = new Schema(
4
+ {
5
+ type: { type: String, default: "default" },
6
+ designJobId: {
7
+ type: Schema.Types.ObjectId,
8
+ ref: "JobDesign",
9
+ default: null,
10
+ },
11
+ oldId: { type: String, default: "" },
12
+ templateId: { type: Schema.Types.ObjectId, ref: "Template", default: null },
13
+ remoteUrl: { type: String, default: "" },
14
+ webImageId: { type: Number, default: null },
15
+ default: { type: Boolean, default: false },
16
+ productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
17
+ url: { type: String, default: "" },
18
+ thumbUrl: { type: String, default: "" },
19
+ width: { type: Number, default: 0 },
20
+ workspaceId: {
21
+ type: Schema.Types.ObjectId,
22
+ ref: "Workspace",
23
+ default: null,
24
+ },
25
+ height: { type: Number, default: 0 },
26
+ variantIds: [
27
+ { type: Schema.Types.ObjectId, ref: "ProductVariant", default: null },
28
+ ],
29
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
30
+ position: { type: Number, default: 1 },
31
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
32
+ isDeleted: { type: Boolean, default: false },
33
+ },
34
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
35
+ );
36
+
37
+ ProductAttachmentSchema.virtual("products", {
38
+ ref: "Product",
39
+ localField: "productId",
40
+ foreignField: "_id",
41
+ });
42
+
43
+ const ProductAttachment = mongoose.model(
44
+ "ProductAttachment",
45
+ ProductAttachmentSchema
46
+ );
47
+
48
+ const createNewProductAttachment = async (productAttachmentData) => {
49
+ try {
50
+ return await ProductAttachment.create(productAttachmentData);
51
+ } catch (error) {
52
+ console.log(error);
53
+ return null;
54
+ }
55
+ };
56
+
57
+ const insertProductAttachments = async (data) => {
58
+ try {
59
+ return await ProductAttachment.create(data);
60
+ } catch (error) {
61
+ console.log(error);
62
+ return [];
63
+ }
64
+ };
65
+
66
+ const findProductAttachmentById = async (productAttachmentId) => {
67
+ try {
68
+ return await ProductAttachment.findById(productAttachmentId);
69
+ } catch (error) {
70
+ console.log(error);
71
+ return null;
72
+ }
73
+ };
74
+
75
+ const updateProductAttachmentById = async (
76
+ criteria,
77
+ updateData,
78
+ options = {}
79
+ ) => {
80
+ try {
81
+ return await ProductAttachment.findByIdAndUpdate(
82
+ criteria,
83
+ updateData,
84
+ options
85
+ );
86
+ } catch (error) {
87
+ console.log(error);
88
+ return null;
89
+ }
90
+ };
91
+
92
+ const deleteProductAttachmentById = async (productAttachmentId) => {
93
+ try {
94
+ return await ProductAttachment.findByIdAndDelete(productAttachmentId);
95
+ } catch (error) {
96
+ console.log(error);
97
+ return null;
98
+ }
99
+ };
100
+
101
+ const findProductAttachment = async (criteria) => {
102
+ try {
103
+ return await ProductAttachment.findOne(criteria);
104
+ } catch (error) {
105
+ console.log(error);
106
+ return null;
107
+ }
108
+ };
109
+
110
+ const findProductAttachments = async (criteria) => {
111
+ try {
112
+ return await ProductAttachment.find(criteria);
113
+ } catch (error) {
114
+ console.log(error);
115
+ return [];
116
+ }
117
+ };
118
+
119
+ const updateManyProductAttachments = async (
120
+ criteria,
121
+ updatedData,
122
+ options = {}
123
+ ) => {
124
+ try {
125
+ return await ProductAttachment.updateMany(criteria, updatedData, options);
126
+ } catch (error) {
127
+ return [];
128
+ }
129
+ };
130
+
131
+ const findAndUpdateProductAttachment = async (
132
+ criteria,
133
+ updatedData,
134
+ options
135
+ ) => {
136
+ try {
137
+ return await ProductAttachment.findOneAndUpdate(
138
+ criteria,
139
+ updatedData,
140
+ options
141
+ );
142
+ } catch (error) {
143
+ return [];
144
+ }
145
+ };
146
+
147
+ module.exports = {
148
+ createNewProductAttachment,
149
+ insertProductAttachments,
150
+ updateManyProductAttachments,
151
+ findProductAttachmentById,
152
+ updateProductAttachmentById,
153
+ deleteProductAttachmentById,
154
+ findProductAttachment,
155
+ findProductAttachments,
156
+ ProductAttachment,
157
+ findAndUpdateProductAttachment,
158
+ };