TypeError: Cannot read properties of undefined

I'm getting the following error when I try to insert into a view.
"TypeError: Cannot read properties of undefined (reading 'entity_cagematch_id')\n    at C:\\Users\\manue\\Documents\\wrestle-stonks\\wrestlestonks\\node_modules\\drizzle-orm\\pg-core\\query-builders\\insert.cjs:62:122\n    at Array.map (<anonymous>)\n    at PgInsertBuilder.values (C:\\Users\\manue\\Documents\\wrestle-stonks\\wrestlestonks\\node_modules\\drizzle-orm\\pg-core\\query-builders\\insert.cjs:57:33)\n    at EntityEloManager.insertELOEntities (C:\\Users\\manue\\Documents\\wrestle-stonks\\wrestlestonks\\managers\\EntityEloManager.js:149:58)\n    at updateEloToDate (C:\\Users\\manue\\Documents\\wrestle-stonks\\wrestlestonks\\index.js:37:49)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async start (C:\\Users\\manue\\Documents\\wrestle-stonks\\wrestlestonks\\index.js:52:9)"

This is the code that makes the insert:
async insertELOEntities(entities){
        try{
            //const xata = getXataClient();
            const sql = neon(process.env.DATABASE_URL_TEST);
            const db = drizzle({ client: sql });
            const eloEntities = entities.map(entity => ({
                entity_cagematch_id: entity.id,
                type_id: getEntityTypeByDescription(entity.type).id,
                entity_name: entity.name,
                elo_date: entity.lastMatchDate,
                elo_prev_elo: entity.oldElo,
                elo_new_elo: entity.newELO
            }));
        const inserted = await db.insert(vEntityEloView).values(eloEntities).execute(); 
            if(inserted.rowCount > 0){
                return inserted.rowCount;
            }
            return inserted;
        } catch(e){
            logger.error({message: e.message, stack: e.stack});
        }
        return null;
    }
Was this page helpful?