Fix TypeScript error: Add RSVP interface to properly type the rsvp parameter in map function
This commit is contained in:
@@ -25,6 +25,18 @@ app.use('/uploads', express.static(path.join(__dirname, '../uploads')));
|
|||||||
// Database connection
|
// Database connection
|
||||||
let db: any;
|
let db: any;
|
||||||
|
|
||||||
|
interface RSVP {
|
||||||
|
id: number;
|
||||||
|
event_id: number;
|
||||||
|
name: string;
|
||||||
|
attending: string;
|
||||||
|
bringing_guests: string;
|
||||||
|
guest_count: number;
|
||||||
|
guest_names: string | null;
|
||||||
|
items_bringing: string | null;
|
||||||
|
created_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
async function connectToDatabase() {
|
async function connectToDatabase() {
|
||||||
try {
|
try {
|
||||||
// Database file will be in the app directory
|
// Database file will be in the app directory
|
||||||
@@ -216,7 +228,7 @@ app.get('/api/events/:slug/rsvps', async (req: Request, res: Response) => {
|
|||||||
const rows = await db.all('SELECT * FROM rsvps WHERE event_id = ?', [eventId]);
|
const rows = await db.all('SELECT * FROM rsvps WHERE event_id = ?', [eventId]);
|
||||||
|
|
||||||
// Parse JSON arrays in each RSVP
|
// Parse JSON arrays in each RSVP
|
||||||
const parsedRows = rows.map(rsvp => {
|
const parsedRows = rows.map((rsvp: RSVP) => {
|
||||||
try {
|
try {
|
||||||
return {
|
return {
|
||||||
...rsvp,
|
...rsvp,
|
||||||
|
|||||||
Reference in New Issue
Block a user