Skip to content

Commit a2cced2

Browse files
committed
1 parent aa61e23 commit a2cced2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2190
-235
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-- UPDATE EXISTING TABLES:
2+
-- product_templates
3+
-- category column: added
4+
-- CREATE NEW TABLE:
5+
-- product_categories
6+
7+
--
8+
-- product_categories
9+
--
10+
CREATE TABLE product_categories (
11+
key character varying(45) NOT NULL,
12+
"displayName" character varying(255) NOT NULL,
13+
"icon" character varying(255) NOT NULL,
14+
"info" character varying(255) NOT NULL,
15+
"question" character varying(255) NOT NULL,
16+
"aliases" json NOT NULL,
17+
"hidden" boolean DEFAULT false,
18+
"disabled" boolean DEFAULT false,
19+
"deletedAt" timestamp with time zone,
20+
"createdAt" timestamp with time zone,
21+
"updatedAt" timestamp with time zone,
22+
"deletedBy" integer,
23+
"createdBy" integer NOT NULL,
24+
"updatedBy" integer NOT NULL
25+
);
26+
27+
ALTER TABLE ONLY product_categories
28+
ADD CONSTRAINT product_categories_pkey PRIMARY KEY (key);
29+
30+
--
31+
-- product_templates
32+
--
33+
ALTER TABLE product_templates ADD COLUMN "category" character varying(45);
34+
UPDATE product_templates set category='generic' where category is null;
35+
ALTER TABLE product_templates ALTER COLUMN "generic" SET NOT NULL;

postman.json

