@unchainedshop/core-products 4.8.29 → 4.8.30
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/lib/db/ProductVariationsCollection.d.ts +1 -0
- package/lib/db/ProductVariationsCollection.js +1 -1
- package/lib/module/configureProductVariationsModule.d.ts +1 -1
- package/lib/module/configureProductVariationsModule.js +7 -1
- package/lib/module/configureProductsModule.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ export const ProductVariationType = {
|
|
|
6
6
|
export const ProductVariationsCollection = async (db) => {
|
|
7
7
|
const ProductVariations = db.collection('product_variations');
|
|
8
8
|
const ProductVariationTexts = db.collection('product_variation_texts');
|
|
9
|
-
await buildDbIndexes(ProductVariations, [{ index: { productId: 1 } }]);
|
|
9
|
+
await buildDbIndexes(ProductVariations, [{ index: { productId: 1, sortKey: 1 } }]);
|
|
10
10
|
await buildDbIndexes(ProductVariationTexts, [
|
|
11
11
|
{ index: { productVariationId: 1 } },
|
|
12
12
|
{ index: { locale: 1, productVariationId: 1 } },
|
|
@@ -17,7 +17,7 @@ export declare const configureProductVariationsModule: ({ db }: ModuleInput<Reco
|
|
|
17
17
|
limit?: number;
|
|
18
18
|
offset?: number;
|
|
19
19
|
}, options?: mongodb.FindOptions) => Promise<ProductVariation[]>;
|
|
20
|
-
create: ({ type, ...doc }: Omit<ProductVariation, "_id" | "created"> & Pick<Partial<ProductVariation>, "_id" | "created"> & {
|
|
20
|
+
create: ({ type, sortKey, ...doc }: Omit<ProductVariation, "_id" | "created"> & Pick<Partial<ProductVariation>, "_id" | "created"> & {
|
|
21
21
|
locale?: string;
|
|
22
22
|
title?: string;
|
|
23
23
|
}) => Promise<ProductVariation>;
|
|
@@ -70,16 +70,22 @@ export const configureProductVariationsModule = async ({ db }) => {
|
|
|
70
70
|
const variations = ProductVariations.find(selector, {
|
|
71
71
|
skip: offset,
|
|
72
72
|
limit,
|
|
73
|
+
sort: { sortKey: 1 },
|
|
73
74
|
...options,
|
|
74
75
|
});
|
|
75
76
|
return variations.toArray();
|
|
76
77
|
},
|
|
77
|
-
create: async ({ type, ...doc }) => {
|
|
78
|
+
create: async ({ type, sortKey, ...doc }) => {
|
|
79
|
+
if (sortKey === undefined || sortKey === null) {
|
|
80
|
+
const lastProductVariation = (await ProductVariations.findOne({ productId: doc.productId }, { sort: { sortKey: -1 } })) || { sortKey: 0 };
|
|
81
|
+
sortKey = (lastProductVariation.sortKey || 0) + 1;
|
|
82
|
+
}
|
|
78
83
|
const { insertedId: productVariationId } = await ProductVariations.insertOne({
|
|
79
84
|
_id: generateDbObjectId(),
|
|
80
85
|
created: new Date(),
|
|
81
86
|
type: ProductVariationType[type],
|
|
82
87
|
...doc,
|
|
88
|
+
sortKey,
|
|
83
89
|
});
|
|
84
90
|
const productVariation = (await ProductVariations.findOne(generateDbFilterById(productVariationId), {}));
|
|
85
91
|
await emit('PRODUCT_CREATE_VARIATION', {
|
|
@@ -222,7 +222,7 @@ export declare const configureProductsModule: (moduleInput: ModuleInput<Products
|
|
|
222
222
|
limit?: number;
|
|
223
223
|
offset?: number;
|
|
224
224
|
}, options?: mongodb.FindOptions) => Promise<import("../products-index.ts").ProductVariation[]>;
|
|
225
|
-
create: ({ type, ...doc }: Omit<import("../products-index.ts").ProductVariation, "_id" | "created"> & Pick<Partial<import("../products-index.ts").ProductVariation>, "_id" | "created"> & {
|
|
225
|
+
create: ({ type, sortKey, ...doc }: Omit<import("../products-index.ts").ProductVariation, "_id" | "created"> & Pick<Partial<import("../products-index.ts").ProductVariation>, "_id" | "created"> & {
|
|
226
226
|
locale?: string;
|
|
227
227
|
title?: string;
|
|
228
228
|
}) => Promise<import("../products-index.ts").ProductVariation>;
|
package/package.json
CHANGED