Created
November 8, 2023 19:45
-
-
Save Aschen/4d5c91984ee3c7942362dfb71cfe29a8 to your computer and use it in GitHub Desktop.
Assistant OpenAI benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTask (req, res) { | |
const newTask = req.body; | |
verifyTask(newTask); | |
const savedTask = database.addTask(newTask); | |
res.status(201).send(`Task ${savedTask.metadata.id} saved successfully`); | |
} | |
function addTask(newTask) { | |
const tasks = readTasksFromFile(); | |
const taskWithId = { ...newTask, metadata: { id: generateId() } }; | |
tasks.push(taskWithId); | |
writeTasksToFile(tasks); | |
return taskWithId; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTask(req, res) { | |
const newTask = req.body; | |
if (!newTask.metadata || typeof newTask.metadata.id !== 'string') { | |
return res.status(400).send('Invalid task metadata'); | |
} | |
verifyTask(newTask); | |
addTask(newTask); | |
res.status(201).send(`Task ${newTask.metadata.id} saved successfully`); | |
} | |
function verifyTask(task) { | |
if (typeof task.title !== 'string' || task.title.length > 120) { | |
throw new Error('Invalid title'); | |
} | |
if (typeof task.position !== 'number' || task.position < 0) { | |
throw new Error('Invalid position'); | |
} | |
// Ensure verifyTask does not mutate the task object | |
return true; | |
} | |
// No correction for addTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTask (req, res) { | |
const newTask = req.body; | |
verifyTask(newTask); | |
addTask(newTask); | |
res.status(201).send(`Task ${newTask.metadata.id} saved successfully`); | |
} | |
function verifyTask(task) { | |
if (typeof task.title !== 'string' || task.title.length > 120) { | |
throw new Error('Invalid title'); | |
} | |
if (typeof task.position !== 'number' || task.position < 0) { | |
throw new Error('Invalid position'); | |
} | |
return true; | |
} | |
function addTask(newTask) { | |
const tasks = readTasksFromFile(); | |
tasks.push({ ...newTask, metadata: { id: generateId() } }); | |
writeTasksToFile(tasks); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment