Skip to content

Instantly share code, notes, and snippets.

@a9kit
Created January 27, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a9kit/c039fad9044e6367155d398b6a55b10a to your computer and use it in GitHub Desktop.
Save a9kit/c039fad9044e6367155d398b6a55b10a to your computer and use it in GitHub Desktop.
import config from './../config/config';
import axios from 'axios';
const newsData = {
// add news to Cosmic JS database
addnews(title, description, newsbody, date)
{
return axios.post(config.url+config.bucket_slug+"/add-object/", {
title: title, slug: title, content: newsbody, type_slug: 'news', write_key: config.write_key,
metafields: [
{
key: "description",
type: "text",
value: description
},
{
key: "date",
type: "text",
value: date
}
]
})
},
// fetch all news from Cosmic JS database
getNews()
{
return axios.get(config.url+config.bucket_slug+"/object-type/news",{
params: {
read_key: config.read_key
}
})
},
// submiting comment
submitComment(name, comment, newsId)
{
return axios.post(config.url+config.bucket_slug+"/add-object/", {
title: name, slug: name, content: newsId, type_slug: 'comments', write_key: config.write_key,
metafields: [
{
key: "comment",
type: "text",
value: comment
}
]
})
},
// all comments
allComments()
{
return axios.get(config.url+config.bucket_slug+"/object-type/comments",{
params: {
read_key: config.read_key
}
})
}
}
export default newsData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment