@primershop/strapi-plugin-product-actions 0.0.3 → 0.0.5
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/dist/server/index.js +1 -4
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/package.json +3 -2
- package/dist/admin/src/components/Initializer/index.js +0 -13
- package/dist/admin/src/components/SeriesProductActions/index.js +0 -84
- package/dist/admin/src/index.js +0 -22
- package/dist/admin/src/pluginId.js +0 -1
- package/dist/admin/src/translations/en.js +0 -21
- package/dist/admin/src/translations/index.js +0 -1
- package/dist/server/src/bootstrap.js +0 -16
- package/dist/server/src/controllers/index.js +0 -10
- package/dist/server/src/controllers/product-series.js +0 -31
- package/dist/server/src/index.js +0 -20
- package/dist/server/src/permissions.js +0 -42
- package/dist/server/src/pluginId.js +0 -4
- package/dist/server/src/register.js +0 -14
- package/dist/server/src/routes/admin.js +0 -37
- package/dist/server/src/routes/index.js +0 -9
- package/dist/server/src/services/index.js +0 -7
- package/dist/server/src/services/product-series.js +0 -116
package/dist/server/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var index$2 = require('./controllers/index.js');
|
|
6
4
|
var index$1 = require('./routes/index.js');
|
|
7
5
|
var index = require('./services/index.js');
|
|
@@ -19,6 +17,5 @@ const plugin = ()=>{
|
|
|
19
17
|
};
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
exports
|
|
23
|
-
exports.plugin = plugin;
|
|
20
|
+
module.exports = plugin;
|
|
24
21
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../server/src/index.ts"],"sourcesContent":["import { controllers } from \"./controllers\";\r\nimport { routes } from \"./routes\";\r\nimport { services } from \"./services\";\r\nimport { register } from \"./register\";\r\nimport { bootstrap } from \"./bootstrap\";\r\n\r\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../server/src/index.ts"],"sourcesContent":["import { controllers } from \"./controllers\";\r\nimport { routes } from \"./routes\";\r\nimport { services } from \"./services\";\r\nimport { register } from \"./register\";\r\nimport { bootstrap } from \"./bootstrap\";\r\n\r\nconst plugin = () => {\r\n return {\r\n register,\r\n\r\n controllers,\r\n routes,\r\n services,\r\n middlewares: {},\r\n bootstrap,\r\n };\r\n};\r\n\r\nexport default plugin;\r\n"],"names":["plugin","register","controllers","routes","services","middlewares","bootstrap"],"mappings":";;;;;;;;AAMA,MAAMA,MAAAA,GAAS,IAAA;IACb,OAAO;AACLC,kBAAAA,iBAAAA;AAEAC,qBAAAA,mBAAAA;AACAC,gBAAAA,cAAAA;AACAC,kBAAAA,cAAAA;AACAC,QAAAA,WAAAA,EAAa,EAAC;AACdC,mBAAAA;AACF,KAAA;AACF;;;;"}
|
package/dist/server/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../server/src/index.ts"],"sourcesContent":["import { controllers } from \"./controllers\";\r\nimport { routes } from \"./routes\";\r\nimport { services } from \"./services\";\r\nimport { register } from \"./register\";\r\nimport { bootstrap } from \"./bootstrap\";\r\n\r\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../server/src/index.ts"],"sourcesContent":["import { controllers } from \"./controllers\";\r\nimport { routes } from \"./routes\";\r\nimport { services } from \"./services\";\r\nimport { register } from \"./register\";\r\nimport { bootstrap } from \"./bootstrap\";\r\n\r\nconst plugin = () => {\r\n return {\r\n register,\r\n\r\n controllers,\r\n routes,\r\n services,\r\n middlewares: {},\r\n bootstrap,\r\n };\r\n};\r\n\r\nexport default plugin;\r\n"],"names":["plugin","register","controllers","routes","services","middlewares","bootstrap"],"mappings":";;;;;;AAMA,MAAMA,MAAAA,GAAS,IAAA;IACb,OAAO;AACLC,QAAAA,QAAAA;AAEAC,QAAAA,WAAAA;AACAC,QAAAA,MAAAA;AACAC,QAAAA,QAAAA;AACAC,QAAAA,WAAAA,EAAa,EAAC;AACdC,QAAAA;AACF,KAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primershop/strapi-plugin-product-actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Enables product actions for Strapi",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./strapi-admin": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "npm-run-all clean --parallel build:code
|
|
22
|
+
"build": "npm-run-all clean --parallel build:code",
|
|
23
23
|
"build:code": "rollup -c",
|
|
24
24
|
"build:types": "run-p build:types:server build:types:admin",
|
|
25
25
|
"build:types:server": "tsc -p server/tsconfig.build.json ",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"keywords": [
|
|
36
36
|
"strapi",
|
|
37
37
|
"plugin",
|
|
38
|
+
"strapi-plugin",
|
|
38
39
|
"product",
|
|
39
40
|
"actions"
|
|
40
41
|
],
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
import { PLUGIN_ID } from "../../pluginId";
|
|
3
|
-
/**
|
|
4
|
-
* @type {import('react').FC<{ setPlugin: (id: string) => void }>}
|
|
5
|
-
*/
|
|
6
|
-
const Initializer = ({ setPlugin }) => {
|
|
7
|
-
const ref = useRef(setPlugin);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
ref.current(PLUGIN_ID);
|
|
10
|
-
}, []);
|
|
11
|
-
return null;
|
|
12
|
-
};
|
|
13
|
-
export { Initializer };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { Box, Button, Typography, Dialog, NumberInput, Flex, MultiSelect, MultiSelectOption, } from "@strapi/design-system";
|
|
4
|
-
import { useFetchClient, unstable_useContentManagerContext as useContentManagerContext, } from "@strapi/strapi/admin";
|
|
5
|
-
import { en } from "../../translations";
|
|
6
|
-
const formatMessage = (arg) => {
|
|
7
|
-
return en[arg.id];
|
|
8
|
-
};
|
|
9
|
-
const valuesToUpdate = [
|
|
10
|
-
"description",
|
|
11
|
-
"shortDescription",
|
|
12
|
-
"media",
|
|
13
|
-
"coverImage",
|
|
14
|
-
"seo",
|
|
15
|
-
"totalCost",
|
|
16
|
-
"wholesalePrice",
|
|
17
|
-
"retailPrice",
|
|
18
|
-
"category",
|
|
19
|
-
"creator",
|
|
20
|
-
];
|
|
21
|
-
const SeriesProductActions = ({ document }) => {
|
|
22
|
-
const { model } = useContentManagerContext();
|
|
23
|
-
const documentId = document?.documentId;
|
|
24
|
-
const [productCount, setProductCount] = useState(1);
|
|
25
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
26
|
-
const [fieldsToUpdate, setFieldsToUpdate] = useState([]);
|
|
27
|
-
const { post, put } = useFetchClient();
|
|
28
|
-
if (model !== "api::product-series.product-series")
|
|
29
|
-
return null;
|
|
30
|
-
const handleCreateProducts = async () => {
|
|
31
|
-
try {
|
|
32
|
-
setIsLoading(true);
|
|
33
|
-
const response = await post(`primer-product-actions/create-products`, {
|
|
34
|
-
count: productCount,
|
|
35
|
-
id: documentId,
|
|
36
|
-
});
|
|
37
|
-
if (!response.data) {
|
|
38
|
-
throw new Error("Failed to create products");
|
|
39
|
-
}
|
|
40
|
-
setProductCount(1);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.error("Error creating products:", error);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
setIsLoading(false);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const handleUpdateProducts = async () => {
|
|
50
|
-
try {
|
|
51
|
-
setIsLoading(true);
|
|
52
|
-
const response = await put(`/primer-product-actions/update-products`, {
|
|
53
|
-
seriesId: documentId,
|
|
54
|
-
fieldsToUpdate,
|
|
55
|
-
});
|
|
56
|
-
if (!response.data) {
|
|
57
|
-
throw new Error("Failed to update products");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("Error updating products:", error);
|
|
62
|
-
}
|
|
63
|
-
finally {
|
|
64
|
-
setIsLoading(false);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
title: "Series Product Actions",
|
|
69
|
-
content: (_jsx(Box, { children: _jsxs(Box, { children: [_jsx(Typography, { variant: "delta", fontWeight: "bold", children: formatMessage({ id: "product-series.actions.label" }) }), _jsxs(Flex, { wrap: "wrap", children: [!documentId && (_jsx(Typography, { display: "block", marginTop: 2, marginBottom: 2, width: "100%", color: "red", children: formatMessage({ id: "product-series.actions.noDocumentId" }) })), _jsxs(Dialog.Root, { children: [_jsx(Dialog.Trigger, { children: _jsx(Button, { variant: "secondary", disabled: isLoading || !documentId, children: formatMessage({
|
|
70
|
-
id: "product-series.actions.createProducts",
|
|
71
|
-
}) }) }), _jsxs(Dialog.Content, { children: [_jsx(Dialog.Body, { children: _jsxs(Box, { children: [_jsx(Typography, { children: formatMessage({
|
|
72
|
-
id: "product-series.actions.createDialogTitle",
|
|
73
|
-
}) }), _jsx(NumberInput, { value: productCount, onValueChange: (value) => setProductCount(value || 1), min: 1, max: 100 })] }) }), _jsxs(Dialog.Footer, { children: [_jsx(Dialog.Cancel, { children: _jsx(Button, { fullWidth: true, variant: "tertiary", children: "Cancel" }) }), _jsx(Dialog.Action, { children: _jsx(Button, { onClick: handleCreateProducts, variant: "default", loading: isLoading, children: formatMessage({ id: "product-series.actions.create" }) }) })] })] })] }), _jsxs(Dialog.Root, { children: [_jsx(Dialog.Trigger, { children: _jsx(Button, { marginLeft: 2, variant: "secondary", disabled: isLoading || !documentId, children: formatMessage({
|
|
74
|
-
id: "product-series.actions.updateProducts",
|
|
75
|
-
}) }) }), _jsxs(Dialog.Content, { children: [_jsxs(Dialog.Body, { display: "flex", direction: "column", gap: 2, justifyContent: "center", alignItems: "center", width: "100%", children: [_jsx(Typography, { variant: "delta", fontWeight: "bold", children: formatMessage({
|
|
76
|
-
id: "product-series.actions.updateDialogTitle",
|
|
77
|
-
}) }), _jsx(Typography, { children: formatMessage({
|
|
78
|
-
id: "product-series.actions.updateDialogDescription",
|
|
79
|
-
}) }), _jsx(MultiSelect, { withTags: true, value: fieldsToUpdate, onClear: () => setFieldsToUpdate([]), onChange: (value) => setFieldsToUpdate(value), required: true, placeholder: formatMessage({
|
|
80
|
-
id: "product-series.actions.selectFields",
|
|
81
|
-
}), children: valuesToUpdate.map((field) => (_jsx(MultiSelectOption, { value: field, children: field }, field))) })] }), _jsxs(Dialog.Footer, { children: [_jsx(Dialog.Cancel, { children: _jsx(Button, { fullWidth: true, variant: "tertiary", children: "Cancel" }) }), _jsx(Dialog.Action, { children: _jsx(Button, { onClick: handleUpdateProducts, variant: "default", loading: isLoading, children: formatMessage({ id: "product-series.actions.update" }) }) })] })] })] })] })] }) })),
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
export { SeriesProductActions };
|
package/dist/admin/src/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Initializer } from "./components/Initializer";
|
|
2
|
-
import { SeriesProductActions } from "./components/SeriesProductActions";
|
|
3
|
-
import { PLUGIN_ID } from "./pluginId";
|
|
4
|
-
const plugin = {
|
|
5
|
-
register(app) {
|
|
6
|
-
app.registerPlugin({
|
|
7
|
-
id: PLUGIN_ID,
|
|
8
|
-
initializer: Initializer,
|
|
9
|
-
isReady: false,
|
|
10
|
-
name: PLUGIN_ID,
|
|
11
|
-
});
|
|
12
|
-
},
|
|
13
|
-
bootstrap(app) {
|
|
14
|
-
console.log("🚀 ~ bootstrap ~ app:", app);
|
|
15
|
-
app
|
|
16
|
-
.getPlugin("content-manager")
|
|
17
|
-
.apis.addEditViewSidePanel((panels) => {
|
|
18
|
-
return [...panels, SeriesProductActions];
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
export default plugin;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PLUGIN_ID = "primer-product-actions";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const en = {
|
|
2
|
-
"plugin.name": "Product Series",
|
|
3
|
-
"plugin.description": "Manage product series and their products",
|
|
4
|
-
"product-series.actions.label": "Product Actions",
|
|
5
|
-
"product-series.actions.createProducts": "Create Products",
|
|
6
|
-
"product-series.actions.updateProducts": "Update Products",
|
|
7
|
-
"product-series.actions.createDialogTitle": "Create Products from Series",
|
|
8
|
-
"product-series.actions.updateDialogTitle": "Update All Products in Series",
|
|
9
|
-
"product-series.actions.updateDialogDescription": "This will update all products in the series with the selected fields. Make sure to save the series first before updating the products.",
|
|
10
|
-
"product-series.actions.productCount": "Number of Products",
|
|
11
|
-
"product-series.actions.create": "Create",
|
|
12
|
-
"product-series.actions.update": "Update",
|
|
13
|
-
"product-series.actions.cancel": "Cancel",
|
|
14
|
-
"product-series.actions.createSuccess": "Products created successfully",
|
|
15
|
-
"product-series.actions.createError": "Failed to create products",
|
|
16
|
-
"product-series.actions.updateSuccess": "Products updated successfully",
|
|
17
|
-
"product-series.actions.updateError": "Failed to update products",
|
|
18
|
-
"product-series.actions.selectFields": "Select fields to update",
|
|
19
|
-
"product-series.actions.noDocumentId": "Save the series first before creating products",
|
|
20
|
-
};
|
|
21
|
-
export { en };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./en";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bootstrap = void 0;
|
|
4
|
-
const permissions_1 = require("./permissions");
|
|
5
|
-
const bootstrap = async ({ strapi }) => {
|
|
6
|
-
// Register permissions for the plugin
|
|
7
|
-
try {
|
|
8
|
-
await strapi
|
|
9
|
-
.service("admin::permission")
|
|
10
|
-
.actionProvider.registerMany(permissions_1.permissions.actions);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
// Handle error silently or log to proper logging service
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
exports.bootstrap = bootstrap;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.controllers = void 0;
|
|
7
|
-
const product_series_1 = __importDefault(require("./product-series"));
|
|
8
|
-
exports.controllers = {
|
|
9
|
-
productSeries: product_series_1.default,
|
|
10
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const productSeries = ({ strapi, }) => ({
|
|
4
|
-
async createProducts(ctx) {
|
|
5
|
-
try {
|
|
6
|
-
const { id, count = 1 } = ctx.request.body;
|
|
7
|
-
const products = await strapi
|
|
8
|
-
.plugin("primer-product-actions")
|
|
9
|
-
.service("productSeries")
|
|
10
|
-
.createProductsFromSeries(id, count);
|
|
11
|
-
return { data: products };
|
|
12
|
-
}
|
|
13
|
-
catch (error) {
|
|
14
|
-
ctx.throw(500, error);
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
async updateProducts(ctx) {
|
|
18
|
-
try {
|
|
19
|
-
const { seriesId, fieldsToUpdate } = ctx.request.body;
|
|
20
|
-
await strapi
|
|
21
|
-
.plugin("primer-product-actions")
|
|
22
|
-
.service("productSeries")
|
|
23
|
-
.updateSeriesProducts(seriesId, fieldsToUpdate);
|
|
24
|
-
return { success: true };
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
ctx.throw(500, error);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
exports.default = productSeries;
|
package/dist/server/src/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.plugin = void 0;
|
|
4
|
-
const controllers_1 = require("./controllers");
|
|
5
|
-
const routes_1 = require("./routes");
|
|
6
|
-
const services_1 = require("./services");
|
|
7
|
-
const register_1 = require("./register");
|
|
8
|
-
const bootstrap_1 = require("./bootstrap");
|
|
9
|
-
const plugin = () => {
|
|
10
|
-
return {
|
|
11
|
-
register: register_1.register,
|
|
12
|
-
controllers: controllers_1.controllers,
|
|
13
|
-
routes: routes_1.routes,
|
|
14
|
-
services: services_1.services,
|
|
15
|
-
middlewares: {},
|
|
16
|
-
bootstrap: bootstrap_1.bootstrap,
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
exports.plugin = plugin;
|
|
20
|
-
exports.default = exports.plugin;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.permissions = void 0;
|
|
4
|
-
exports.permissions = {
|
|
5
|
-
actions: [
|
|
6
|
-
{
|
|
7
|
-
// Roles
|
|
8
|
-
section: "plugins",
|
|
9
|
-
displayName: "Create",
|
|
10
|
-
uid: "product-series.create",
|
|
11
|
-
subCategory: "product-series",
|
|
12
|
-
pluginName: "primer-product-actions",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
section: "plugins",
|
|
16
|
-
displayName: "Read",
|
|
17
|
-
uid: "product-series.read",
|
|
18
|
-
subCategory: "product-series",
|
|
19
|
-
pluginName: "primer-product-actions",
|
|
20
|
-
aliases: [
|
|
21
|
-
{
|
|
22
|
-
actionId: "plugin::content-manager.explorer.read",
|
|
23
|
-
subjects: ["api::product-series.product-series"],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
section: "plugins",
|
|
29
|
-
displayName: "Update",
|
|
30
|
-
uid: "product-series.update",
|
|
31
|
-
subCategory: "product-series",
|
|
32
|
-
pluginName: "primer-product-actions",
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
section: "plugins",
|
|
36
|
-
displayName: "Delete",
|
|
37
|
-
uid: "product-series.delete",
|
|
38
|
-
subCategory: "product-series",
|
|
39
|
-
pluginName: "primer-product-actions",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.register = void 0;
|
|
4
|
-
const pluginId_1 = require("./pluginId");
|
|
5
|
-
const register = ({ strapi }) => {
|
|
6
|
-
// Register permissions
|
|
7
|
-
strapi.admin.services.permission.actionProvider.register({
|
|
8
|
-
section: "plugins",
|
|
9
|
-
displayName: "Product Actions",
|
|
10
|
-
uid: pluginId_1.PLUGIN_ID,
|
|
11
|
-
pluginName: pluginId_1.PLUGIN_ID,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
exports.register = register;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
type: "admin",
|
|
5
|
-
routes: [
|
|
6
|
-
{
|
|
7
|
-
method: "POST",
|
|
8
|
-
path: "/create-products",
|
|
9
|
-
handler: "productSeries.createProducts",
|
|
10
|
-
config: {
|
|
11
|
-
policies: [
|
|
12
|
-
{
|
|
13
|
-
name: "admin::hasPermissions",
|
|
14
|
-
config: {
|
|
15
|
-
actions: ["plugin::primer-product-actions.product-series.create"],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
method: "PUT",
|
|
23
|
-
path: "/update-products",
|
|
24
|
-
handler: "productSeries.updateProducts",
|
|
25
|
-
config: {
|
|
26
|
-
policies: [
|
|
27
|
-
{
|
|
28
|
-
name: "admin::hasPermissions",
|
|
29
|
-
config: {
|
|
30
|
-
actions: ["plugin::primer-product-actions.product-series.update"],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.routes = void 0;
|
|
7
|
-
const admin_1 = __importDefault(require("./admin"));
|
|
8
|
-
const routes = { admin: admin_1.default };
|
|
9
|
-
exports.routes = routes;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.productSeriesService = void 0;
|
|
4
|
-
const productSeriesService = ({ strapi }) => ({
|
|
5
|
-
async createProductsFromSeries(seriesId, count = 1) {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
const series = await getSeries(strapi, seriesId);
|
|
8
|
-
const products = [];
|
|
9
|
-
const startIndex = ((_a = series.products) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
10
|
-
for (let i = 0; i < count; i++) {
|
|
11
|
-
const index = startIndex + i;
|
|
12
|
-
// Create product with series data
|
|
13
|
-
const product = await strapi.documents("api::product.product").create({
|
|
14
|
-
data: {
|
|
15
|
-
name: `${series.name} #${index + 1}`,
|
|
16
|
-
slug: `${series.slug}-${index + 1}`,
|
|
17
|
-
series: {
|
|
18
|
-
set: seriesId,
|
|
19
|
-
},
|
|
20
|
-
seriesIndex: index,
|
|
21
|
-
category: series.category
|
|
22
|
-
? {
|
|
23
|
-
set: series.category.documentId,
|
|
24
|
-
}
|
|
25
|
-
: null,
|
|
26
|
-
creator: series.creator
|
|
27
|
-
? {
|
|
28
|
-
set: (_b = series.creator) === null || _b === void 0 ? void 0 : _b.documentId,
|
|
29
|
-
}
|
|
30
|
-
: null,
|
|
31
|
-
publishedAt: undefined,
|
|
32
|
-
// Copy all required fields from series
|
|
33
|
-
description: series.description,
|
|
34
|
-
shortDescription: series.shortDescription,
|
|
35
|
-
media: series.media,
|
|
36
|
-
coverImage: series.coverImage,
|
|
37
|
-
seo: series.seo,
|
|
38
|
-
totalCost: series.totalCost,
|
|
39
|
-
wholesalePrice: series.wholesalePrice,
|
|
40
|
-
retailPrice: series.retailPrice,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
products.push(product);
|
|
44
|
-
}
|
|
45
|
-
return products;
|
|
46
|
-
},
|
|
47
|
-
async updateSeriesProducts(seriesId, fieldsToUpdate) {
|
|
48
|
-
var _a, _b, _c;
|
|
49
|
-
const series = await getSeries(strapi, seriesId);
|
|
50
|
-
const dataToUpdate = {};
|
|
51
|
-
if (fieldsToUpdate.includes("description")) {
|
|
52
|
-
dataToUpdate.description = series.description;
|
|
53
|
-
}
|
|
54
|
-
if (fieldsToUpdate.includes("shortDescription")) {
|
|
55
|
-
dataToUpdate.shortDescription = series.shortDescription;
|
|
56
|
-
}
|
|
57
|
-
if (fieldsToUpdate.includes("media")) {
|
|
58
|
-
dataToUpdate.media = series.media;
|
|
59
|
-
}
|
|
60
|
-
if (fieldsToUpdate.includes("coverImage")) {
|
|
61
|
-
dataToUpdate.coverImage = series.coverImage;
|
|
62
|
-
}
|
|
63
|
-
if (fieldsToUpdate.includes("seo")) {
|
|
64
|
-
dataToUpdate.seo = series.seo;
|
|
65
|
-
}
|
|
66
|
-
if (fieldsToUpdate.includes("totalCost")) {
|
|
67
|
-
dataToUpdate.totalCost = series.totalCost;
|
|
68
|
-
}
|
|
69
|
-
if (fieldsToUpdate.includes("wholesalePrice")) {
|
|
70
|
-
dataToUpdate.wholesalePrice = series.wholesalePrice;
|
|
71
|
-
}
|
|
72
|
-
if (fieldsToUpdate.includes("retailPrice")) {
|
|
73
|
-
dataToUpdate.retailPrice = series.retailPrice;
|
|
74
|
-
}
|
|
75
|
-
if (fieldsToUpdate.includes("category")) {
|
|
76
|
-
dataToUpdate.category = {
|
|
77
|
-
set: [(_a = series.category) === null || _a === void 0 ? void 0 : _a.documentId],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (fieldsToUpdate.includes("creator")) {
|
|
81
|
-
dataToUpdate.creator = {
|
|
82
|
-
set: [(_b = series.creator) === null || _b === void 0 ? void 0 : _b.documentId],
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const updatePromises = (_c = series.products) === null || _c === void 0 ? void 0 : _c.map((product) => strapi.documents("api::product.product").update({
|
|
86
|
-
documentId: product.documentId,
|
|
87
|
-
data: {
|
|
88
|
-
...dataToUpdate,
|
|
89
|
-
},
|
|
90
|
-
}));
|
|
91
|
-
if (updatePromises) {
|
|
92
|
-
await Promise.all(updatePromises);
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
exports.productSeriesService = productSeriesService;
|
|
98
|
-
async function getSeries(strapi, seriesId) {
|
|
99
|
-
const series = await strapi
|
|
100
|
-
.documents("api::product-series.product-series")
|
|
101
|
-
.findOne({
|
|
102
|
-
documentId: seriesId,
|
|
103
|
-
populate: [
|
|
104
|
-
"products",
|
|
105
|
-
"category",
|
|
106
|
-
"creator",
|
|
107
|
-
"media",
|
|
108
|
-
"coverImage",
|
|
109
|
-
"seo",
|
|
110
|
-
],
|
|
111
|
-
});
|
|
112
|
-
if (!series) {
|
|
113
|
-
throw new Error("Series not found");
|
|
114
|
-
}
|
|
115
|
-
return series;
|
|
116
|
-
}
|