19 lines
491 B
TypeScript
19 lines
491 B
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import { Restaurant } from '@/app/types'
|
|
|
|
const DATA_FILE = path.join(process.cwd(), 'data', 'restaurants.json')
|
|
|
|
export function readRestaurants(): Restaurant[] {
|
|
try {
|
|
const raw = fs.readFileSync(DATA_FILE, 'utf-8')
|
|
return JSON.parse(raw) as Restaurant[]
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
export function writeRestaurants(restaurants: Restaurant[]): void {
|
|
fs.writeFileSync(DATA_FILE, JSON.stringify(restaurants, null, 2), 'utf-8')
|
|
}
|