Skip to content

Instantly share code, notes, and snippets.

@malihassan20

malihassan20/cosmic.js Secret

Last active Jan 18, 2018
Embed
What would you like to do?
nextJs-tour-diary-app\cosmic\cosmic.js
import Cosmic from 'cosmicjs';
import config from './config';
export default function cosmic(type, params) {
if (type === 'GET_TYPE') {
return new Promise((resolve, reject) => {
Cosmic.getObjectType(config, params, (err, res) => {
if (!err) {
resolve(res.objects.all);
} else {
reject(err);
}
});
});
} else if (type === 'SEARCH_BY_TYPE') {
return new Promise((resolve, reject) => {
Cosmic.getObjectsBySearch(config, params, (err, res) => {
if (!err) {
resolve(res.objects.all);
} else {
reject(err);
}
});
});
} else if (type === 'ADD') {
return new Promise((resolve, reject) => {
Cosmic.addObject(config, params, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
});
} else if (type === 'EDIT') {
return new Promise((resolve, reject) => {
Cosmic.editObject(config, params, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
});
} else if (type === 'DELETE') {
return new Promise((resolve, reject) => {
Cosmic.deleteObject(config, params, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
});
} else if (type === 'ADD_MEDIA') {
return new Promise((resolve, reject) => {
Cosmic.addMedia(config, params, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
});
} else if (type === 'DELETE_MEDIA') {
return new Promise((resolve, reject) => {
Cosmic.deleteMedia(config, params, (err, res) => {
if (!err) {
resolve(res);
} else {
reject(err);
}
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment