Commit 5e34216d authored by Nguyễn Hải Sơn's avatar Nguyễn Hải Sơn

Initial commit

parents
Pipeline #245 canceled with stages
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
settings: {
react: {
version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use
},
},
extends: [
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
};
node_modules
dist
*.log
.env
\ No newline at end of file
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 120,
tabWidth: 4,
};
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon src/app.ts",
"build": "tsc -p ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.11",
"@types/node": "^14.14.37",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
},
"dependencies": {
"@types/mysql": "^2.15.18",
"express": "^4.17.1",
"http-status-codes": "^2.1.4",
"mysql": "^2.18.1"
}
}
import { AppConfig } from './configurations/app-config';
import express from 'express';
import demoApi from './routes/demo-api';
import meetingRoom from './routes/meeting-rooms';
const app = express();
app.use('/demo-api', demoApi);
app.use('/meeting-rooms', meetingRoom);
app.listen(AppConfig.PORT, () => console.log(`Server is running on port ${AppConfig.PORT}`));
export const AppConfig = {
PORT: 3000,
DB_CONNECTION_AMOUNT: 3,
DB_HOST: 'localhost',
DB_USER: 'qldh',
DB_PASSWORD: 'qldh@2021!wGqvF9DV4W',
DB_DATABASE: 'qldh',
DB_PORT: 3308,
};
import { AppConfig } from './../configurations/app-config';
import { createPool } from 'mysql';
export const DB_POOL = createPool({
connectionLimit: AppConfig.DB_CONNECTION_AMOUNT,
host: AppConfig.DB_HOST,
user: AppConfig.DB_USER,
password: AppConfig.DB_PASSWORD,
database: AppConfig.DB_DATABASE,
port: AppConfig.DB_PORT,
});
export enum DB_Tables {
device = 'device',
meetingRoom = 'room',
}
import { DB_POOL } from './../../database/qldh-mysql';
export const getDemoData = () => {
return new Promise<Record<string, unknown>>((resolve, reject) => {
DB_POOL.query('SELECT 1 + 1 AS solution', (error, results, fields) => {
if (error) {
reject({ error });
} else {
resolve({ results });
}
});
});
};
import { DB_POOL, DB_Tables } from '../../database/qldh-mysql';
import { FilterMeetingRoomOptions, MeetingRoom } from '../../models/MeetingRoom';
export const getMeetingRooms = (pageIndex: number, pageSize: number, Options?: FilterMeetingRoomOptions) => {
let query = `select * from ${DB_Tables.meetingRoom}`;
query += ` limit ${DB_POOL.escape((pageIndex - 1) * pageSize)}, ${DB_POOL.escape(pageSize)}`;
console.log(query);
return new Promise<Array<MeetingRoom>>((resolve, reject) => {
DB_POOL.query(query, (error, results: Array<MeetingRoom>, fields) => {
if (error) {
reject(error);
} else {
resolve(results);
}
});
});
};
export type Device = {
id: number;
code?: string;
name: string;
model?: string;
image?: string;
status?: number;
create_time?: Date;
create_by?: string;
update_time?: Date;
update_by?: string;
};
import { Device } from './Device';
export type FilterMeetingRoomOptions = {
status?: number;
name?: string;
capacity?: number;
devices?: Array<Device>;
};
export type MeetingRoom = {
id: number;
code?: string;
name: string;
description?: string;
capacity: number;
floor: number;
building: number;
status?: number;
};
import { Router } from 'express';
import { StatusCodes, ReasonPhrases } from 'http-status-codes';
import { getDemoData } from '../functions/demo-functions/demo-api';
const router = Router();
router.get('/', async (req, res) => {
try {
const data = await getDemoData();
res.status(StatusCodes.OK).send(data);
} catch (error) {
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({ error });
}
});
export default router;
import { Router } from 'express';
import { ReasonPhrases, StatusCodes } from 'http-status-codes';
import { getMeetingRooms } from '../../functions/meeting-rooms';
const router = Router();
router.get('/', async (req, res) => {
try {
const results = await getMeetingRooms(1, 10);
res.status(StatusCodes.OK).send(results);
} catch (error) {
res.status(StatusCodes.INTERNAL_SERVER_ERROR).send({
error,
message: ReasonPhrases.INTERNAL_SERVER_ERROR,
});
}
});
export default router;
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./dist" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */
/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
"skipLibCheck": true /* Skip type checking of declaration files. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment