2023-02-11 10:22:15 -05:00
|
|
|
const mongoose = require('mongoose');
|
2023-12-14 07:49:27 -05:00
|
|
|
const { logger } = require('~/config');
|
2023-02-11 10:22:15 -05:00
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const promptSchema = mongoose.Schema(
|
|
|
|
|
{
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
2023-07-14 09:36:49 -04:00
|
|
|
required: true,
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
|
prompt: {
|
|
|
|
|
type: String,
|
2023-07-14 09:36:49 -04:00
|
|
|
required: true,
|
2023-05-18 11:09:31 -07:00
|
|
|
},
|
|
|
|
|
category: {
|
2023-07-14 09:36:49 -04:00
|
|
|
type: String,
|
|
|
|
|
},
|
2023-02-11 10:22:15 -05:00
|
|
|
},
|
2023-07-14 09:36:49 -04:00
|
|
|
{ timestamps: true },
|
2023-05-18 11:09:31 -07:00
|
|
|
);
|
2023-02-11 10:22:15 -05:00
|
|
|
|
|
|
|
|
const Prompt = mongoose.models.Prompt || mongoose.model('Prompt', promptSchema);
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
savePrompt: async ({ title, prompt }) => {
|
|
|
|
|
try {
|
|
|
|
|
await Prompt.create({
|
|
|
|
|
title,
|
2023-07-14 09:36:49 -04:00
|
|
|
prompt,
|
2023-02-11 10:22:15 -05:00
|
|
|
});
|
|
|
|
|
return { title, prompt };
|
|
|
|
|
} catch (error) {
|
2023-12-14 07:49:27 -05:00
|
|
|
logger.error('Error saving prompt', error);
|
2023-02-11 10:22:15 -05:00
|
|
|
return { prompt: 'Error saving prompt' };
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getPrompts: async (filter) => {
|
|
|
|
|
try {
|
2023-07-25 19:27:55 -04:00
|
|
|
return await Prompt.find(filter).lean();
|
2023-02-11 10:22:15 -05:00
|
|
|
} catch (error) {
|
2023-12-14 07:49:27 -05:00
|
|
|
logger.error('Error getting prompts', error);
|
2023-02-11 10:22:15 -05:00
|
|
|
return { prompt: 'Error getting prompts' };
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deletePrompts: async (filter) => {
|
|
|
|
|
try {
|
2023-07-25 19:27:55 -04:00
|
|
|
return await Prompt.deleteMany(filter);
|
2023-02-11 10:22:15 -05:00
|
|
|
} catch (error) {
|
2023-12-14 07:49:27 -05:00
|
|
|
logger.error('Error deleting prompts', error);
|
2023-02-11 10:22:15 -05:00
|
|
|
return { prompt: 'Error deleting prompts' };
|
|
|
|
|
}
|
2023-07-14 09:36:49 -04:00
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
};
|