slugify bug fixed
This commit is contained in:
@@ -38,23 +38,12 @@ export class RestaurantsService {
|
||||
async setupRestuarant(dto: CreateRestaurantDto): Promise<Restaurant> {
|
||||
return await this.em.transactional(async (em) => {
|
||||
// Generate or validate slug
|
||||
let slug = dto.slug;
|
||||
if (!slug) {
|
||||
// Generate slug from restaurant name
|
||||
slug = slugify(dto.name, {
|
||||
lower: true,
|
||||
strict: true,
|
||||
locale: 'fa'
|
||||
});
|
||||
}
|
||||
const slug = slugify(dto.slug ?? dto.name, {
|
||||
lower: true,
|
||||
strict: true,
|
||||
locale: 'fa'
|
||||
});
|
||||
|
||||
// Ensure slug uniqueness
|
||||
let finalSlug = slug;
|
||||
let counter = 1;
|
||||
while (await em.findOne(Restaurant, { slug: finalSlug })) {
|
||||
finalSlug = `${slug}-${counter}`;
|
||||
counter++;
|
||||
}
|
||||
|
||||
const validateSubscriptionId = await em.findOne(Restaurant, { subscriptionId: dto.subscriptionId })
|
||||
if (validateSubscriptionId) {
|
||||
@@ -64,12 +53,12 @@ export class RestaurantsService {
|
||||
// Create restaurant
|
||||
const restaurant = em.create(Restaurant, {
|
||||
name: dto.name,
|
||||
slug: finalSlug,
|
||||
slug,
|
||||
establishedYear: dto.establishedYear,
|
||||
phone: dto.phone,
|
||||
isActive: true,
|
||||
plan: dto.plan,
|
||||
domain: `https://dmenu-plus-front.dev.danakcorp.com/${finalSlug}`,
|
||||
domain: `https://dmenu-plus-front.dev.danakcorp.com/${slug}`,
|
||||
subscriptionId: dto.subscriptionId,
|
||||
subscriptionEndDate: dto.subscriptionEndDate,
|
||||
subscriptionStartDate: dto.subscriptionStartDate,
|
||||
@@ -169,30 +158,14 @@ export class RestaurantsService {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
// Handle slug generation/update
|
||||
if (dto.slug !== undefined || dto.name !== undefined) {
|
||||
let slug = dto.slug;
|
||||
if(dto.slug){
|
||||
dto.slug = slugify(dto.slug, {
|
||||
lower: true,
|
||||
strict: true,
|
||||
locale: 'fa'
|
||||
});
|
||||
}
|
||||
|
||||
if (!slug && dto.name) {
|
||||
// Generate slug from restaurant name if slug not provided but name is
|
||||
slug = slugify(dto.name, {
|
||||
lower: true,
|
||||
strict: true,
|
||||
locale: 'fa'
|
||||
});
|
||||
}
|
||||
|
||||
// Ensure slug uniqueness if slug is being updated
|
||||
if (slug) {
|
||||
let finalSlug = slug;
|
||||
let counter = 1;
|
||||
while (await this.em.findOne(Restaurant, { slug: finalSlug, id: { $ne: id } })) {
|
||||
finalSlug = `${slug}-${counter}`;
|
||||
counter++;
|
||||
}
|
||||
dto.slug = finalSlug;
|
||||
}
|
||||
}
|
||||
|
||||
this.restRepository.assign(restaurant, dto);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user