database-connector 1.0.7 → 2.0.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,112 @@
1
1
  const mongoose = require('mongoose');
2
- const User = require('database-connector/models/User');
3
- const Product = require('database-connector/models/Product');
4
2
  const { policySchema } = require('database-connector/models/Policy');
5
- var ObjectId = require('mongodb').ObjectID;
3
+ const { getBaseURL, getDefaultStoreImagePath } = require('../config');
6
4
 
5
+ /**
6
+ * @swagger
7
+ * components:
8
+ * schemas:
9
+ * Store:
10
+ * type: object
11
+ * required:
12
+ * - name
13
+ * - sellerId
14
+ * - image
15
+ * - description
16
+ * properties:
17
+ * id:
18
+ * type: string
19
+ * description: The store identifier
20
+ * name:
21
+ * type: string
22
+ * description: Store name
23
+ * sellerId:
24
+ * type: string
25
+ * description: Reference to the seller/owner
26
+ * address:
27
+ * type: object
28
+ * properties:
29
+ * city:
30
+ * type: string
31
+ * streetName:
32
+ * type: string
33
+ * postalCode:
34
+ * type: string
35
+ * country:
36
+ * type: string
37
+ * fullAdress:
38
+ * type: string
39
+ * region:
40
+ * type: string
41
+ * countryCode:
42
+ * type: string
43
+ * phone:
44
+ * type: string
45
+ * location:
46
+ * type: object
47
+ * properties:
48
+ * type:
49
+ * type: string
50
+ * enum: [Point]
51
+ * default: Point
52
+ * coordinates:
53
+ * type: array
54
+ * items:
55
+ * type: number
56
+ * description: [longitude, latitude]
57
+ * image:
58
+ * type: string
59
+ * description: Store image URL
60
+ * description:
61
+ * type: string
62
+ * description: Store description
63
+ * isActive:
64
+ * type: boolean
65
+ * default: true
66
+ * description: Whether the store is active
67
+ * ratingCount:
68
+ * type: number
69
+ * default: 0
70
+ * description: Number of ratings
71
+ * ratingSum:
72
+ * type: number
73
+ * default: 0
74
+ * description: Sum of all ratings
75
+ * revenue:
76
+ * type: number
77
+ * default: 0
78
+ * description: Store revenue
79
+ * templateId:
80
+ * type: number
81
+ * default: 1
82
+ * description: Template identifier
83
+ * activated:
84
+ * type: boolean
85
+ * default: false
86
+ * description: Whether the store is activated
87
+ * subscriptionId:
88
+ * type: string
89
+ * description: Reference to subscription
90
+ * createdAt:
91
+ * type: string
92
+ * format: date-time
93
+ * updatedAt:
94
+ * type: string
95
+ * format: date-time
96
+ * example:
97
+ * id: "507f1f77bcf86cd799439011"
98
+ * name: "Tech Store"
99
+ * sellerId: "507f1f77bcf86cd799439012"
100
+ * description: "Electronics and gadgets store"
101
+ * image: "store-image.jpg"
102
+ * isActive: true
103
+ * ratingCount: 150
104
+ * ratingSum: 735
105
+ * revenue: 25000
106
+ * activated: true
107
+ * createdAt: "2025-11-01T10:30:00.000Z"
108
+ * updatedAt: "2025-12-01T15:45:00.000Z"
109
+ */
7
110
  const storeSchema = new mongoose.Schema(
8
111
  {
9
112
  name: {
@@ -240,12 +343,12 @@ const storeSchema = new mongoose.Schema(
240
343
 
241
344
  { timestamps: true, toJSON: { virtuals: true } }
242
345
  );
243
- //virtual image url
346
+ // Virtual: image URL with base path
244
347
  storeSchema.virtual('imageUrl').get(function () {
245
348
  if (this.image != null) {
246
- return `${process.env.APP_URL}/${this.image}`;
349
+ return `${getBaseURL()}/${this.image}`;
247
350
  }
248
- return `${process.env.APP_URL}/images/stores/default.jpg`;
351
+ return `${getBaseURL()}${getDefaultStoreImagePath()}`;
249
352
  });
250
353
  //virtual rating
251
354
  storeSchema.virtual('rating').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
2
  const { policySchema } = require('database-connector/models/Policy');
3
- var ObjectId = require('mongodb').ObjectID;
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: {
@@ -1,5 +1,44 @@
1
1
  const mongoose = require("mongoose");
2
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
+ */
3
42
  const UserActionSchema = new mongoose.Schema({
4
43
  userId: {
5
44
  type: mongoose.Schema.Types.ObjectId,
package/models/View.js CHANGED
@@ -1,12 +1,52 @@
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
- clientId: { type: mongoose.Schema.Types.ObjectId, ref: 'Client' },
6
- storeId: { type: mongoose.Schema.Types.ObjectId, ref: 'Store' },
7
- productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' },
8
- date: { type: Date, required: true },
9
- 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 }
10
50
  });
11
51
 
12
52
  module.exports = mongoose.model('View', viewsSchema);
package/models/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const mongoose = require('mongoose');
2
+ const config = require('../config');
2
3
 
3
4
  const connectToDatabase = async (databaseUrl) => {
4
5
  try {
@@ -31,7 +32,7 @@ const SubscriptionOffer = require('./SubscriptionOffer');
31
32
  const FlashDeal = require('./FlashDeal');
32
33
  const Notification = require('./Notification');
33
34
  const PaymentType = require('./PaymentType');
34
- const { policySchema } = require('./Policy');
35
+ const Policy = require('./Policy');
35
36
  const ReductionOffer = require('./ReductionOffer');
36
37
  const Sale = require('./Sale');
37
38
  const StoreCategory = require('./StoreCategory');
@@ -40,8 +41,10 @@ const UserAction = require('./UserAction.js');
40
41
 
41
42
  module.exports = {
42
43
  connectToDatabase,
44
+ configure: config.configure,
45
+ getConfig: config.getConfig,
43
46
  PaymentType,
44
- policySchema,
47
+ Policy,
45
48
  ReductionOffer,
46
49
  Sale,
47
50
  StoreCategory,
package/package.json CHANGED
@@ -1,15 +1,36 @@
1
1
  {
2
2
  "name": "database-connector",
3
- "version": "1.0.7",
3
+ "version": "2.0.0",
4
+ "description": "MongoDB models package with Mongoose schemas for e-commerce applications. Includes User, Product, Store, Order and more with built-in validation and virtual properties.",
4
5
  "main": "models/index.js",
5
6
  "scripts": {
6
7
  "test": "echo \"Error: no test specified\" && exit 1"
7
8
  },
8
- "keywords": [],
9
+ "keywords": [
10
+ "mongoose",
11
+ "mongodb",
12
+ "models",
13
+ "schemas",
14
+ "ecommerce",
15
+ "database",
16
+ "user",
17
+ "product",
18
+ "store",
19
+ "order"
20
+ ],
9
21
  "author": "",
10
22
  "license": "ISC",
11
- "description": "",
12
23
  "dependencies": {
13
- "mongoose": "^6.2.10"
24
+ "mongoose": "^6.2.10"
25
+ },
26
+ "files": [
27
+ "models/",
28
+ "config.js",
29
+ "README.md",
30
+ "CHANGELOG.md"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": ""
14
35
  }
15
36
  }