add create endpoint

This commit is contained in:
Ean Milligan
2026-04-09 17:08:59 -04:00
parent 495698f33e
commit 57a9678f38
4 changed files with 40 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
meta {
name: create plan
type: http
seq: 1
}
post {
url: http://localhost:14014/api/create
body: json
auth: inherit
}
body:json {
{
"name": "test",
"pin": "1234",
"planName": "test plan",
"folder": "",
"data": "data string"
}
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -1,7 +1,7 @@
meta {
name: delete plan
type: http
seq: 1
seq: 2
}
delete {

View File

@@ -1,7 +1,7 @@
meta {
name: undelete plan
type: http
seq: 2
seq: 3
}
put {

12
mod.ts
View File

@@ -75,6 +75,18 @@ Deno.serve({ port: config.api.port }, async (req) => {
case 'POST':
if (path === '/auth') {
return genericResponse(STATUS_CODE.OK, JSON.stringify({ id, hasEmail }));
} else if (path === '/create') {
if (body.planName.trim().length > 200) return genericResponse(STATUS_CODE.BadRequest, 'Name too long.');
if (body.folder.trim() && body.folder.trim().length > 200) return genericResponse(STATUS_CODE.BadRequest, 'Folder name too long.');
const newPlanId = nanoid();
await dbClient
.execute('INSERT INTO plans(id,ownerId,name,folder,data) values(?,?,?,?,?)', [newPlanId, id, body.planName.trim(), body.folder.trim(), body.data])
.catch(() => {
failed = true;
});
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't write DB.");
return genericResponse(STATUS_CODE.OK, JSON.stringify({ id: newPlanId, name: body.planName.trim() }));
}
break;
case 'PUT':