built read endpoint
This commit is contained in:
10
mod.ts
10
mod.ts
@@ -36,7 +36,15 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
// SSR "home page"
|
||||
return genericResponse(STATUS_CODE.NotImplemented, 'WIP');
|
||||
} else if (path.startsWith('/read/')) {
|
||||
return genericResponse(STATUS_CODE.NotImplemented, 'WIP');
|
||||
const planId = path.replace('/read/', '');
|
||||
|
||||
const plans = await dbClient.query('SELECT name, folder, data FROM plans WHERE id = ?', [planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
|
||||
if (!plans.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
|
||||
return genericResponse(STATUS_CODE.OK, JSON.stringify(plans[0]));
|
||||
} else if (path.startsWith('/list/')) {
|
||||
const userId = path.replace('/list/', '');
|
||||
const userMatch = await dbClient.query('SELECT id FROM users WHERE id = ?', [userId]).catch(() => {
|
||||
|
||||
Reference in New Issue
Block a user