database-connector 2.2.4 → 2.2.6
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/Advertisement.js +73 -0
- package/models/Product.js +23 -23
- package/models/Store.js +6 -6
- package/models/index.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @swagger
|
|
5
|
+
* components:
|
|
6
|
+
* schemas:
|
|
7
|
+
* Advertisement:
|
|
8
|
+
* type: object
|
|
9
|
+
* required:
|
|
10
|
+
* - sellerId
|
|
11
|
+
* - storeId
|
|
12
|
+
* - productId
|
|
13
|
+
* - image
|
|
14
|
+
* properties:
|
|
15
|
+
* id:
|
|
16
|
+
* type: string
|
|
17
|
+
* description: The advertisement identifier
|
|
18
|
+
* sellerId:
|
|
19
|
+
* type: string
|
|
20
|
+
* description: Reference to seller
|
|
21
|
+
* storeId:
|
|
22
|
+
* type: string
|
|
23
|
+
* description: Reference to store
|
|
24
|
+
* productId:
|
|
25
|
+
* type: string
|
|
26
|
+
* description: Reference to product
|
|
27
|
+
* image:
|
|
28
|
+
* type: string
|
|
29
|
+
* description: Advertisement image (URL or path)
|
|
30
|
+
* confirmed:
|
|
31
|
+
* type: boolean
|
|
32
|
+
* default: false
|
|
33
|
+
* description: Whether the advertisement is approved by a manager
|
|
34
|
+
* createdAt:
|
|
35
|
+
* type: string
|
|
36
|
+
* format: date-time
|
|
37
|
+
* updatedAt:
|
|
38
|
+
* type: string
|
|
39
|
+
* format: date-time
|
|
40
|
+
*/
|
|
41
|
+
const advertisementSchema = new mongoose.Schema(
|
|
42
|
+
{
|
|
43
|
+
sellerId: {
|
|
44
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
45
|
+
ref: 'User',
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
storeId: {
|
|
49
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
50
|
+
ref: 'Store',
|
|
51
|
+
required: true,
|
|
52
|
+
},
|
|
53
|
+
productId: {
|
|
54
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
55
|
+
ref: 'Product',
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
image: {
|
|
59
|
+
type: String,
|
|
60
|
+
required: true,
|
|
61
|
+
},
|
|
62
|
+
confirmed: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: false,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
timestamps: true,
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
module.exports = mongoose.model('Advertisement', advertisementSchema);
|
package/models/Product.js
CHANGED
|
@@ -259,16 +259,16 @@ productSchema.virtual('PriceMax').get(function () {
|
|
|
259
259
|
*/
|
|
260
260
|
|
|
261
261
|
// Virtual: array of all product images with full URLs
|
|
262
|
-
productSchema.virtual('imagesss').get(function () {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
});
|
|
262
|
+
// productSchema.virtual('imagesss').get(function () {
|
|
263
|
+
// if (this.images != null) {
|
|
264
|
+
// const images = this.images;
|
|
265
|
+
// console.log(images);
|
|
266
|
+
// console.log('images');
|
|
267
|
+
// return images.map(function (image) {
|
|
268
|
+
// return `${getBaseURL()}/${image}`;
|
|
269
|
+
// });
|
|
270
|
+
// }
|
|
271
|
+
// });
|
|
272
272
|
|
|
273
273
|
// Virtual: discounted price
|
|
274
274
|
productSchema.virtual('discounted').get(function () {
|
|
@@ -281,19 +281,19 @@ productSchema.virtual('discounted').get(function () {
|
|
|
281
281
|
});
|
|
282
282
|
|
|
283
283
|
// Virtual: array of all variant images with full URLs
|
|
284
|
-
productSchema.virtual('variantImages').get(function () {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
});
|
|
284
|
+
// productSchema.virtual('variantImages').get(function () {
|
|
285
|
+
// if (this.variants != null) {
|
|
286
|
+
// const variants = this.variants;
|
|
287
|
+
// console.log(variants);
|
|
288
|
+
// return variants.map(function (variant) {
|
|
289
|
+
// if (variant.img != null) {
|
|
290
|
+
// return `${getBaseURL()}/${variant.img}`;
|
|
291
|
+
// } else {
|
|
292
|
+
// return `${getBaseURL()}${getDefaultImagePath()}`;
|
|
293
|
+
// }
|
|
294
|
+
// });
|
|
295
|
+
// }
|
|
296
|
+
// });
|
|
297
297
|
|
|
298
298
|
// Indexes for performance optimization
|
|
299
299
|
productSchema.index({ storeId: 1, deleted: 1 });
|
package/models/Store.js
CHANGED
|
@@ -379,12 +379,12 @@ const storeSchema = new mongoose.Schema(
|
|
|
379
379
|
{ timestamps: true, toJSON: { virtuals: true } }
|
|
380
380
|
);
|
|
381
381
|
// Virtual: image URL with base path
|
|
382
|
-
storeSchema.virtual('imageUrl').get(function () {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
});
|
|
382
|
+
// storeSchema.virtual('imageUrl').get(function () {
|
|
383
|
+
// if (this.image != null) {
|
|
384
|
+
// return `${getBaseURL()}/${this.image}`;
|
|
385
|
+
// }
|
|
386
|
+
// return `${getBaseURL()}${getDefaultStoreImagePath()}`;
|
|
387
|
+
// });
|
|
388
388
|
//virtual rating
|
|
389
389
|
storeSchema.virtual('rating').get(function () {
|
|
390
390
|
if (this.ratingSum != 0 && this.ratingCount != 0) {
|
package/models/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const ReductionOffer = require('./ReductionOffer');
|
|
|
40
40
|
const Sale = require('./Sale');
|
|
41
41
|
const StoreCategory = require('./StoreCategory');
|
|
42
42
|
const UserAction = require('./UserAction.js');
|
|
43
|
+
const Advertisement = require('./Advertisement');
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
module.exports = {
|
|
@@ -71,5 +72,6 @@ module.exports = {
|
|
|
71
72
|
Plan,
|
|
72
73
|
SubscriptionOffer,
|
|
73
74
|
UserAction,
|
|
75
|
+
Advertisement,
|
|
74
76
|
ObjectId: mongoose.Types.ObjectId,
|
|
75
77
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "database-connector",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6",
|
|
4
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.",
|
|
5
5
|
"main": "models/index.js",
|
|
6
6
|
"scripts": {
|