Implement lastUpdated timestamp
This commit is contained in:
12
mod.ts
12
mod.ts
@@ -67,7 +67,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
|
||||
if (!userMatch.length) return genericResponse(STATUS_CODE.NotFound, 'User ID does not exist.');
|
||||
|
||||
const plans = await dbClient.query('SELECT id, name, folder FROM plans WHERE ownerId = ? AND deleted = 0', [userId]).catch(() => {
|
||||
const plans = await dbClient.query('SELECT id, name, folder, lastUpdated FROM plans WHERE ownerId = ? AND deleted = 0', [userId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't read DB.");
|
||||
@@ -153,7 +153,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (!planMatch.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
if (planMatch[0].ownerId !== id) return genericResponse(STATUS_CODE.Forbidden, "You don't own this plan.");
|
||||
|
||||
await dbClient.execute('UPDATE plans SET deleted = 0 WHERE id = ?', [planId]).catch(() => {
|
||||
await dbClient.execute('UPDATE plans SET deleted = 0, lastUpdated = ? WHERE id = ?', [new Date(), planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't update DB.");
|
||||
@@ -167,7 +167,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (!planMatch.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
if (planMatch[0].ownerId !== id) return genericResponse(STATUS_CODE.Forbidden, "You don't own this plan.");
|
||||
|
||||
await dbClient.execute('UPDATE plans SET data = ? WHERE id = ?', [body.data, planId]).catch(() => {
|
||||
await dbClient.execute('UPDATE plans SET data = ?, lastUpdated = ? WHERE id = ?', [body.data, new Date(), planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't update DB.");
|
||||
@@ -183,7 +183,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (!planMatch.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
if (planMatch[0].ownerId !== id) return genericResponse(STATUS_CODE.Forbidden, "You don't own this plan.");
|
||||
|
||||
await dbClient.execute('UPDATE plans SET name = ? WHERE id = ?', [body.planName, planId]).catch(() => {
|
||||
await dbClient.execute('UPDATE plans SET name = ?, lastUpdated = ? WHERE id = ?', [body.planName, new Date(), planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't update DB.");
|
||||
@@ -199,7 +199,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (!planMatch.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
if (planMatch[0].ownerId !== id) return genericResponse(STATUS_CODE.Forbidden, "You don't own this plan.");
|
||||
|
||||
await dbClient.execute('UPDATE plans SET folder = ? WHERE id = ?', [body.folder, planId]).catch(() => {
|
||||
await dbClient.execute('UPDATE plans SET folder = ?, lastUpdated = ? WHERE id = ?', [body.folder, new Date(), planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't update DB.");
|
||||
@@ -280,7 +280,7 @@ Deno.serve({ port: config.api.port }, async (req) => {
|
||||
if (!planMatch.length) return genericResponse(STATUS_CODE.NotFound, 'Plan ID does not exist.');
|
||||
if (planMatch[0].ownerId !== id) return genericResponse(STATUS_CODE.Forbidden, "You don't own this plan.");
|
||||
|
||||
await dbClient.execute('UPDATE plans SET deleted = 1 WHERE id = ?', [planId]).catch(() => {
|
||||
await dbClient.execute('UPDATE plans SET deleted = 1, lastUpdated = ? WHERE id = ?', [new Date(), planId]).catch(() => {
|
||||
failed = true;
|
||||
});
|
||||
if (failed) return genericResponse(STATUS_CODE.InternalServerError, "Couldn't update DB.");
|
||||
|
||||
Reference in New Issue
Block a user