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:
+17
-12
@@ -479,20 +479,25 @@ export class DatabaseStorage implements IStorage {
|
||||
}
|
||||
|
||||
async getProfessionalServices(type?: string, location?: string): Promise<ProfessionalService[]> {
|
||||
let query = db
|
||||
.select()
|
||||
.from(professionalServices)
|
||||
.where(eq(professionalServices.isActive, true));
|
||||
try {
|
||||
let query = db
|
||||
.select()
|
||||
.from(professionalServices)
|
||||
.where(eq(professionalServices.isActive, true));
|
||||
|
||||
if (type) {
|
||||
query = query.where(eq(professionalServices.serviceType, type));
|
||||
}
|
||||
|
||||
if (location) {
|
||||
query = query.where(eq(professionalServices.location, location));
|
||||
}
|
||||
if (type) {
|
||||
query = query.where(eq(professionalServices.type, type));
|
||||
}
|
||||
|
||||
if (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> {
|
||||
|
||||
+8
-10
@@ -359,20 +359,18 @@ export const messageStatuses = pgTable("message_statuses", {
|
||||
// Professional services table
|
||||
export const professionalServices = pgTable("professional_services", {
|
||||
id: serial("id").primaryKey(),
|
||||
providerId: integer("provider_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
name: text("name").notNull(),
|
||||
userId: integer("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
providerId: integer("provider_id").references(() => users.id, { onDelete: "cascade" }),
|
||||
name: text("name"),
|
||||
title: text("title"),
|
||||
description: text("description"),
|
||||
type: professionalTypeEnum("type").notNull(),
|
||||
serviceType: professionalTypeEnum("service_type").notNull(),
|
||||
specializations: text("specializations").array(),
|
||||
hourlyRate: numeric("hourly_rate", { precision: 10, scale: 2 }),
|
||||
currency: varchar("currency", { length: 3 }).default("OMR"),
|
||||
availability: json("availability").$type<{
|
||||
[key: string]: { start: string; end: string; available: boolean }[]
|
||||
}>(),
|
||||
priceRange: text("price_range"),
|
||||
availabilitySchedule: text("availability_schedule"),
|
||||
location: text("location"),
|
||||
isOnline: boolean("is_online").default(false),
|
||||
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),
|
||||
isActive: boolean("is_active").default(true),
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
|
||||
Reference in New Issue
Block a user