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
+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;
}