From 0d1d995a7761bf72538b4acec915a6e10cc5bbc3 Mon Sep 17 00:00:00 2001 From: zhijinwuu Date: Thu, 12 Oct 2023 17:17:50 -0400 Subject: [PATCH 1/2] translate ping.js --- src/controllers/ping.js | 55 ++++++++++++++++++++++++++++++++++------- src/controllers/ping.ts | 13 ++++++++++ 2 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 src/controllers/ping.ts diff --git a/src/controllers/ping.js b/src/controllers/ping.js index 68ca1d0..d78f055 100644 --- a/src/controllers/ping.js +++ b/src/controllers/ping.js @@ -1,13 +1,50 @@ -'use strict'; - -const nconf = require('nconf'); -const db = require('../database'); - -module.exports.ping = async function (req, res, next) { +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ping = void 0; +const nconf = __importStar(require("nconf")); +const database_1 = __importDefault(require("../database")); +const ping = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { try { - await db.getObject('config'); + yield database_1.default.getObject('config'); res.status(200).send(req.path === `${nconf.get('relative_path')}/sping` ? 'healthy' : '200'); - } catch (err) { + } + catch (err) { next(err); } -}; +}); +exports.ping = ping; diff --git a/src/controllers/ping.ts b/src/controllers/ping.ts new file mode 100644 index 0000000..9643b5d --- /dev/null +++ b/src/controllers/ping.ts @@ -0,0 +1,13 @@ +import * as nconf from 'nconf'; +import { Request, Response, NextFunction } from 'express'; +import db from '../database'; + +export const ping = async (req: Request, res: Response, next: NextFunction) => { + try { + await db.getObject('config'); + res.status(200).send(req.path === `${nconf.get('relative_path')}/sping` ? 'healthy' : '200'); + } catch (err) { + next(err); + } +}; + From 37f71375e01966903a1712b0ac9971bb350f181b Mon Sep 17 00:00:00 2001 From: zhijinwuu Date: Thu, 12 Oct 2023 17:28:21 -0400 Subject: [PATCH 2/2] resolve lint errors --- src/controllers/ping.js | 58 +++++++++++++---------------------------- src/controllers/ping.ts | 14 ++++++---- 2 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/controllers/ping.js b/src/controllers/ping.js index d78f055..d36c10e 100644 --- a/src/controllers/ping.js +++ b/src/controllers/ping.js @@ -1,27 +1,3 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -31,20 +7,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; +// eslint-disable-next-line +const nconf = require('nconf'); +// eslint-disable-next-line +const db = require('../database'); +// eslint-disable-next-line +module.exports.ping = function (req, res, next) { + return __awaiter(this, void 0, void 0, function* () { + try { + // eslint-disable-next-line + yield db.getObject('config'); + // eslint-disable-next-line + res.status(200).send(req.path === `${nconf.get('relative_path')}/sping` ? 'healthy' : '200'); + } + catch (err) { + // eslint-disable-next-line + next(err); + } + }); }; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ping = void 0; -const nconf = __importStar(require("nconf")); -const database_1 = __importDefault(require("../database")); -const ping = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () { - try { - yield database_1.default.getObject('config'); - res.status(200).send(req.path === `${nconf.get('relative_path')}/sping` ? 'healthy' : '200'); - } - catch (err) { - next(err); - } -}); -exports.ping = ping; diff --git a/src/controllers/ping.ts b/src/controllers/ping.ts index 9643b5d..0d74b57 100644 --- a/src/controllers/ping.ts +++ b/src/controllers/ping.ts @@ -1,13 +1,17 @@ -import * as nconf from 'nconf'; -import { Request, Response, NextFunction } from 'express'; -import db from '../database'; +// eslint-disable-next-line +const nconf = require('nconf'); +// eslint-disable-next-line +const db = require('../database'); -export const ping = async (req: Request, res: Response, next: NextFunction) => { +// eslint-disable-next-line +module.exports.ping = async function (req, res, next) { try { + // eslint-disable-next-line await db.getObject('config'); + // eslint-disable-next-line res.status(200).send(req.path === `${nconf.get('relative_path')}/sping` ? 'healthy' : '200'); } catch (err) { + // eslint-disable-next-line next(err); } }; -