Lines changed: 199 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@
25302530
],
25312531
"body": {
25322532
"mode": "raw",
2533-
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"alias 1\"\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\"\r\n }\r\n }\r\n}"
2533+
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"category\":\"generic\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"alias 1\"\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\"\r\n }\r\n }\r\n}"
25342534
},
25352535
"url": {
25362536
"raw": "{{api-url}}/v4/productTemplates",
@@ -2624,7 +2624,7 @@
26242624
],
26252625
"body": {
26262626
"mode": "raw",
2627-
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"scope 1\",\r\n \"alias2\": [\"a\"]\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\",\r\n \"template2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
2627+
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"productKey\":\"new productKey\",\r\n \"category\":\"generic\",\r\n \"icon\":\"http://example.com/icon-new.ico\",\r\n \"brief\": \"new brief\",\r\n \"details\": \"new details\",\r\n \"aliases\":{\r\n \"alias1\":\"scope 1\",\r\n \"alias2\": [\"a\"]\r\n },\r\n \"template\":{\r\n \"template1\":\"template 1\",\r\n \"template2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
26282628
},
26292629
"url": {
26302630
"raw": "{{api-url}}/v4/productTemplates/1",
@@ -2838,6 +2838,202 @@
28382838
}
28392839
]
28402840
},
2841+
{
2842+
"name": "Product Category",
2843+
"description": null,
2844+
"item": [
2845+
{
2846+
"name": "Create product category",
2847+
"request": {
2848+
"method": "POST",
2849+
"header": [
2850+
{
2851+
"key": "Content-Type",
2852+
"value": "application/json"
2853+
},
2854+
{
2855+
"key": "Authorization",
2856+
"value": "Bearer {{jwt-token}}"
2857+
}
2858+
],
2859+
"body": {
2860+
"mode": "raw",
2861+
"raw": "{\r\n \"param\":{\r\n \"key\": \"generic\",\r\n \"displayName\": \"new displayName\",\r\n \"icon\": \"icon\",\r\n \"question\": \"question\",\r\n \"info\": \"info\",\r\n \"aliases\": [\"key-1\", \"key-2\"]\r\n }\r\n}"
2862+
},
2863+
"url": {
2864+
"raw": "{{api-url}}/v4/productCategories",
2865+
"host": [
2866+
"{{api-url}}"
2867+
],
2868+
"path": [
2869+
"v4",
2870+
"productCategories"
2871+
]
2872+
}
2873+
},
2874+
"response": []
2875+
},
2876+
{
2877+
"name": "List product categories",
2878+
"request": {
2879+
"method": "GET",
2880+
"header": [
2881+
{
2882+
"key": "Content-Type",
2883+
"value": "application/json"
2884+
},
2885+
{
2886+
"key": "Authorization",
2887+
"value": "Bearer {{jwt-token}}"
2888+
}
2889+
],
2890+
"body": {
2891+
"mode": "raw",
2892+
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
2893+
},
2894+
"url": {
2895+
"raw": "{{api-url}}/v4/productCategories",
2896+
"host": [
2897+
"{{api-url}}"
2898+
],
2899+
"path": [
2900+
"v4",
2901+
"productCategories"
2902+
]
2903+
}
2904+
},
2905+
"response": []
2906+
},
2907+
{
2908+
"name": "Get product category",
2909+
"request": {
2910+
"method": "GET",
2911+
"header": [
2912+
{
2913+
"key": "Content-Type",
2914+
"value": "application/json"
2915+
},
2916+
{
2917+
"key": "Authorization",
2918+
"value": "Bearer {{jwt-token}}"
2919+
}
2920+
],
2921+
"body": {
2922+
"mode": "raw",
2923+
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\"\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\"\r\n }\r\n }\r\n}"
2924+
},
2925+
"url": {
2926+
"raw": "{{api-url}}/v4/productCategories/generic",
2927+
"host": [
2928+
"{{api-url}}"
2929+
],
2930+
"path": [
2931+
"v4",
2932+
"productCategories",
2933+
"generic"
2934+
]
2935+
}
2936+
},
2937+
"response": []
2938+
},
2939+
{
2940+
"name": "Update product category",
2941+
"request": {
2942+
"method": "PATCH",
2943+
"header": [
2944+
{
2945+
"key": "Content-Type",
2946+
"value": "application/json"
2947+
},
2948+
{
2949+
"key": "Authorization",
2950+
"value": "Bearer {{jwt-token}}"
2951+
}
2952+
],
2953+
"body": {
2954+
"mode": "raw",
2955+
"raw": "{\r\n \"param\":{\r\n \"displayName\": \"Chatbot-updated\"\r\n }\r\n}"
2956+
},
2957+
"url": {
2958+
"raw": "{{api-url}}/v4/productCategories/generic",
2959+
"host": [
2960+
"{{api-url}}"
2961+
],
2962+
"path": [
2963+
"v4",
2964+
"productCategories",
2965+
"generic"
2966+
]
2967+
}
2968+
},
2969+
"response": []
2970+
},
2971+
{
2972+
"name": "Delete product category",
2973+
"request": {
2974+
"method": "DELETE",
2975+
"header": [
2976+
{
2977+
"key": "Content-Type",
2978+
"value": "application/json"
2979+
},
2980+
{
2981+
"key": "Authorization",
2982+
"value": "Bearer {{jwt-token}}"
2983+
}
2984+
],
2985+
"body": {
2986+
"mode": "raw",
2987+
"raw": "{\r\n \"param\":{\r\n \"name\":\"new name\",\r\n \"key\":\"new key\",\r\n \"category\":\"new category\",\r\n \"scope\":{\r\n \"scope1\":\"scope 1\",\r\n \"scope2\": [\"a\"]\r\n },\r\n \"phases\":{\r\n \"phase1\":\"phase 1\",\r\n \"phase2\": {\r\n \t\"another\": \"another\"\r\n }\r\n }\r\n }\r\n}"
2988+
},
2989+
"url": {
2990+
"raw": "{{api-url}}/v4/productCategories/generic",
2991+
"host": [
2992+
"{{api-url}}"
2993+
],
2994+
"path": [
2995+
"v4",
2996+
"productCategories",
2997+
"generic"
2998+
]
2999+
}
3000+
},
3001+
"response": []
3002+
}
3003+
],
3004+
"auth": {
3005+
"type": "bearer",
3006+
"bearer": [
3007+
{
3008+
"key": "token",
3009+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJhZG1pbmlzdHJhdG9yIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJwc2hhaDEiLCJleHAiOjI0NjI0OTQ2MTgsInVzZXJJZCI6IjQwMTM1OTc4IiwiaWF0IjoxNDYyNDk0MDE4LCJlbWFpbCI6InBzaGFoMUB0ZXN0LmNvbSIsImp0aSI6ImY0ZTFhNTE0LTg5ODAtNDY0MC04ZWM1LWUzNmUzMWE3ZTg0OSJ9.XuNN7tpMOXvBG1QwWRQROj7NfuUbqhkjwn39Vy4tR5I",
3010+
"type": "string"
3011+
}
3012+
]
3013+
},
3014+
"event": [
3015+
{
3016+
"listen": "prerequest",
3017+
"script": {
3018+
"id": "f0092ef5-e624-4c25-87b2-b6a9e4c81ec8",
3019+
"type": "text/javascript",
3020+
"exec": [
3021+
""
3022+
]
3023+
}
3024+
},
3025+
{
3026+
"listen": "test",
3027+
"script": {
3028+
"id": "9183c429-a5e0-4bf9-96a2-89f4d66e9b0d",
3029+
"type": "text/javascript",
3030+
"exec": [
3031+
""
3032+
]
3033+
}
3034+
}
3035+
]
3036+
},
28413037
{
28423038
"name": "issue86 (create project with templateId)",
28433039
"description": null,
@@ -4179,4 +4375,4 @@
41794375
]
41804376
}
41814377
]
4182-
}
4378+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import _ from 'lodash';
2+
3+
/**
4+
* Constructs a middleware the validates the existence of a record given a path to find in the req. For example, in
5+
* order to check for a ProductCategory being received in "req.body.param.category" you would construct this middleware
6+
* by calling this function with (models.ProductCategory, 'key', 'body.param.category', 'Category').
7+
* Note that this also works for updates where the value might not be present in the request, in which the case
8+
* the built middleware will continue without errors.
9+
*
10+
* @param {Object} model the mode.
11+
* @param {string} modelKey the model key
12+
* @param {string} path the path to seek the value in the request
13+
* @param {string} errorEntityName the error entity name used to build an error
14+
* @returns {Function} the middleware
15+
*/
16+
export default function (model, modelKey, path, errorEntityName) {
17+
return (req, res, next) => {
18+
const value = _.get(req, path);
19+
if (value) {
20+
model.findOne({ where: { [modelKey]: value } })
21+
.then((record) => {
22+
if (record) {
23+
next();
24+
} else {
25+
const err = new Error(`${errorEntityName} not found for key "${value}"`);
26+
err.status = 422;
27+
next(err);
28+
}
29+
});
30+
} else {
31+
next();
32+
}
33+
};
34+
}

0 commit comments

Comments
 (0)