I’m never able to remember how this is done
const getPage = async (pageId) => {
const data = {};
const response = await notion.pages.retrieve({ page_id: pageId });
data.id = pageId;
data.name = response.properties.Name.title[0].plain_text;
data.imageUrl = response.properties.img.rich_text[0].plain_text;
data.stock = response.properties.stock.rich_text[0].plain_text;
data.price = `£${response.properties.price.number}`;
return data;
};
The above return a data object when I pass it an id. The I want to add each object in an array
const getPosts = async () => {
const { results } = await notion.request({
path: `databases/${process.env.NOTION_DATABASE_ID}/query/`,
method: "POST",
});
const test = results.map((prop) => {
const id = prop.id;
const data = [];
getPage(id).then((t) => data.push(t)); // this is the problem right?
return data;
});
console.log(test);
};
getPosts();
I’m sure I did it before but I have no idea how.