add create endpoint
This commit is contained in:
12
mod.ts
12
mod.ts
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user