-
-
Save malihassan20/e1bd7abeb5e6fac0d02fca0d0a22bb7f to your computer and use it in GitHub Desktop.
nextJs-tour-diary-app\cosmic\cosmic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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