database-connector 1.0.6 → 1.1.0

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/models/Store.js CHANGED
@@ -1,9 +1,111 @@
1
1
  const mongoose = require('mongoose');
2
- const User = require('./User');
3
- const Product = require('./Product');
4
- const { policySchema } = require('./Policy');
5
- var ObjectId = require('mongodb').ObjectID;
2
+ const { policySchema } = require('database-connector/models/Policy');
6
3
 
4
+ /**
5
+ * @swagger
6
+ * components:
7
+ * schemas:
8
+ * Store:
9
+ * type: object
10
+ * required:
11
+ * - name
12
+ * - sellerId
13
+ * - image
14
+ * - description
15
+ * properties:
16
+ * id:
17
+ * type: string
18
+ * description: The store identifier
19
+ * name:
20
+ * type: string
21
+ * description: Store name
22
+ * sellerId:
23
+ * type: string
24
+ * description: Reference to the seller/owner
25
+ * address:
26
+ * type: object
27
+ * properties:
28
+ * city:
29
+ * type: string
30
+ * streetName:
31
+ * type: string
32
+ * postalCode:
33
+ * type: string
34
+ * country:
35
+ * type: string
36
+ * fullAdress:
37
+ * type: string
38
+ * region:
39
+ * type: string
40
+ * countryCode:
41
+ * type: string
42
+ * phone:
43
+ * type: string
44
+ * location:
45
+ * type: object
46
+ * properties:
47
+ * type:
48
+ * type: string
49
+ * enum: [Point]
50
+ * default: Point
51
+ * coordinates:
52
+ * type: array
53
+ * items:
54
+ * type: number
55
+ * description: [longitude, latitude]
56
+ * image:
57
+ * type: string
58
+ * description: Store image URL
59
+ * description:
60
+ * type: string
61
+ * description: Store description
62
+ * isActive:
63
+ * type: boolean
64
+ * default: true
65
+ * description: Whether the store is active
66
+ * ratingCount:
67
+ * type: number
68
+ * default: 0
69
+ * description: Number of ratings
70
+ * ratingSum:
71
+ * type: number
72
+ * default: 0
73
+ * description: Sum of all ratings
74
+ * revenue:
75
+ * type: number
76
+ * default: 0
77
+ * description: Store revenue
78
+ * templateId:
79
+ * type: number
80
+ * default: 1
81
+ * description: Template identifier
82
+ * activated:
83
+ * type: boolean
84
+ * default: false
85
+ * description: Whether the store is activated
86
+ * subscriptionId:
87
+ * type: string
88
+ * description: Reference to subscription
89
+ * createdAt:
90
+ * type: string
91
+ * format: date-time
92
+ * updatedAt:
93
+ * type: string
94
+ * format: date-time
95
+ * example:
96
+ * id: "507f1f77bcf86cd799439011"
97
+ * name: "Tech Store"
98
+ * sellerId: "507f1f77bcf86cd799439012"
99
+ * description: "Electronics and gadgets store"
100
+ * image: "store-image.jpg"
101
+ * isActive: true
102
+ * ratingCount: 150
103
+ * ratingSum: 735
104
+ * revenue: 25000
105
+ * activated: true
106
+ * createdAt: "2025-11-01T10:30:00.000Z"
107
+ * updatedAt: "2025-12-01T15:45:00.000Z"
108
+ */
7
109
  const storeSchema = new mongoose.Schema(
8
110
  {
9
111
  name: {
@@ -237,8 +339,8 @@ const storeSchema = new mongoose.Schema(
237
339
  ref: 'Subscription',
238
340
  },
239
341
  },
240
- { timestamps: true }
241
- //{ timestamps: true, toJSON: { virtuals: true } }
342
+
343
+ { timestamps: true, toJSON: { virtuals: true } }
242
344
  );
243
345
  //virtual image url
244
346
  storeSchema.virtual('imageUrl').get(function () {
@@ -1,13 +1,44 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * StoreCategory:
8
+ * type: object
9
+ * required:
10
+ * - name
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The store category identifier
15
+ * name:
16
+ * type: string
17
+ * description: Store category name
18
+ * confirmed:
19
+ * type: boolean
20
+ * default: false
21
+ * description: Whether the category is confirmed
22
+ * createdAt:
23
+ * type: string
24
+ * format: date-time
25
+ * updatedAt:
26
+ * type: string
27
+ * format: date-time
28
+ * example:
29
+ * id: "507f1f77bcf86cd799439011"
30
+ * name: "Grocery Store"
31
+ * confirmed: true
32
+ * createdAt: "2025-11-01T10:30:00.000Z"
33
+ * updatedAt: "2025-12-01T15:45:00.000Z"
34
+ */
3
35
  const storeCategorySchema = new mongoose.Schema(
4
36
  {
5
37
  name: {
6
38
  type: String,
7
- required: true,
8
- } ,
9
-
10
- confirmed : { type : Boolean , default : false } ,
39
+ required: true
40
+ },
41
+ confirmed: { type: Boolean, default: false }
11
42
  },
12
43
  { timestamps: true, toJSON: { virtuals: true } }
13
44
  );
@@ -1,5 +1,34 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * StoreRate:
8
+ * type: object
9
+ * required:
10
+ * - userId
11
+ * - storeId
12
+ * properties:
13
+ * id:
14
+ * type: string
15
+ * description: The store rate identifier
16
+ * userId:
17
+ * type: string
18
+ * description: Reference to the user
19
+ * storeId:
20
+ * type: string
21
+ * description: Reference to the store
22
+ * rate:
23
+ * type: number
24
+ * default: 0
25
+ * description: Rating value
26
+ * example:
27
+ * id: "507f1f77bcf86cd799439011"
28
+ * userId: "507f1f77bcf86cd799439012"
29
+ * storeId: "507f1f77bcf86cd799439013"
30
+ * rate: 4.5
31
+ */
3
32
  const storeRateSchema = new mongoose.Schema(
4
33
  {
5
34
  userId: {
@@ -10,12 +39,12 @@ const storeRateSchema = new mongoose.Schema(
10
39
  storeId: {
11
40
  type: mongoose.Schema.Types.ObjectId,
12
41
  required: true,
13
- ref: 'User',
42
+ ref: 'User'
14
43
  },
15
44
  rate: {
16
45
  type: Number,
17
- default: 0,
18
- },
46
+ default: 0
47
+ }
19
48
  },
20
49
  { toJSON: { virtuals: true } }
21
50
  );
@@ -1,5 +1,68 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * Subscription:
8
+ * type: object
9
+ * required:
10
+ * - storeId
11
+ * - paymentAmount
12
+ * - startDate
13
+ * - endDate
14
+ * properties:
15
+ * id:
16
+ * type: string
17
+ * description: The subscription identifier
18
+ * paymentManagerId:
19
+ * type: string
20
+ * description: Reference to the payment manager
21
+ * storeId:
22
+ * type: string
23
+ * description: Reference to the store
24
+ * planId:
25
+ * type: string
26
+ * description: Reference to the plan
27
+ * subscriptionOfferId:
28
+ * type: string
29
+ * description: Reference to subscription offer
30
+ * paymentAmount:
31
+ * type: number
32
+ * description: Payment amount
33
+ * paymentTypeId:
34
+ * type: string
35
+ * description: Reference to payment type
36
+ * reductionOfferId:
37
+ * type: string
38
+ * description: Reference to reduction offer
39
+ * status:
40
+ * type: string
41
+ * enum: [inactive, active, delayed, suspended, upcoming, deleted]
42
+ * default: inactive
43
+ * description: Subscription status
44
+ * startDate:
45
+ * type: string
46
+ * format: date-time
47
+ * description: Subscription start date
48
+ * endDate:
49
+ * type: string
50
+ * format: date-time
51
+ * description: Subscription end date
52
+ * notes:
53
+ * type: array
54
+ * items:
55
+ * type: string
56
+ * description: Notes about the subscription
57
+ * example:
58
+ * id: "507f1f77bcf86cd799439011"
59
+ * storeId: "507f1f77bcf86cd799439012"
60
+ * planId: "507f1f77bcf86cd799439013"
61
+ * paymentAmount: 99.99
62
+ * status: "active"
63
+ * startDate: "2025-12-01T00:00:00.000Z"
64
+ * endDate: "2026-12-01T00:00:00.000Z"
65
+ */
3
66
  const subscriptionSchema = new mongoose.Schema(
4
67
  {
5
68
  paymentManagerId: {
@@ -1,5 +1,37 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * SubscriptionOffer:
8
+ * type: object
9
+ * required:
10
+ * - discount
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The subscription offer identifier
15
+ * discount:
16
+ * type: number
17
+ * description: Discount amount or percentage
18
+ * isActive:
19
+ * type: boolean
20
+ * default: false
21
+ * description: Whether the offer is active
22
+ * createdAt:
23
+ * type: string
24
+ * format: date-time
25
+ * updatedAt:
26
+ * type: string
27
+ * format: date-time
28
+ * example:
29
+ * id: "507f1f77bcf86cd799439011"
30
+ * discount: 20
31
+ * isActive: true
32
+ * createdAt: "2025-11-01T10:30:00.000Z"
33
+ * updatedAt: "2025-12-01T15:45:00.000Z"
34
+ */
3
35
  const subscriptionOfferSchema = new mongoose.Schema(
4
36
  {
5
37
  discount: {
package/models/User.js CHANGED
@@ -1,7 +1,124 @@
1
1
  const mongoose = require('mongoose');
2
- const { policySchema } = require('./Policy');
3
- var ObjectId = require('mongodb').ObjectID;
2
+ const { policySchema } = require('database-connector/models/Policy');
4
3
 
4
+ /**
5
+ * @swagger
6
+ * components:
7
+ * schemas:
8
+ * User:
9
+ * type: object
10
+ * required:
11
+ * - password
12
+ * properties:
13
+ * id:
14
+ * type: string
15
+ * description: The user identifier
16
+ * password:
17
+ * type: string
18
+ * minLength: 8
19
+ * description: User password (must contain at least one letter and one number)
20
+ * username:
21
+ * type: string
22
+ * description: Unique username
23
+ * role:
24
+ * type: string
25
+ * enum: [user, admin, seller, paymentManager, manager, SuperManager]
26
+ * default: user
27
+ * description: User role
28
+ * isAdmin:
29
+ * type: boolean
30
+ * default: false
31
+ * description: Whether the user is an admin
32
+ * companyName:
33
+ * type: string
34
+ * description: Company name
35
+ * phone:
36
+ * type: string
37
+ * description: User phone number
38
+ * verificationCode:
39
+ * type: string
40
+ * description: Verification code for account
41
+ * isVerified:
42
+ * type: boolean
43
+ * default: false
44
+ * description: Whether the user is verified
45
+ * welcome:
46
+ * type: boolean
47
+ * default: false
48
+ * description: Welcome status
49
+ * profileImage:
50
+ * type: string
51
+ * description: Profile image URL
52
+ * discountCode:
53
+ * type: string
54
+ * description: Discount code
55
+ * email:
56
+ * type: string
57
+ * description: User email address
58
+ * favouritsProductst:
59
+ * type: array
60
+ * items:
61
+ * type: object
62
+ * properties:
63
+ * productId:
64
+ * type: string
65
+ * description: List of favorite products
66
+ * adresse:
67
+ * type: object
68
+ * properties:
69
+ * latitude:
70
+ * type: number
71
+ * longitude:
72
+ * type: number
73
+ * countryCode:
74
+ * type: string
75
+ * country:
76
+ * type: string
77
+ * city:
78
+ * type: string
79
+ * postalCode:
80
+ * type: string
81
+ * locality:
82
+ * type: string
83
+ * apartmentNumber:
84
+ * type: string
85
+ * streetName:
86
+ * type: string
87
+ * region:
88
+ * type: string
89
+ * fullAddress:
90
+ * type: string
91
+ * proximityRange:
92
+ * type: number
93
+ * default: 20
94
+ * description: Proximity range in kilometers
95
+ * storeCategorieIds:
96
+ * type: array
97
+ * items:
98
+ * type: string
99
+ * description: Store category references
100
+ * storeSubs:
101
+ * type: array
102
+ * items:
103
+ * type: string
104
+ * description: Subscribed stores
105
+ * createdAt:
106
+ * type: string
107
+ * format: date-time
108
+ * updatedAt:
109
+ * type: string
110
+ * format: date-time
111
+ * example:
112
+ * id: "507f1f77bcf86cd799439011"
113
+ * username: "john_doe"
114
+ * role: "user"
115
+ * email: "john.doe@example.com"
116
+ * phone: "+1234567890"
117
+ * isVerified: true
118
+ * proximityRange: 25
119
+ * createdAt: "2025-11-01T10:30:00.000Z"
120
+ * updatedAt: "2025-12-01T15:45:00.000Z"
121
+ */
5
122
  const userSchema = new mongoose.Schema(
6
123
  {
7
124
  password: {
@@ -20,7 +137,7 @@ const userSchema = new mongoose.Schema(
20
137
  },
21
138
  role: {
22
139
  type: String,
23
- enum: ['user', 'admin', 'seller', 'paymentManager','manager','SuperManager'],
140
+ enum: ['user', 'admin', 'seller', 'paymentManager', 'manager', 'SuperManager'],
24
141
  default: 'user',
25
142
  },
26
143
  isAdmin: { type: Boolean, default: false },
@@ -93,6 +210,12 @@ const userSchema = new mongoose.Schema(
93
210
  ref: 'StoreCategory',
94
211
  },
95
212
  ],
213
+ storeSubs: [
214
+ {
215
+ type: mongoose.Schema.Types.ObjectId,
216
+ ref: 'Store',
217
+ },
218
+ ],
96
219
  productCategorieIds: [
97
220
  {
98
221
  categoryId: {
@@ -0,0 +1,72 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * UserAction:
8
+ * type: object
9
+ * required:
10
+ * - type
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The user action identifier
15
+ * userId:
16
+ * type: string
17
+ * description: Reference to the user
18
+ * type:
19
+ * type: string
20
+ * description: Type of action
21
+ * deviceId:
22
+ * type: string
23
+ * description: Device identifier
24
+ * sessionId:
25
+ * type: string
26
+ * description: Session identifier
27
+ * details:
28
+ * type: object
29
+ * description: Additional details about the action
30
+ * timestamp:
31
+ * type: string
32
+ * format: date-time
33
+ * description: When the action occurred
34
+ * example:
35
+ * id: "507f1f77bcf86cd799439011"
36
+ * userId: "507f1f77bcf86cd799439012"
37
+ * type: "product_view"
38
+ * deviceId: "device123"
39
+ * sessionId: "session456"
40
+ * timestamp: "2025-12-07T10:30:00.000Z"
41
+ */
42
+ const UserActionSchema = new mongoose.Schema({
43
+ userId: {
44
+ type: mongoose.Schema.Types.ObjectId,
45
+ ref: "User",
46
+ required: false
47
+ },
48
+ type: {
49
+ type: String,
50
+ required: true
51
+ },
52
+ deviceId: {
53
+ type: String,
54
+ required: false
55
+ },
56
+ sessionId: {
57
+ type: String,
58
+ required: false
59
+ },
60
+ details: {
61
+ type: mongoose.Schema.Types.Mixed,
62
+ required: false
63
+ },
64
+ timestamp: {
65
+ type: Date,
66
+ default: Date.now
67
+ }
68
+ });
69
+
70
+ const UserAction = mongoose.model("UserAction", UserActionSchema);
71
+
72
+ module.exports = UserAction;
package/models/View.js CHANGED
@@ -1,13 +1,54 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
+ /**
4
+ * @swagger
5
+ * components:
6
+ * schemas:
7
+ * View:
8
+ * type: object
9
+ * required:
10
+ * - date
11
+ * properties:
12
+ * id:
13
+ * type: string
14
+ * description: The view identifier
15
+ * sellerId:
16
+ * type: string
17
+ * description: Reference to the seller
18
+ * clientId:
19
+ * type: string
20
+ * description: Reference to the client
21
+ * storeId:
22
+ * type: string
23
+ * description: Reference to the store
24
+ * productId:
25
+ * type: string
26
+ * description: Reference to the product
27
+ * date:
28
+ * type: string
29
+ * format: date-time
30
+ * description: The date of the view
31
+ * region:
32
+ * type: string
33
+ * description: Region where the view occurred
34
+ * example:
35
+ * id: "507f1f77bcf86cd799439011"
36
+ * sellerId: "507f1f77bcf86cd799439012"
37
+ * clientId: "507f1f77bcf86cd799439013"
38
+ * storeId: "507f1f77bcf86cd799439014"
39
+ * productId: "507f1f77bcf86cd799439015"
40
+ * date: "2025-12-07T10:30:00.000Z"
41
+ * region: "North Region"
42
+ */
3
43
  const viewsSchema = new mongoose.Schema({
4
- sellerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Seller' },
5
- storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
6
- productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
7
- date: { type: Date, required: true },
8
- region: { type: String }, // If you want to track region for each view
44
+ sellerId: { type: mongoose.Schema.Types.ObjectId, ref: 'Seller' },
45
+ clientId: { type: mongoose.Schema.Types.ObjectId, ref: 'Client' },
46
+ storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
47
+ productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
48
+ date: { type: Date, required: true },
49
+ region: { type: String }
9
50
  });
10
51
 
11
- module.exports = mongoose.model('View', viewsSchema);
52
+ module.exports = mongoose.model('View', viewsSchema);
12
53
 
13
54
 
package/models/index.js CHANGED
@@ -31,17 +31,17 @@ const SubscriptionOffer = require('./SubscriptionOffer');
31
31
  const FlashDeal = require('./FlashDeal');
32
32
  const Notification = require('./Notification');
33
33
  const PaymentType = require('./PaymentType');
34
- const {policySchema} = require('./Policy');
34
+ const Policy = require('./Policy');
35
35
  const ReductionOffer = require('./ReductionOffer');
36
36
  const Sale = require('./Sale');
37
37
  const StoreCategory = require('./StoreCategory');
38
-
38
+ const UserAction = require('./UserAction.js');
39
39
 
40
40
 
41
41
  module.exports = {
42
42
  connectToDatabase,
43
43
  PaymentType,
44
- policySchema,
44
+ Policy,
45
45
  ReductionOffer,
46
46
  Sale,
47
47
  StoreCategory,
@@ -62,5 +62,6 @@ module.exports = {
62
62
  Subscription,
63
63
  Plan,
64
64
  SubscriptionOffer,
65
- ObjectId: mongoose.Types.ObjectId,
65
+ UserAction,
66
+ ObjectId: mongoose.Types.ObjectId,
66
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "main": "models/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -10,6 +10,6 @@
10
10
  "license": "ISC",
11
11
  "description": "",
12
12
  "dependencies": {
13
- "mongoose": "^6.2.10"
13
+ "mongoose": "^6.2.10"
14
14
  }
15
15
  }