b
This commit is contained in:
+66
-4
@@ -127,6 +127,16 @@ export interface Collection {
|
||||
updatedAt: Date
|
||||
}
|
||||
|
||||
export interface WidgetPartner {
|
||||
id: string
|
||||
name: string
|
||||
url: string
|
||||
neighborhoodSlug: string | null
|
||||
isActive: boolean
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
}
|
||||
|
||||
export interface InstagramFeedCache {
|
||||
id: string
|
||||
listingId: string
|
||||
@@ -191,6 +201,7 @@ const globalForMockDb = globalThis as unknown as {
|
||||
instagramFeedCaches: InstagramFeedCache[]
|
||||
listingAnalyticsDaily: ListingAnalyticsDaily[]
|
||||
events: Event[]
|
||||
widgetPartners: WidgetPartner[]
|
||||
generatedItineraries: GeneratedItinerary[]
|
||||
initialized: boolean
|
||||
__version: number
|
||||
@@ -586,6 +597,8 @@ if (!globalForMockDb.initialized || globalForMockDb.__version !== MOCK_DB_VERSIO
|
||||
]
|
||||
|
||||
// Seed Events
|
||||
globalForMockDb.widgetPartners = []
|
||||
|
||||
globalForMockDb.events = [
|
||||
{
|
||||
id: 'evt-1',
|
||||
@@ -1307,14 +1320,63 @@ export const mockDb = {
|
||||
// Phase 3 Widget & Backlink
|
||||
async getWidgetPartners() {
|
||||
if (this.isMock()) {
|
||||
return globalForMockDb.listings.filter(l => l.hasWidgetInstalled && !l.deletedAt)
|
||||
return globalForMockDb.widgetPartners.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
|
||||
}
|
||||
return db.listing.findMany({
|
||||
where: { hasWidgetInstalled: true, deletedAt: null },
|
||||
include: { category: true, neighborhood: true }
|
||||
return db.widgetPartner.findMany({
|
||||
orderBy: { createdAt: 'desc' }
|
||||
})
|
||||
},
|
||||
|
||||
async getWidgetPartner(id: string) {
|
||||
if (this.isMock()) {
|
||||
return globalForMockDb.widgetPartners.find(w => w.id === id) || null
|
||||
}
|
||||
return db.widgetPartner.findUnique({ where: { id } })
|
||||
},
|
||||
|
||||
async createWidgetPartner(data: Omit<WidgetPartner, 'id' | 'createdAt' | 'updatedAt'>) {
|
||||
if (this.isMock()) {
|
||||
const newPartner: WidgetPartner = {
|
||||
id: `wp-${Date.now()}`,
|
||||
...data,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date()
|
||||
}
|
||||
globalForMockDb.widgetPartners.push(newPartner)
|
||||
return newPartner
|
||||
}
|
||||
return db.widgetPartner.create({ data })
|
||||
},
|
||||
|
||||
async updateWidgetPartner(id: string, data: Partial<WidgetPartner>) {
|
||||
if (this.isMock()) {
|
||||
const idx = globalForMockDb.widgetPartners.findIndex(w => w.id === id)
|
||||
if (idx !== -1) {
|
||||
globalForMockDb.widgetPartners[idx] = {
|
||||
...globalForMockDb.widgetPartners[idx],
|
||||
...data,
|
||||
updatedAt: new Date()
|
||||
}
|
||||
return globalForMockDb.widgetPartners[idx]
|
||||
}
|
||||
return null
|
||||
}
|
||||
return db.widgetPartner.update({ where: { id }, data })
|
||||
},
|
||||
|
||||
async deleteWidgetPartner(id: string) {
|
||||
if (this.isMock()) {
|
||||
const idx = globalForMockDb.widgetPartners.findIndex(w => w.id === id)
|
||||
if (idx !== -1) {
|
||||
globalForMockDb.widgetPartners.splice(idx, 1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
await db.widgetPartner.delete({ where: { id } })
|
||||
return true
|
||||
},
|
||||
|
||||
// Phase 3 Analytics daily aggregates
|
||||
async getAnalytics(listingId: string, startDate?: Date, endDate?: Date) {
|
||||
if (this.isMock()) {
|
||||
|
||||
Reference in New Issue
Block a user