2023-02-11 10:22:15 -05:00
|
|
|
const mongoose = require('mongoose');
|
|
|
|
|
|
2023-05-18 11:09:31 -07:00
|
|
|
const promptSchema = mongoose.Schema(
|
|
|
|
|
{
|
|
|
|
|
title: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
prompt: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true
|
|
|
|
|
},
|
|
|
|
|
category: {
|
|
|
|
|
type: String
|
|
|
|
|
}
|
2023-02-11 10:22:15 -05:00
|
|
|
},
|
2023-05-18 11:09:31 -07:00
|
|
|
{ timestamps: true }
|
|
|
|
|
);
|
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,
|
|
|
|
|
prompt
|
|
|
|
|
});
|
|
|
|
|
return { title, prompt };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return { prompt: 'Error saving prompt' };
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getPrompts: async (filter) => {
|
|
|
|
|
try {
|
2023-05-18 11:09:31 -07:00
|
|
|
return await Prompt.find(filter).exec();
|
2023-02-11 10:22:15 -05:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return { prompt: 'Error getting prompts' };
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deletePrompts: async (filter) => {
|
|
|
|
|
try {
|
2023-05-18 11:09:31 -07:00
|
|
|
return await Prompt.deleteMany(filter).exec();
|
2023-02-11 10:22:15 -05:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
return { prompt: 'Error deleting prompts' };
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-18 11:09:31 -07:00
|
|
|
};
|