Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created November 8, 2023 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aschen/4d5c91984ee3c7942362dfb71cfe29a8 to your computer and use it in GitHub Desktop.
Save Aschen/4d5c91984ee3c7942362dfb71cfe29a8 to your computer and use it in GitHub Desktop.
Assistant OpenAI benchmark
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;
}
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
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