name & url format fix (#144)

* name & url format fix

* Added pushing staging notes to readme

* push-to-staging

---------

Co-authored-by: Sreeraj Rajendran Nair <sreeraj.rajendran@photowall.com>
This commit is contained in:
Sreeraj Rajendran Nair
2023-02-27 10:52:07 +01:00
committed by GitHub
co-authored by Sreeraj Rajendran Nair
parent 74f89e9934
commit 5bc4e92c92
2 changed files with 19 additions and 2 deletions
+4
View File
@@ -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.
+15 -2
View File
@@ -489,8 +489,21 @@ export class ProductAPI extends BaseSQLDataSource {
designerId: number,
): Promise<number> {
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;
}