Improve professional service listings and handle database errors gracefully

Updates professional service schema, adds error handling for service queries.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: c5f0c281-8dd8-4846-b452-4a07bcd21062
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9777c70b-fc38-4831-8d6b-78dfffe041b0/77e3a9be-2270-44e5-9c08-420849b57e18.jpg
This commit is contained in:
ghaddaditw
2025-06-08 08:21:34 +00:00
parent a16fca481c
commit d0ccbf0a50
2 changed files with 25 additions and 22 deletions
+17 -12
View File
@@ -479,20 +479,25 @@ export class DatabaseStorage implements IStorage {
} }
async getProfessionalServices(type?: string, location?: string): Promise<ProfessionalService[]> { async getProfessionalServices(type?: string, location?: string): Promise<ProfessionalService[]> {
let query = db try {
.select() let query = db
.from(professionalServices) .select()
.where(eq(professionalServices.isActive, true)); .from(professionalServices)
.where(eq(professionalServices.isActive, true));
if (type) { if (type) {
query = query.where(eq(professionalServices.serviceType, type)); query = query.where(eq(professionalServices.type, type));
} }
if (location) { if (location) {
query = query.where(eq(professionalServices.location, location)); query = query.where(eq(professionalServices.location, location));
} }
return await query.orderBy(desc(professionalServices.rating)); return await query.orderBy(desc(professionalServices.rating));
} catch (error) {
console.error('Database error in getProfessionalServices:', error);
return [];
}
} }
async updateProfessionalService(id: number, userId: number, updates: Partial<ProfessionalService>): Promise<ProfessionalService | undefined> { async updateProfessionalService(id: number, userId: number, updates: Partial<ProfessionalService>): Promise<ProfessionalService | undefined> {
+8 -10
View File
@@ -359,20 +359,18 @@ export const messageStatuses = pgTable("message_statuses", {
// Professional services table // Professional services table
export const professionalServices = pgTable("professional_services", { export const professionalServices = pgTable("professional_services", {
id: serial("id").primaryKey(), id: serial("id").primaryKey(),
providerId: integer("provider_id").notNull().references(() => users.id, { onDelete: "cascade" }), userId: integer("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
name: text("name").notNull(), providerId: integer("provider_id").references(() => users.id, { onDelete: "cascade" }),
name: text("name"),
title: text("title"),
description: text("description"), description: text("description"),
type: professionalTypeEnum("type").notNull(), serviceType: professionalTypeEnum("service_type").notNull(),
specializations: text("specializations").array(), specializations: text("specializations").array(),
hourlyRate: numeric("hourly_rate", { precision: 10, scale: 2 }), priceRange: text("price_range"),
currency: varchar("currency", { length: 3 }).default("OMR"), availabilitySchedule: text("availability_schedule"),
availability: json("availability").$type<{
[key: string]: { start: string; end: string; available: boolean }[]
}>(),
location: text("location"), location: text("location"),
isOnline: boolean("is_online").default(false),
rating: numeric("rating", { precision: 3, scale: 2 }), rating: numeric("rating", { precision: 3, scale: 2 }),
reviewCount: integer("review_count").default(0), totalReviews: integer("total_reviews").default(0),
isVerified: boolean("is_verified").default(false), isVerified: boolean("is_verified").default(false),
isActive: boolean("is_active").default(true), isActive: boolean("is_active").default(true),
createdAt: timestamp("created_at").defaultNow(), createdAt: timestamp("created_at").defaultNow(),