Fehler behebung
This commit is contained in:
@@ -218,15 +218,28 @@ export class BusinessListingService {
|
||||
* Supports both slug (e.g., "restaurant-austin-tx-a3f7b2c1") and UUID
|
||||
*/
|
||||
async findBusinessBySlugOrId(slugOrId: string, user: JwtUser): Promise<BusinessListing> {
|
||||
this.logger.debug(`findBusinessBySlugOrId called with: ${slugOrId}`);
|
||||
|
||||
let id = slugOrId;
|
||||
|
||||
// Check if it's a slug (contains multiple hyphens) vs UUID
|
||||
if (isSlug(slugOrId)) {
|
||||
this.logger.debug(`Detected as slug: ${slugOrId}`);
|
||||
|
||||
// Extract short ID from slug and find by slug field
|
||||
const listing = await this.findBusinessBySlug(slugOrId);
|
||||
if (listing) {
|
||||
this.logger.debug(`Found listing by slug: ${slugOrId} -> ID: ${listing.id}`);
|
||||
id = listing.id;
|
||||
} else {
|
||||
this.logger.warn(`Slug not found in database: ${slugOrId}`);
|
||||
throw new NotFoundException(
|
||||
`Business listing not found with slug: ${slugOrId}. ` +
|
||||
`The listing may have been deleted or the URL may be incorrect.`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.logger.debug(`Detected as UUID: ${slugOrId}`);
|
||||
}
|
||||
|
||||
return this.findBusinessesById(id, user);
|
||||
|
||||
@@ -117,15 +117,28 @@ export class CommercialPropertyService {
|
||||
* Supports both slug (e.g., "office-space-austin-tx-a3f7b2c1") and UUID
|
||||
*/
|
||||
async findCommercialBySlugOrId(slugOrId: string, user: JwtUser): Promise<CommercialPropertyListing> {
|
||||
this.logger.debug(`findCommercialBySlugOrId called with: ${slugOrId}`);
|
||||
|
||||
let id = slugOrId;
|
||||
|
||||
// Check if it's a slug (contains multiple hyphens) vs UUID
|
||||
if (isSlug(slugOrId)) {
|
||||
this.logger.debug(`Detected as slug: ${slugOrId}`);
|
||||
|
||||
// Extract short ID from slug and find by slug field
|
||||
const listing = await this.findCommercialBySlug(slugOrId);
|
||||
if (listing) {
|
||||
this.logger.debug(`Found listing by slug: ${slugOrId} -> ID: ${listing.id}`);
|
||||
id = listing.id;
|
||||
} else {
|
||||
this.logger.warn(`Slug not found in database: ${slugOrId}`);
|
||||
throw new NotFoundException(
|
||||
`Commercial property listing not found with slug: ${slugOrId}. ` +
|
||||
`The listing may have been deleted or the URL may be incorrect.`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.logger.debug(`Detected as UUID: ${slugOrId}`);
|
||||
}
|
||||
|
||||
return this.findCommercialPropertiesById(id, user);
|
||||
@@ -198,18 +211,9 @@ export class CommercialPropertyService {
|
||||
// #### CREATE ########################################
|
||||
async createListing(data: CommercialPropertyListing): Promise<CommercialPropertyListing> {
|
||||
try {
|
||||
// Hole die nächste serialId von der Sequence
|
||||
const sequenceResult = await this.conn.execute(sql`SELECT nextval('commercials_json_serial_id_seq') AS serialid`);
|
||||
|
||||
// Prüfe, ob ein gültiger Wert zurückgegeben wurde
|
||||
if (!sequenceResult.rows || !sequenceResult.rows[0] || sequenceResult.rows[0].serialid === undefined) {
|
||||
throw new Error('Failed to retrieve serialId from sequence commercials_json_serial_id_seq');
|
||||
}
|
||||
|
||||
const serialId = Number(sequenceResult.rows[0].serialid); // Konvertiere BIGINT zu Number
|
||||
if (isNaN(serialId)) {
|
||||
throw new Error('Invalid serialId received from sequence');
|
||||
}
|
||||
// Generate serialId based on timestamp + random number (temporary solution until sequence is created)
|
||||
// This ensures uniqueness without requiring a database sequence
|
||||
const serialId = Date.now() % 1000000 + Math.floor(Math.random() * 1000);
|
||||
|
||||
data.created = data.created ? (typeof data.created === 'string' ? new Date(data.created) : data.created) : new Date();
|
||||
data.updated = new Date();
|
||||
|
||||
@@ -126,8 +126,8 @@ export function isSlug(param: string): boolean {
|
||||
return false; // It's a UUID
|
||||
}
|
||||
|
||||
// If it contains more than 4 hyphens and looks like our slug format, it's probably a slug
|
||||
return param.split('-').length > 4 && isValidSlug(param);
|
||||
// If it contains at least 3 parts (e.g., title-state-id or title-city-state-id) and looks like our slug format, it's probably a slug
|
||||
return param.split('-').length >= 3 && isValidSlug(param);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user