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:
co-authored by
Sreeraj Rajendran Nair
parent
74f89e9934
commit
5bc4e92c92
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user