shuttlepro-shared 1.3.29 → 1.3.31

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 (60) 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/AgentActivity.js +5 -2
  7. package/models/Attribute.js +130 -0
  8. package/models/Automation.js +238 -0
  9. package/models/Card.js +50 -1
  10. package/models/Catalogue.js +22 -0
  11. package/models/Category.js +129 -0
  12. package/models/ChatMemberSession.js +21 -0
  13. package/models/ChatMessage.js +43 -0
  14. package/models/Color.js +10 -0
  15. package/models/Column.js +6 -0
  16. package/models/Conversation.js +1 -0
  17. package/models/Customer.js +3 -2
  18. package/models/DeviceInfo.js +13 -0
  19. package/models/EscalationConfiguration.js +123 -0
  20. package/models/EscalationManager.js +50 -0
  21. package/models/Faq.js +29 -0
  22. package/models/FeedbackResponse.js +72 -0
  23. package/models/FormTemplate.js +27 -0
  24. package/models/Integration.js +6 -0
  25. package/models/InternalComments.js +27 -0
  26. package/models/InternalThreads.js +20 -0
  27. package/models/JobDesign.js +32 -0
  28. package/models/JobQueue.js +17 -0
  29. package/models/LabelsPdf.js +12 -0
  30. package/models/Layout.js +12 -0
  31. package/models/Location.js +147 -0
  32. package/models/Logo.js +11 -0
  33. package/models/Notification.js +32 -0
  34. package/models/Order.js +11 -0
  35. package/models/OrderPdf.js +29 -0
  36. package/models/PostsAutomation.js +66 -0
  37. package/models/Product.js +336 -0
  38. package/models/ProductAttachment.js +158 -0
  39. package/models/ProductAttribute.js +140 -0
  40. package/models/ProductCategory.js +128 -0
  41. package/models/ProductLabels.js +11 -0
  42. package/models/ProductShopify.js +13 -0
  43. package/models/ProductTag.js +124 -0
  44. package/models/ProductVariant.js +156 -0
  45. package/models/ServiceUsage.js +26 -0
  46. package/models/ShipperSetting.js +24 -0
  47. package/models/SocialGroup.js +127 -0
  48. package/models/SocialPost.js +40 -0
  49. package/models/SocialProfile.js +57 -0
  50. package/models/Tag.js +77 -0
  51. package/models/Template.js +76 -0
  52. package/models/TemplateFrame.js +37 -0
  53. package/models/TemplateTag.js +10 -0
  54. package/models/UserSession.js +47 -0
  55. package/models/VariantLocation.js +145 -0
  56. package/models/WhatsappFlow.js +0 -0
  57. package/models/Workflow.js +34 -0
  58. package/models/Workspace.js +13 -0
  59. package/models.js +148 -49
  60. package/package.json +1 -1
