import { Prompt } from "@models/Prompt.model";
/**
* Prompt Service
* @category Services
*/
export class PromptService {
/**
* Retrieves a prompt by its name from the database.
* @category Services
* @param {string} name - The name of the prompt to retrieve.
* @returns {Promise<IPrompt | null>} - The prompt object if found.
* @throws {Error} If no prompt with the specified name is found or if a database error occurs.
*/
async getPromptByName(name) {
try {
const prompt = await Prompt.findOne({ name: name });
if (!prompt) {
throw new Error(`${name} prompt not found.`);
}
return prompt;
}
catch (error) {
throw error;
}
}
}
Source