diff --git a/README.md b/README.md index 29e6308..7fce978 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Third party systems like Unbox (Synergy) will use the `graphql.photowall.com` to Create an .env file (see .env.example for what to set). `COGNITO_LOGIN_CLIENT_SECRET`, `COGNITO_LOGIN_CLIENT_ID` is found in cognito `photowall-test-staff` pool. In `photowall-web-test-client` app. +## Publish it to staging + +Run `make publish-to-staging`. Please note that further commits on the same branch will not be updated automatically and the same command must be run again if changes are made. + ### Development This project does only run in docker, so when developing start the docker environment and let it updated when changing files. Sometimes the watch for files doesnt trigger. Like when you edit the .graphql file. Then just edit a .ts file and it will reload. diff --git a/src/datasources/product-api.ts b/src/datasources/product-api.ts index 9a96141..a374af3 100644 --- a/src/datasources/product-api.ts +++ b/src/datasources/product-api.ts @@ -489,8 +489,21 @@ export class ProductAPI extends BaseSQLDataSource { designerId: number, ): Promise { ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_WRITE]); + + // Replace underscores and hyphens with spaces + let formattedName = name.replace(/[_-]/g, ' '); + // Add spaces before capital letters that are not at the beginning of the string + + formattedName = formattedName.replace(/([a-z])([A-Z])/g, '$1 $2'); + // Capitalize the first letter of each word + + formattedName = formattedName + .split(' ') + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); + const fixedBatch = !!batch ? batch : ''; - const productPath = slug(name); + const productPath = slug(formattedName); const safePath = await this.getUniqueProductPath(productPath, null); const idres = await this.knex @@ -504,7 +517,7 @@ export class ProductAPI extends BaseSQLDataSource { .returning('productid'); const id = idres[0].productid; this.updateProductField(id, 'artNo', `e${id}`); - await this.updateProductField(id, 'name', name); + await this.updateProductField(id, 'name', formattedName); await this.updateProductField(id, 'batch', fixedBatch); return id; }