JSFiddle - React, Tailwind, and code Playground

by ChrisStanyon

JavaScript

const Post = {
  FindById : id => new Promise((resolve, reject) => {
    if (id > 10) reject("Post Not Found");

    setTimeout(function() {
      resolve({ id : id, message : "Record Found" });
    }, 500);
  }),
  
  DeleteById : id => new Promise((resolve, reject) => {
      if (id > 10) reject("Could not delete");
			resolve({ id : id, message : "Record Deleted" });
  }),
}

Post.FindById(15)
	.then(result => {
  	console.log(result);
    return Post.DeleteById(result.id);
  })
  .then(result => console.log(result))
	.catch(error => console.log(error));