@@ -0,0 +1,128 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema, model } = mongoose;
3
+ const ProductCategorySchema = new Schema(
4
+ {
5
+ productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
6
+ categoryId: { type: Schema.Types.ObjectId, ref: "Category", default: null },
7
+ webProductCategoryId: { type: Number, default: null },
8
+ oldId: { type: String, default: "" },
9
+ workspaceId: {
10
+ type: Schema.Types.ObjectId,
11
+ ref: "Workspace",
12
+ default: null,
13
+ },
14
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
15
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
16
+ isDeleted: { type: Boolean, default: false },
17
+ },
18
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
19
+ );
20
+
21
+ ProductCategorySchema.virtual("categoriesProducts", {
22
+ ref: "Product",
23
+ localField: "productId",
24
+ foreignField: "_id",
25
+ });
26
+ const ProductCategory = mongoose.model(
27
+ "ProductCategory",
28
+ ProductCategorySchema
29
+ );
30
+
31
+ const softDeleteProductCategories = async (
32
+ workspaceId,
33
+ convertingIds,
34
+ type
35
+ ) => {
36
+ const filter = {
37
+ workspaceId: workspaceId,
38
+ isDeleted: false,
39
+ };
40
+ filter[type] = { $in: convertingIds };
41
+ const update = { $set: { isDeleted: true } };
42
+ const result = await ProductCategory.updateMany(filter, update);
43
+ if (result.matchedCount === 0) {
44
+ return true;
45
+ }
46
+ if (result.modifiedCount === 0 && result.matchedCount > 0) {
47
+ return false;
48
+ }
49
+ return true;
50
+ };
51
+
52
+ const insertProductCategories = async (obj) => {
53
+ try {
54
+ return await ProductCategory.insertMany(obj);
55
+ } catch (err) {
56
+ return [];
57
+ }
58
+ };
59
+
60
+ const findProductCategory = async (criteria = {}) => {
61
+ try {
62
+ return await ProductCategory.findOne(criteria);
63
+ } catch (error) {
64
+ return null;
65
+ }
66
+ };
67
+
68
+ const findProductCategories = async (criteria = {}) => {
69
+ try {
70
+ return await ProductCategory.find(criteria);
71
+ } catch (error) {
72
+ return [];
73
+ }
74
+ };
75
+
76
+ const createProductCategory = async (obj) => {
77
+ try {
78
+ const productCategory = new ProductCategory(obj);
79
+ let newCategory = await productCategory.save();
80
+ return newCategory;
81
+ } catch (err) {
82
+ return null;
83
+ }
84
+ };
85
+
86
+ const findProductCategoriesWithPopulate = async (
87
+ criteria = {},
88
+ populate = ""
89
+ ) => {
90
+ try {
91
+ return await ProductCategory.find(criteria).populate(populate);
92
+ } catch (error) {
93
+ console.log("error", error);
94
+ return [];
95
+ }
96
+ };
97
+
98
+ const bulkWriteProductCategories = async (operations = []) => {
99
+ try {
100
+ return await ProductCategory.bulkWrite(operations);
101
+ } catch (error) {
102
+ return [];
103
+ }
104
+ };
105
+
106
+ const updateManyProductCategories = async (
107
+ criteria,
108
+ updatedData,
109
+ options = {}
110
+ ) => {
111
+ try {
112
+ return await ProductCategory.updateMany(criteria, updatedData, options);
113
+ } catch (error) {
114
+ return null;
115
+ }
116
+ };
117
+
118
+ module.exports = {
119
+ ProductCategory,
120
+ findProductCategory,
121
+ findProductCategories,
122
+ createProductCategory,
123
+ insertProductCategories,
124
+ softDeleteProductCategories,
125
+ findProductCategoriesWithPopulate,
126
+ bulkWriteProductCategories,
127
+ updateManyProductCategories,
128
+ };
@@ -0,0 +1,11 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const productLabelsSchema = 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("ProductLabels", productLabelsSchema);
@@ -0,0 +1,13 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const ProductShopifySchema = new Schema(
5
+ {
6
+ type: { type: String, default: "" },
7
+ body: {},
8
+ },
9
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
10
+ );
11
+
12
+ const ProductShopify = mongoose.model("ProductShopify", ProductShopifySchema);
13
+ module.exports = ProductShopify;
@@ -0,0 +1,124 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema, model } = mongoose;
3
+ const ProductTagSchema = new Schema(
4
+ {
5
+ productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
6
+ tagId: { type: Schema.Types.ObjectId, ref: "Tag", default: null },
7
+ webProductTagId: { type: String, default: " " },
8
+ oldId: { type: String, default: "" },
9
+ workspaceId: {
10
+ type: Schema.Types.ObjectId,
11
+ ref: "Workspace",
12
+ default: null,
13
+ },
14
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
15
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
16
+ isDeleted: { type: Boolean, default: false },
17
+ },
18
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
19
+ );
20
+
21
+ const ProductTag = mongoose.model("ProductTag", ProductTagSchema);
22
+
23
+ const productTagsByAggregation = async (aggregate) => {
24
+ try {
25
+ let tags = await ProductTag.aggregate(aggregate);
26
+ return tags;
27
+ } catch (err) {
28
+ return [];
29
+ }
30
+ };
31
+
32
+ const findSingleProductTag = async (obj) => {
33
+ try {
34
+ let tag = await ProductTag.findOne(obj);
35
+ return tag;
36
+ } catch (err) {
37
+ return null;
38
+ }
39
+ };
40
+
41
+ const insertProductTags = async (obj) => {
42
+ try {
43
+ return await ProductTag.insertMany(obj);
44
+ } catch (err) {
45
+ console.log("null", err);
46
+ return [];
47
+ }
48
+ };
49
+
50
+ const createProductTag = async (obj) => {
51
+ try {
52
+ const tag = new ProductTag(obj);
53
+ let newTag = await tag.save();
54
+ return newTag;
55
+ } catch (err) {
56
+ console.log("null", err);
57
+ return null;
58
+ }
59
+ };
60
+
61
+ const softDeleteProductTags = async (workspaceId, convertingIds, type) => {
62
+ const filter = {
63
+ workspaceId: workspaceId,
64
+ isDeleted: false,
65
+ };
66
+ filter[type] = { $in: convertingIds };
67
+ const update = { $set: { isDeleted: true } };
68
+ const result = await ProductTag.updateMany(filter, update);
69
+ if (result.matchedCount === 0) {
70
+ return true;
71
+ }
72
+ if (result.modifiedCount === 0 && result.matchedCount > 0) {
73
+ return false;
74
+ }
75
+ return true;
76
+ };
77
+
78
+ const findProductTag = async (obj) => {
79
+ try {
80
+ let tag = await ProductTag.findOne(obj);
81
+ return tag;
82
+ } catch (err) {
83
+ return null;
84
+ }
85
+ };
86
+
87
+ const findProductTags = async (obj) => {
88
+ try {
89
+ let tag = await ProductTag.find(obj);
90
+ return tag;
91
+ } catch (err) {
92
+ return [];
93
+ }
94
+ };
95
+
96
+ const findProductTagsByPopulate = async (obj, populate) => {
97
+ try {
98
+ let tag = await ProductTag.find(obj).populate(populate);
99
+ return tag;
100
+ } catch (err) {
101
+ return [];
102
+ }
103
+ };
104
+
105
+ const updateManyProductTags = async (criteria, updatedData, options = {}) => {
106
+ try {
107
+ return await ProductTag.updateMany(criteria, updatedData, options);
108
+ } catch (error) {
109
+ return null;
110
+ }
111
+ };
112
+
113
+ module.exports = {
114
+ ProductTag,
115
+ productTagsByAggregation,
116
+ findSingleProductTag,
117
+ insertProductTags,
118
+ createProductTag,
119
+ softDeleteProductTags,
120
+ findProductTag,
121
+ findProductTags,
122
+ findProductTagsByPopulate,
123
+ updateManyProductTags,
124
+ };
@@ -0,0 +1,156 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const ProductVariantSchema = new Schema(
5
+ {
6
+ price: { type: Number, default: 0 },
7
+ costPrice: { type: Number, default: 0 },
8
+ name: { type: String, default: "" },
9
+ sku: { type: String, default: "" },
10
+ subSku: { type: String, default: "" },
11
+ salePrice: { type: Number, default: 0 },
12
+ quantity: { type: Number, default: null },
13
+ productId: { type: Schema.Types.ObjectId, ref: "Product", default: null },
14
+ oldId: { type: String, default: "" },
15
+ workspaceId: {
16
+ type: Schema.Types.ObjectId,
17
+ ref: "Workspace",
18
+ default: null,
19
+ },
20
+ webVariantId: { type: Number, default: null },
21
+ inventoryPolicy: { type: String, default: "deny" }, //deny,continue
22
+ taxable: { type: Boolean, default: false },
23
+ tax: { type: Number, default: 0 },
24
+ weight: { type: Number, default: 0 },
25
+ weightUnit: { type: String, default: "" },
26
+ attachmentId: {
27
+ type: Schema.Types.ObjectId,
28
+ ref: "ProductAttachment",
29
+ default: null,
30
+ },
31
+ webAttachmentId: { type: Number, default: null },
32
+ inventoryManagement: { type: String, default: "shopify" }, //shopify, null, fulfillment_service
33
+ webInventoryItemId: { type: Number, default: null },
34
+ manufactureDate: { type: String, default: "" },
35
+ expiryDate: { type: String, default: "" },
36
+ attributes: [],
37
+ attributeIds: [
38
+ // {
39
+ // type: Schema.Types.ObjectId,
40
+ // ref: "Attribute",
41
+ // default: null,
42
+ // },
43
+ ],
44
+ isDeleted: { type: Boolean, default: false },
45
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
46
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
47
+ isDeleted: { type: Boolean, default: false },
48
+ },
49
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
50
+ );
51
+
52
+ ProductVariantSchema.virtual("variantLocations", {
53
+ ref: "VariantLocation",
54
+ localField: "_id",
55
+ foreignField: "variantId",
56
+ });
57
+
58
+ ProductVariantSchema.virtual("productAttachments", {
59
+ ref: "ProductAttachment",
60
+ localField: "_id",
61
+ foreignField: "variantIds",
62
+ });
63
+
64
+ const ProductVariant = mongoose.model("ProductVariant", ProductVariantSchema);
65
+
66
+ const createNewProductVariant = async (variantData) => {
67
+ try {
68
+ return await ProductVariant.create(variantData);
69
+ } catch (error) {
70
+ console.log(error);
71
+ return null;
72
+ }
73
+ };
74
+
75
+ const insertProductVariants = async (data) => {
76
+ try {
77
+ return await ProductVariant.create(data);
78
+ } catch (error) {
79
+ console.log(error);
80
+ return [];
81
+ }
82
+ };
83
+
84
+ const findProductVariants = async (criteria) => {
85
+ try {
86
+ const variants = await ProductVariant.find(criteria);
87
+ return variants;
88
+ } catch (error) {
89
+ console.log(error);
90
+ return [];
91
+ }
92
+ };
93
+
94
+ const findSingleProductVariant = async (obj) => {
95
+ try {
96
+ let variant = await ProductVariant.findOne(obj);
97
+ return variant;
98
+ } catch (err) {
99
+ return null;
100
+ }
101
+ };
102
+
103
+ const updateManyProductVariants = async (
104
+ criteria,
105
+ updateData,
106
+ options = {}
107
+ ) => {
108
+ try {
109
+ return await ProductVariant.updateMany(criteria, updateData, options);
110
+ } catch (error) {
111
+ console.log(error);
112
+ return null;
113
+ }
114
+ };
115
+
116
+ const findOneAndUpdateProductVariant = async (query, data) => {
117
+ try {
118
+ return await ProductVariant.findOneAndUpdate(
119
+ query,
120
+ { $set: data },
121
+ { new: true }
122
+ );
123
+ } catch (error) {
124
+ console.log("eerr", error);
125
+ return null;
126
+ }
127
+ };
128
+
129
+ const aggregateProductVariants = async (pipeline) => {
130
+ try {
131
+ return await ProductVariant.aggregate(pipeline);
132
+ } catch (error) {
133
+ console.log(error);
134
+ return null;
135
+ }
136
+ };
137
+
138
+ const findSingleProductVariantWithPopulate = async (obj, populateObj) => {
139
+ try {
140
+ return await ProductVariant.findOne(obj).populate(populateObj);
141
+ } catch (err) {
142
+ return null;
143
+ }
144
+ };
145
+
146
+ module.exports = {
147
+ insertProductVariants,
148
+ createNewProductVariant,
149
+ updateManyProductVariants,
150
+ findOneAndUpdateProductVariant,
151
+ aggregateProductVariants,
152
+ findProductVariants,
153
+ findSingleProductVariant,
154
+ findSingleProductVariantWithPopulate,
155
+ ProductVariant,
156
+ };
@@ -0,0 +1,26 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const ServiceUsageSchema = new Schema(
5
+ {
6
+ type: {
7
+ type: String,
8
+ enum: ["nlp", "google"],
9
+ required: true,
10
+ },
11
+ data: {},
12
+ labelId: {
13
+ type: Schema.Types.ObjectId,
14
+ ref: "Label",
15
+ required: false,
16
+ },
17
+ workspaceId: {
18
+ type: Schema.Types.ObjectId,
19
+ ref: "Workspace",
20
+ },
21
+ },
22
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
23
+ );
24
+
25
+ const ServiceUsage = mongoose.model("ServiceUsage", ServiceUsageSchema);
26
+ module.exports = ServiceUsage;
@@ -0,0 +1,24 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const shipperSettingSchema = new mongoose.Schema(
4
+ {
5
+ publish: { type: Boolean, default: false },
6
+ defaultShipper: { type: String, default: "" },
7
+ codAmount: { type: Number, default: 0 },
8
+ workspaceId: { type: String, default: "" },
9
+ publishTime: [],
10
+ days: [],
11
+ minAmount: { type: Number, default: 0 },
12
+ tabs: [],
13
+ location: {
14
+ shippers: [],
15
+ citiesShippers: [],
16
+ },
17
+ weight: [],
18
+ prepaidOrder: [],
19
+ amount: [],
20
+ },
21
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
22
+ );
23
+
24
+ module.exports = mongoose.model("ShipperSetting", shipperSettingSchema);
@@ -0,0 +1,127 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const SocialGroupSchema = new mongoose.Schema(
5
+ {
6
+ name: { type: String, default: "" },
7
+ products: [
8
+ {
9
+ productId: {
10
+ type: Schema.Types.ObjectId,
11
+ ref: "Product",
12
+ },
13
+ orderNo: {
14
+ type: String,
15
+ default: "",
16
+ },
17
+ },
18
+ ],
19
+ deletedArr: [],
20
+ productCount: { type: String, default: "" },
21
+ workspaceId: {
22
+ type: Schema.Types.ObjectId,
23
+ ref: "Workspace",
24
+ default: null,
25
+ },
26
+ isDeleted: { type: Boolean, default: false },
27
+ createdBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
28
+ updatedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
29
+ },
30
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
31
+ );
32
+
33
+ const SocialGroup = mongoose.model("SocialGroup", SocialGroupSchema);
34
+
35
+ const createNewSocialGroup = async (socialGroupData) => {
36
+ try {
37
+ return await SocialGroup.create(socialGroupData);
38
+ } catch (error) {
39
+ console.log(error);
40
+ return null;
41
+ }
42
+ };
43
+
44
+ const findSocialGroupById = async (socialGroupId) => {
45
+ try {
46
+ return await SocialGroup.findById(socialGroupId);
47
+ } catch (error) {
48
+ console.log(error);
49
+ return null;
50
+ }
51
+ };
52
+
53
+ const updateSocialGroupById = async (criteria, updateData, options = {}) => {
54
+ try {
55
+ return await SocialGroup.findByIdAndUpdate(criteria, updateData, options);
56
+ } catch (error) {
57
+ console.log(error);
58
+ return null;
59
+ }
60
+ };
61
+
62
+ const deleteSocialGroupById = async (socialGroupId) => {
63
+ try {
64
+ return await SocialGroup.findByIdAndDelete(socialGroupId);
65
+ } catch (error) {
66
+ console.log(error);
67
+ return null;
68
+ }
69
+ };
70
+
71
+ const findSocialGroup = async (criteria, selectFields, populateOptions) => {
72
+ try {
73
+ let query = SocialGroup.findOne(criteria);
74
+
75
+ if (selectFields) {
76
+ query = query.select(selectFields);
77
+ }
78
+
79
+ if (populateOptions) {
80
+ query = query.populate(populateOptions);
81
+ }
82
+
83
+ return await query.exec();
84
+ } catch (error) {
85
+ console.error(error);
86
+ return null;
87
+ }
88
+ };
89
+
90
+ const findSocialGroups = async (criteria) => {
91
+ try {
92
+ return await SocialGroup.find(criteria);
93
+ } catch (error) {
94
+ console.log(error);
95
+ return null;
96
+ }
97
+ };
98
+
99
+ const socialGroupByAggregation = async (pipeline) => {
100
+ try {
101
+ return await SocialGroup.aggregate(pipeline);
102
+ } catch (error) {
103
+ console.log(error);
104
+ return null;
105
+ }
106
+ };
107
+
108
+ const socialGroupUpdateMany = async (criteria, updateData, options = {}) => {
109
+ try {
110
+ return await SocialGroup.updateMany(criteria, updateData, options);
111
+ } catch (error) {
112
+ console.log(error);
113
+ return null;
114
+ }
115
+ };
116
+
117
+ module.exports = {
118
+ SocialGroup,
119
+ createNewSocialGroup,
120
+ findSocialGroupById,
121
+ updateSocialGroupById,
122
+ deleteSocialGroupById,
123
+ findSocialGroup,
124
+ findSocialGroups,
125
+ socialGroupByAggregation,
126
+ socialGroupUpdateMany,
127
+ };
@@ -0,0 +1,40 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+
4
+ const SocialPostSchema = new Schema(
5
+ {
6
+ type: { type: String, default: "single" },
7
+ postType: { type: String, default: "post" },
8
+ platformType: { type: String, default: "facebook" },
9
+ isScheduledPost: { type: Boolean, default: false },
10
+ workspaceId: {
11
+ type: Schema.Types.ObjectId,
12
+ ref: "Workspace",
13
+ default: null,
14
+ },
15
+ pageId: { type: String, default: "" },
16
+ pageName: { type: String, default: "" },
17
+ pageLogo: { type: String, default: "" },
18
+ pageToken: { type: String, default: "" },
19
+ caption: { type: String, default: "" },
20
+ permanentLink: { type: String, default: "" },
21
+ attachments: [{
22
+ link: { type: String, default: ""},
23
+ src: { type: String, default: "" },
24
+ caption: { type: String, default: "" },
25
+ mediaType: { type: String, default: "" }
26
+ }],
27
+ socialProfile: { type: Schema.Types.ObjectId, ref: "Integration", default: null },
28
+ status: { type: String, default: "scheduled" },
29
+ scheduleDate: {type: Date, default: null },
30
+ queued: { type: Boolean, default: false },
31
+ isDeleted: { type: Boolean, default: false },
32
+ publishedAt: { type: String, default: "" },
33
+ publishedBy: { type: Schema.Types.ObjectId, ref: "User", default: null },
34
+ },
35
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
36
+ );
37
+
38
+ const SocialPost = mongoose.model("SocialPost", SocialPostSchema);
39
+ module.exports = SocialPost;
40
+
@@ -0,0 +1,57 @@
1
+ const mongoose = require("mongoose");
2
+ const { Schema } = mongoose;
3
+ // const { Workspace } = require("./Workspace");
4
+
5
+ const socialProfileSchema = new mongoose.Schema(
6
+ {
7
+ pageName: { type: String, default: "" },
8
+ pageToken: { type: String, default: "" },
9
+ platformType: { type: String, default: "" },
10
+ pageId: { type: String, default: "" },
11
+ pageIcon: { type: String, default: "" },
12
+ pageCoverUrl: { type: String, default: "" },
13
+ username: { type: String, default: "" },
14
+ workspaceId: {
15
+ type: Schema.Types.ObjectId,
16
+ ref: "Workspace",
17
+ default: null,
18
+ },
19
+ isDeleted: { type: Boolean, default: false },
20
+ userId: { type: Schema.Types.ObjectId, ref: "User", default: null },
21
+ options: {
22
+ type: Object,
23
+ default: null,
24
+ },
25
+ },
26
+ { timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
27
+ );
28
+
29
+ const SocialProfile = mongoose.model("socialProfile", socialProfileSchema);
30
+
31
+ const getSocialProfile = async (profileId) => {
32
+ try {
33
+ return await SocialProfile.findOne({
34
+ _id: mongoose.Types.ObjectId(profileId),
35
+ });
36
+ } catch (error) {
37
+ throw error;
38
+ }
39
+ };
40
+ const findByPageId = async (pageId) => {
41
+ try {
42
+ let obj = { pageId: pageId, isDeleted: false };
43
+ const fetchingSocialProfile = await SocialProfile.findOne(obj);
44
+ if (fetchingSocialProfile) {
45
+ return fetchingSocialProfile;
46
+ }
47
+ return null;
48
+ } catch (err) {
49
+ return null;
50
+ }
51
+ };
52
+
53
+ module.exports = {
54
+ getSocialProfile,
55
+ findByPageId,
56
+ SocialProfile,
57
+ };