From 040b13282f65df32b72dfa2807da85538d0c0121 Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Tue, 19 Dec 2023 12:46:56 +0800 Subject: [PATCH] Add COE result endpoint --- packages/functions/src/coe.ts | 13 +++++++++---- stacks/MyStack.ts | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/functions/src/coe.ts b/packages/functions/src/coe.ts index 77b1a74..18cde52 100644 --- a/packages/functions/src/coe.ts +++ b/packages/functions/src/coe.ts @@ -1,11 +1,16 @@ import { ApiHandler } from "sst/node/api"; -import { COE } from "@lta-datasets-updater/core/coe"; +import db from "../../config/db"; -export const updater = ApiHandler(async (_evt) => { - const { message } = await COE.updater(); +export const result = ApiHandler(async (_evt) => { + const result = await db + .collection("coe") + .find({ month: "2023-12" }) + .toArray(); + + console.log(`COE result:`, result); return { statusCode: 200, - body: JSON.stringify({ status: 200, message }), + body: JSON.stringify(result), }; }); diff --git a/stacks/MyStack.ts b/stacks/MyStack.ts index 571711b..06cea46 100644 --- a/stacks/MyStack.ts +++ b/stacks/MyStack.ts @@ -30,6 +30,7 @@ export const api = ({ stack }: StackContext) => { "GET /brands": "packages/functions/src/brand.brands", "GET /car/electric": "packages/functions/src/car.electric", "GET /car/petrol": "packages/functions/src/car.petrol", + "GET /coe": "packages/functions/src/coe.result", "GET /updater/cars": "packages/functions/src/updater.cars", "GET /updater/coe": "packages/functions/src/updater.coe", },