2023-03-04 17:39:06 -05:00
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
2023-03-07 13:19:56 -05:00
|
|
|
const { getCustomGpts, updateCustomGpt, updateByLabel, deleteCustomGpts } = require('../../models');
|
2023-03-04 17:39:06 -05:00
|
|
|
|
|
|
|
|
router.get('/', async (req, res) => {
|
|
|
|
|
const models = (await getCustomGpts()).map(model => {
|
|
|
|
|
model = model.toObject();
|
|
|
|
|
model._id = model._id.toString();
|
|
|
|
|
return model;
|
|
|
|
|
});
|
|
|
|
|
res.status(200).send(models);
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-07 13:19:56 -05:00
|
|
|
router.post('/delete', async (req, res) => {
|
|
|
|
|
const { arg } = req.body;
|
2023-03-04 17:39:06 -05:00
|
|
|
|
|
|
|
|
try {
|
2023-03-07 13:19:56 -05:00
|
|
|
const dbResponse = await deleteCustomGpts(arg);
|
2023-03-04 17:39:06 -05:00
|
|
|
res.status(201).send(dbResponse);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
res.status(500).send(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// router.post('/create', async (req, res) => {
|
|
|
|
|
// const payload = req.body.arg;
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// const dbResponse = await createCustomGpt(payload);
|
|
|
|
|
// res.status(201).send(dbResponse);
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.error(error);
|
|
|
|
|
// res.status(500).send(error);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
router.post('/', async (req, res) => {
|
|
|
|
|
const update = req.body.arg;
|
|
|
|
|
|
2023-03-07 13:19:56 -05:00
|
|
|
let setter = updateCustomGpt;
|
|
|
|
|
|
|
|
|
|
if (update.prevLabel) {
|
|
|
|
|
setter = updateByLabel;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 17:39:06 -05:00
|
|
|
try {
|
2023-03-07 13:19:56 -05:00
|
|
|
const dbResponse = await setter(update);
|
2023-03-04 17:39:06 -05:00
|
|
|
res.status(201).send(dbResponse);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
res.status(500).send(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|