Skip to content

Instantly share code, notes, and snippets.

@vsnai
Last active March 21, 2021 16:43
Show Gist options
  • Save vsnai/6c12af00ba0b16758a0225e53e337b92 to your computer and use it in GitHub Desktop.
Save vsnai/6c12af00ba0b16758a0225e53e337b92 to your computer and use it in GitHub Desktop.
C POST
R GET
U PUT
D DELETE
  • GET /api/v1/properties
_id     img         city        size        price
1       [1, 2]      Riga        500         150000
2       [4]         Jelgava     1000        200000
  • POST /api/v1/properties
// reference: pages/api/v1/tweet.js
if (req.method === 'POST') {
  const { property } = req.body;

  db.collection('properties').insert({
    userId: ObjectId(session.user._id),
    images: [
      "https://images.unsplash.com/photo-1512917774080-9991f1c4c750?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80",
      "https://images.unsplash.com/photo-1513584684374-8bab748fbf90?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1946&q=80",
    ],
    city: property.city,
    size: property.size,
    price: property.price,
  });

  res.send(201).end();
}

Seed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment