I downloaded and installed "Totaljs Eshop" and noticed that the product creation does not allow me to define product options (ie, color of product).
I went into the NoSQL embedded database, and looked at the models/product.js file.
I see:
NEWSCHEMA('Product').make(function(schema) {
schema.define('id', 'String(20)');
schema.define('pictures', '[String]');
schema.define('reference', 'String(20)');
schema.define('category', 'String(300)', true);
schema.define('manufacturer', 'String(50)');
schema.define('name', 'String(50)', true);
schema.define('price', Number, true);
schema.define('priceold', Number);
schema.define('description', String, true);
schema.define('availability', 'String(40)');
schema.define('template', 'String(30)');
schema.define('body', String);
schema.define('pictures2', '[String]');
schema.define('istop', Boolean);
schema.define('isnew', Boolean);
schema.define('linker', 'String(50)');
I tried adding the following code:
schema.define('nicstrength', 'Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)')
I am getting errors saying:
======= 2017-01-02 02:50:21: Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default". Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default".
at SchemaBuilderEntity.default (/Users/student/Dev/eshop/node_modules/total.js/builders.js:1138:23)
at SchemaBuilderEntity.get.SchemaBuilderEntity.read (/Users/student/Dev/eshop/node_modules/total.js/builders.js:832:27)
at Controller.$get.Controller.$read (/Users/student/Dev/eshop/node_modules/total.js/index.js:10247:19)
at Controller.json_products_read (/Users/student/Dev/eshop/controllers/api.js:73:7)
at Subscribe.doExecute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9754:23)
at Subscribe.execute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9680:8)
at Subscribe.doAuthorization (/Users/student/Dev/eshop/node_modules/total.js/index.js:9796:8)
at /Users/student/Dev/eshop/node_modules/total.js/index.js:9707:9
at F.onAuthorize (/Users/student/Dev/eshop/models/users.js:324:3)
at Subscribe.prepare (/Users/student/Dev/eshop/node_modules/total.js/index.js:9694:3)
I am pretty new to backend, so I apologize if this is a trivial question.
Here is a link to my repository where I forked the initial open source project
you have to define a correct schema type and
Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)
is not valid Total.js schema type. Here are all supported types: https://docs.totaljs.com/latest/en.html#api~SchemaBuilderQuick fix:
So the field needs to contain only the one value from defined values.