add create endpoint
This commit is contained in:
26
.bruno/Plan Endpoints/create plan.bru
Normal file
26
.bruno/Plan Endpoints/create plan.bru
Normal 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
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
meta {
|
meta {
|
||||||
name: delete plan
|
name: delete plan
|
||||||
type: http
|
type: http
|
||||||
seq: 1
|
seq: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
delete {
|
delete {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
meta {
|
meta {
|
||||||
name: undelete plan
|
name: undelete plan
|
||||||
type: http
|
type: http
|
||||||
seq: 2
|
seq: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
put {
|
put {
|
||||||
|
|||||||
12
mod.ts
12
mod.ts
@@ -75,6 +75,18 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
|||||||
case 'POST':
|
case 'POST':
|
||||||
if (path === '/auth') {
|
if (path === '/auth') {
|
||||||
return genericResponse(STATUS_CODE.OK, JSON.stringify({ id, hasEmail }));
|
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;
|
break;
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
|
|||||||
Reference in New Issue
Block a user