|
|
@@ -0,0 +1,278 @@
|
|
|
+const { Keystone } = require('@keystonejs/keystone');
|
|
|
+const { PasswordAuthStrategy } = require('@keystonejs/auth-password');
|
|
|
+const { Text, Checkbox, Password } = require('@keystonejs/fields');
|
|
|
+const { GraphQLApp } = require('@keystonejs/app-graphql');
|
|
|
+const { AdminUIApp } = require('@keystonejs/app-admin-ui');
|
|
|
+const { StaticApp } = require('@keystonejs/app-static');
|
|
|
+//const { expressSession } = require('express-session');
|
|
|
+//const { FileSessionStore } = require('session-file-store')(expressSession);
|
|
|
+
|
|
|
+const fs = require('fs');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// Lists
|
|
|
+const CashregistersSchema = require('./schema/cashregisters.js');
|
|
|
+const CashregisterdocsSchema = require('./schema/cashregisterdocs.js');
|
|
|
+const CompaniesSchema = require('./schema/companies.js');
|
|
|
+const CurrencySchema = require('./schema/currency.js');
|
|
|
+const DeliveryitemsSchema = require('./schema/deliveryitems.js');
|
|
|
+const DeliverymaterialpricesSchema = require('./schema/deliverymaterialprices.js');
|
|
|
+const DocflowSchema = require('./schema/docflow.js');
|
|
|
+const DocnumbersSchema = require('./schema/docnumbers.js')
|
|
|
+const DocpaymentSchema = require('./schema/docpayment.js');
|
|
|
+const DocumentsSchema = require('./schema/documents.js');
|
|
|
+const Eshop_removedSchema = require('./schema/eshop_removed.js');
|
|
|
+const Feature_groups_featuresSchema = require('./schema/feature_groups_features.js');
|
|
|
+const Feature_groupsSchema = require('./schema/feature_groups.js');
|
|
|
+const FeaturesSchema = require('./schema/features.js');
|
|
|
+const FeaturesvalSchema = require('./schema/featuresval.js');
|
|
|
+const FifopartSchema = require('./schema/fifopart.js');
|
|
|
+const FifoposSchema = require('./schema/fifopos.js');
|
|
|
+const ItemsSchema = require('./schema/items.js');
|
|
|
+const KindsSchema = require('./schema/kinds.js')
|
|
|
+const LocationsSchema = require('./schema/locations.js');
|
|
|
+const LogsSchema = require('./schema/logs.js');
|
|
|
+const MaterialsSchema = require('./schema/materials.js');
|
|
|
+const Monitor_logsSchema = require('./schema/monitor_logs.js');
|
|
|
+const OperatorgroupprivilegesSchema = require('./schema/operatorgroupprivileges.js');
|
|
|
+const OperatorgroupsSchema = require('./schema/operatorgroups.js');
|
|
|
+const Operators_cashregistersSchema = require('./schema/operators_cashregisters.js');
|
|
|
+const Operators_settingsSchema = require('./schema/operators_settings.js');
|
|
|
+const Operators_shopsSchema = require('./schema/operators_shops.js');
|
|
|
+const OperatorsSchema = require('./schema/operators.js');
|
|
|
+const PicturesSchema = require('./schema/pictures.js');
|
|
|
+const PositionsSchema = require('./schema/positions.js');
|
|
|
+const PrinttemplatesSchema = require('./schema/printtemplates.js');
|
|
|
+const Product_minmax_featuresSchema = require('./schema/product_minmax_features.js');
|
|
|
+const ProductfeaturesSchema = require('./schema/productfeatures.js');
|
|
|
+const Products_minmaxSchema = require('./schema/products_minmax.js');
|
|
|
+const ProductsgroupSchema = require('./schema/productsgroup.js');
|
|
|
+const ProductsSchema = require('./schema/products.js');
|
|
|
+const SettlementsSchema = require('./schema/settlements.js');
|
|
|
+const ShopsSchema = require('./schema/shops.js');
|
|
|
+const Stocktaking_itemsSchema = require('./schema/stocktaking_items.js');
|
|
|
+const StocktakingSchema = require('./schema/stocktaking.js');
|
|
|
+const SupaddressSchema = require('./schema/supaddress.js');
|
|
|
+const SuppliersSchema = require('./schema/suppliers.js');
|
|
|
+const SysparamsSchema = require('./schema/sysparams.js');
|
|
|
+const SysprivilegesSchema = require('./schema/sysprivileges.js');
|
|
|
+const TagtemplateobjectsSchema = require('./schema/tagtemplateobjects.js');
|
|
|
+const TagtemplatesSchema = require('./schema/tagtemplates.js');
|
|
|
+const TransferdocreceivedSchema = require('./schema/transferdocreceived.js');
|
|
|
+const UninumbersSchema = require('./schema/uninumbers.js');
|
|
|
+const UomSchema = require('./schema/uom.js');
|
|
|
+const UpgradelogSchema = require('./schema/upgradelog.js');
|
|
|
+const VatSchema = require('./schema/vat.js');
|
|
|
+//const Logger = require('@keystonejs/logger').logger('test');
|
|
|
+
|
|
|
+
|
|
|
+const initialiseData = require('./initial-data');
|
|
|
+
|
|
|
+const { KnexAdapter: Adapter } = require('@keystonejs/adapter-knex');
|
|
|
+
|
|
|
+const PROJECT_NAME = 'SchuStock';
|
|
|
+const adapterConfig = { knexOptions: {
|
|
|
+ connection: 'postgresql://kdev_postgres:utnQ67pt74bVw6aB@postgres:5432/kdev_postgres',
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+/*
|
|
|
+const { v4: uuid } = require('uuid');
|
|
|
+const { CloudinaryAdapter } = require('@keystonejs/file-adapters');
|
|
|
+const { Wysiwyg } = require('@keystonejs/fields-wysiwyg-tinymce')
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+const keystone = new Keystone({
|
|
|
+ adapter: new Adapter(adapterConfig),
|
|
|
+ //onConnect: process.env.CREATE_TABLES !== 'true' && initialiseData,
|
|
|
+ onConnect: initialiseData,
|
|
|
+ //secureCookies: false,
|
|
|
+ /*
|
|
|
+ cookie: {
|
|
|
+ secure: process.env.NODE_ENV === 'production', // Default to true in production
|
|
|
+ //secure: true, // Default to true in production
|
|
|
+ maxAge: 1000 * 60 * 60 * 24 * 30, // 30 days
|
|
|
+ sameSite: false,
|
|
|
+ },
|
|
|
+ */
|
|
|
+ cookieSecret: 'dupa23',
|
|
|
+ name: 'SchuStock',
|
|
|
+ brand: 'Jubiler Schubert',
|
|
|
+ //sessionStore: new FileSessionStore({ }),
|
|
|
+});
|
|
|
+
|
|
|
+//keystone.set('signin logo', ['https://jubilerschubert.pl/wp-content/uploads/schubert_logo.svg', 180, 42]);
|
|
|
+
|
|
|
+// Access control functions
|
|
|
+const userIsAdmin = ({ authentication: { item: user } }) => Boolean(user && user.isAdmin);
|
|
|
+const userOwnsItem = ({ authentication: { item: user } }) => {
|
|
|
+ if (!user) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Instead of a boolean, you can return a GraphQL query:
|
|
|
+ // https://www.keystonejs.com/api/access-control#graphqlwhere
|
|
|
+ return { id: user.id };
|
|
|
+};
|
|
|
+
|
|
|
+const userIsAdminOrOwner = auth => {
|
|
|
+ const isAdmin = access.userIsAdmin(auth);
|
|
|
+ const isOwner = access.userOwnsItem(auth);
|
|
|
+ return isAdmin ? isAdmin : isOwner;
|
|
|
+};
|
|
|
+
|
|
|
+const access = { userIsAdmin, userOwnsItem, userIsAdminOrOwner };
|
|
|
+
|
|
|
+keystone.createList('User', {
|
|
|
+ fields: {
|
|
|
+ name: { type: Text },
|
|
|
+ email: {
|
|
|
+ type: Text,
|
|
|
+ isUnique: true,
|
|
|
+ },
|
|
|
+ isAdmin: {
|
|
|
+ type: Checkbox,
|
|
|
+ // Field-level access controls
|
|
|
+ // Here, we set more restrictive field access so a non-admin cannot make themselves admin.
|
|
|
+ access: {
|
|
|
+ update: access.userIsAdmin,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ password: {
|
|
|
+ type: Password,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ // List-level access controls
|
|
|
+ access: {
|
|
|
+ read: access.userIsAdminOrOwner,
|
|
|
+ update: access.userIsAdminOrOwner,
|
|
|
+ create: access.userIsAdmin,
|
|
|
+ delete: access.userIsAdmin,
|
|
|
+ auth: true,
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+const authStrategy = keystone.createAuthStrategy({
|
|
|
+ type: PasswordAuthStrategy,
|
|
|
+ list: 'User',
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
+keystone.createList('cashregisters', CashregistersSchema);
|
|
|
+keystone.createList('cashregisterdocs', CashregisterdocsSchema);
|
|
|
+keystone.createList('companies', CompaniesSchema);
|
|
|
+keystone.createList('currency', CurrencySchema);
|
|
|
+keystone.createList('deliveryitems', DeliveryitemsSchema);
|
|
|
+keystone.createList('deliverymaterialprices', DeliverymaterialpricesSchema);
|
|
|
+keystone.createList('docflow', DocflowSchema);
|
|
|
+keystone.createList('docnumbers', DocnumbersSchema);
|
|
|
+keystone.createList('docpayment', DocpaymentSchema);
|
|
|
+keystone.createList('documents', DocumentsSchema);
|
|
|
+keystone.createList('eshop_removed', Eshop_removedSchema);
|
|
|
+keystone.createList('feature_groups_features', Feature_groups_featuresSchema);
|
|
|
+keystone.createList('feature_groups', Feature_groupsSchema);
|
|
|
+keystone.createList('features', FeaturesSchema);
|
|
|
+keystone.createList('featuresval', FeaturesvalSchema);
|
|
|
+keystone.createList('fifopart', FifopartSchema);
|
|
|
+keystone.createList('fifopos', FifoposSchema);
|
|
|
+keystone.createList('items', ItemsSchema); // todo: spr
|
|
|
+keystone.createList('kinds', KindsSchema);
|
|
|
+keystone.createList('locations', LocationsSchema);
|
|
|
+keystone.createList('logs', LogsSchema);
|
|
|
+keystone.createList('materials', MaterialsSchema);
|
|
|
+keystone.createList('monitor_logs', Monitor_logsSchema);
|
|
|
+keystone.createList('operatorgroupprivileges', OperatorgroupprivilegesSchema);
|
|
|
+keystone.createList('operatorgroups', OperatorgroupsSchema);
|
|
|
+keystone.createList('operators_cashregisters', Operators_cashregistersSchema);
|
|
|
+keystone.createList('operators_settings', Operators_settingsSchema);
|
|
|
+keystone.createList('operators_shops', Operators_shopsSchema);
|
|
|
+keystone.createList('operators', OperatorsSchema);
|
|
|
+keystone.createList('pictures', PicturesSchema);
|
|
|
+keystone.createList('positions', PositionsSchema);
|
|
|
+keystone.createList('printtemplates', PrinttemplatesSchema);
|
|
|
+keystone.createList('product_minmax_features', Product_minmax_featuresSchema);
|
|
|
+keystone.createList('productfeatures', ProductfeaturesSchema);
|
|
|
+keystone.createList('products_minmax', Products_minmaxSchema);
|
|
|
+keystone.createList('products', ProductsSchema);
|
|
|
+keystone.createList('productsgroup', ProductsgroupSchema);
|
|
|
+keystone.createList('settlements', SettlementsSchema);
|
|
|
+keystone.createList('shops', ShopsSchema);
|
|
|
+keystone.createList('stocktaking_items', Stocktaking_itemsSchema);
|
|
|
+keystone.createList('stocktaking', StocktakingSchema);
|
|
|
+keystone.createList('supaddress', SupaddressSchema);
|
|
|
+keystone.createList('suppliers', SuppliersSchema);
|
|
|
+keystone.createList('sysparams', SysparamsSchema);
|
|
|
+keystone.createList('sysprivileges', SysprivilegesSchema);
|
|
|
+keystone.createList('tagtemplateobjects', TagtemplateobjectsSchema);
|
|
|
+keystone.createList('tagtemplates', TagtemplatesSchema);
|
|
|
+keystone.createList('transferdocreceived', TransferdocreceivedSchema);
|
|
|
+keystone.createList('uninumbers', UninumbersSchema);
|
|
|
+keystone.createList('uom', UomSchema);
|
|
|
+keystone.createList('upgradelog', UpgradelogSchema);
|
|
|
+keystone.createList('vat', VatSchema);
|
|
|
+
|
|
|
+
|
|
|
+//console.log(keystone._providers);
|
|
|
+/*
|
|
|
+const {
|
|
|
+ resolveAllKeys,
|
|
|
+ arrayToObject,
|
|
|
+ mapKeys,
|
|
|
+ objMerge,
|
|
|
+ flatten,
|
|
|
+ unique,
|
|
|
+ filterValues,
|
|
|
+ compose,
|
|
|
+} = require('@keystonejs/utils');
|
|
|
+
|
|
|
+//console.log(keystone._providers);
|
|
|
+//console.log(keystone._providers.map(p => console.log(p.lists)));
|
|
|
+
|
|
|
+
|
|
|
+//const queries = unique(flatten(this._providers.map(p => p.lists.map(x => console.log(x.getGqlQueries())))));
|
|
|
+//const queries = unique(flatten(this._providers.map(p => p.lists.map(x => console.log())));
|
|
|
+
|
|
|
+//console.log(keystone._providers.map(p => console.log(p.lists)));//.map(x => x.getGqlQueries())));
|
|
|
+//console.log(keystone._providers[0].getQueries('public'));
|
|
|
+//const mutations = unique(flatten(keystone._providers.map(p => p.getMutations('public'))));
|
|
|
+//console.log(flatten(keystone._providers.map(p => p.getTypes('public'))));
|
|
|
+
|
|
|
+//queries.length > 0 && `type Query { ${queries.join('\n')} }`,
|
|
|
+//mutations.length > 0 && `type Mutation { ${mutations.join('\n')} }`,
|
|
|
+
|
|
|
+//console.log(keystone._providers);
|
|
|
+
|
|
|
+//console.log(keystone.getTypeDefs('public'));
|
|
|
+
|
|
|
+/*
|
|
|
+if (typeof process.env.DUMP_SCHEMA === 'string') {
|
|
|
+ keystone.dumpSchema(process.env.DUMP_SCHEMA, 'public');
|
|
|
+ console.log(`Schema dumped to: ${path.resolve(process.env.DUMP_SCHEMA)}`);
|
|
|
+ process.exit(0);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function function2() {
|
|
|
+ console.log(keystone);
|
|
|
+}
|
|
|
+setTimeout(function2, 100);
|
|
|
+*/
|
|
|
+
|
|
|
+module.exports = {
|
|
|
+ keystone,
|
|
|
+ apps: [
|
|
|
+ new GraphQLApp(),
|
|
|
+ new StaticApp({ path: '/', src: 'public' }),
|
|
|
+ new AdminUIApp({
|
|
|
+ name: 'SchuStocc',
|
|
|
+ enableDefaultRoute: true,
|
|
|
+ authStrategy,
|
|
|
+ }),
|
|
|
+ ],
|
|
|
+ /*configureExpress: app => {
|
|
|
+ app.set('trust proxy', true);
|
|
|
+ }*/
|
|
|
+};
|