add re-execute API
error hundling
This commit is contained in:
parent
395fba645d
commit
c004f6c34f
6 changed files with 99 additions and 93 deletions
|
|
@ -3,7 +3,7 @@ import zlib from "zlib";
|
|||
import { storageController } from "./logics/storage";
|
||||
import { MiiTelWebhookSchema, processRequest } from "./logics/process";
|
||||
import { hubspotController } from "./logics/hubspot";
|
||||
import { createCustomError } from "./logics/error";
|
||||
import { createCustomError, responseError } from "./logics/error";
|
||||
import { CLOUD_STORAGE_LOG_FOLDER_NAME, CLOUD_STORAGE_MASTER_FOLDER_NAME, COMPANIES_FILE_NAME, OWNERS_FILE_NAME } from "../serverConfig";
|
||||
|
||||
const router = express.Router();
|
||||
|
|
@ -20,14 +20,15 @@ router.post("/miitel", async (req, res) => {
|
|||
await storageController.saveToGCS(CLOUD_STORAGE_LOG_FOLDER_NAME, `${videoInfo.id}.json.gz`, gzipped, 'application/gzip');
|
||||
|
||||
await processRequest(videoInfo);
|
||||
// if(!result) throw
|
||||
|
||||
res.status(200).send("ok");
|
||||
} catch(err) {
|
||||
res.status(400).send("Invalid webhook body");
|
||||
responseError(err, res)
|
||||
}
|
||||
});
|
||||
|
||||
// Update Master Data And Check Google Drive Folder
|
||||
// Refresh Master Data Everyday
|
||||
router.post("/dailyBatch", async (req, res) => {
|
||||
try {
|
||||
console.log("Starting daily batch process...");
|
||||
|
|
@ -41,7 +42,6 @@ router.post("/dailyBatch", async (req, res) => {
|
|||
if(!owners) throw createCustomError("GET_COMPANIES_FAILED");
|
||||
await storageController.saveToGCS(CLOUD_STORAGE_MASTER_FOLDER_NAME, OWNERS_FILE_NAME, JSON.stringify(owners), 'application/json');
|
||||
|
||||
// check folders in Google Drive
|
||||
res.status(200).send("Daily batch executed.");
|
||||
|
||||
} catch (error) {
|
||||
|
|
@ -61,6 +61,29 @@ router.post("/getLog", async (req, res) => {
|
|||
});
|
||||
|
||||
|
||||
// Check Log By Meeting ID
|
||||
router.post("/reExecute", async (req, res) => {
|
||||
try {
|
||||
console.log(req.body);
|
||||
const meetingId = req.body.meetingId;
|
||||
const newTitle = req.body.newTitle;
|
||||
const log = await storageController.loadFromGCS(CLOUD_STORAGE_LOG_FOLDER_NAME, `${meetingId}.json.gz`);
|
||||
if(!log) throw Error();
|
||||
const params = MiiTelWebhookSchema.safeParse(JSON.parse(log));
|
||||
if(!params.success) throw createCustomError("ZOD_FAILED");
|
||||
params.data.video.title = newTitle;
|
||||
// console.log(params.data.video)
|
||||
|
||||
await processRequest(params.data.video);
|
||||
|
||||
res.send(log);
|
||||
} catch(error) {
|
||||
console.log("===== Route Log =====")
|
||||
console.log(error);
|
||||
res.status(400).send("Failed");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// router.post("/deleteFile", async (req, res) => {
|
||||
// console.log(req.body);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue