From fa3b768b0642e87cc273b8a4cb2f90071cf9af27 Mon Sep 17 00:00:00 2001 From: tsunami776 <43768723+tsunami776@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:05:04 -0600 Subject: [PATCH] Create default prompt when there is no prompt --- src/controllers/dashBoardController.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/controllers/dashBoardController.js b/src/controllers/dashBoardController.js index 3a203481f..40037297a 100644 --- a/src/controllers/dashBoardController.js +++ b/src/controllers/dashBoardController.js @@ -27,10 +27,26 @@ const dashboardcontroller = function () { const getDashBoardData = function (req, res) { DashboardData.findById({ _id: 'ai-prompt' }) - .then((results) => { - res.status(200).send(results); - }) - .catch(error => res.status(500).send(error)); + .then((result) => { + if (result) { + // If the GPT prompt exists, send it back. + res.status(200).send(result); + } else { + // If the GPT prompt does not exist, create it. + const defaultPrompt = { + _id: 'ai-prompt', + aIPromptText: "Please edit the following summary of my week's work. Make sure it is professionally written in 3rd person format.\nWrite it as only one paragraph. It must be only one paragraph. Keep it less than 500 words. Start the paragraph with 'This week'.\nMake sure the paragraph contains no links or URLs and write it in a tone that is matter-of-fact and without embellishment.\nDo not add flowery language, keep it simple and factual. Do not add a final summary sentence. Apply all this to the following:" + }; + DashboardData.create(defaultPrompt) + .then((newResult) => { + res.status(200).send(newResult); + }) + .catch((creationError) => { + res.status(500).send(creationError); + }); + } + }) + .catch(error => res.status(500).send(error)); }; const monthlydata = function (req, res) {