分页查询添加

This commit is contained in:
zhangyiming 2020-12-01 16:40:52 +08:00
parent 7cf0756eb6
commit 081ac958c9
5 changed files with 67 additions and 31 deletions

View File

@ -1,5 +1,5 @@
{ {
"name": "check-ts", "name": "backend-ts",
"version": "1.0.0", "version": "1.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
@ -3749,4 +3749,4 @@
} }
} }
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "check-ts", "name": "backend-ts",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "API接口",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
@ -9,7 +9,7 @@
"start": "nodemon ./dist/server.js", "start": "nodemon ./dist/server.js",
"prod": "npm run build && npm run start" "prod": "npm run build && npm run start"
}, },
"author": "Coral Ram", "author": "team",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"nodemon": "^1.19.4", "nodemon": "^1.19.4",
@ -27,4 +27,4 @@
"svg-captcha": "^1.4.0", "svg-captcha": "^1.4.0",
"winston": "^3.3.3" "winston": "^3.3.3"
} }
} }

View File

@ -16,9 +16,9 @@ export default {
options: { options: {
swaggerDefinition: { swaggerDefinition: {
info: { info: {
description: 'This is a server', description: 'CURD-TS专用接口',
title: 'Swagger', title: 'Swagger',
version: '1.0.0' version: require('../../package.json').version
}, },
host: `localhost:${parseInt(process.env.PORT, 10)}`, host: `localhost:${parseInt(process.env.PORT, 10)}`,
basePath: '/', basePath: '/',
@ -29,7 +29,7 @@ export default {
type: 'apiKey', type: 'apiKey',
in: 'header', in: 'header',
name: 'Authorization', name: 'Authorization',
description: '' description: 'Bearer Authorization'
} }
} }
}, },

View File

@ -12,14 +12,7 @@ export interface dataModel {
} }
// 保存验证码 // 保存验证码
let generateVerify: number | string let generateVerify: number
/**
* @typedef Login
* @property {string} username.required -
* @property {string} password.required -
* @property {string} verify.required -
*/
/** /**
* @typedef Error * @typedef Error
@ -31,12 +24,21 @@ let generateVerify: number | string
* @property {[integer]} code * @property {[integer]} code
*/ */
/**
* @typedef Login
* @property {string} username.required - - eg: admin
* @property {string} password.required - - eg: 123456
* @property {integer} verify.required -
*/
/** /**
* *
* @route POST /login * @route POST /login
* @param {Login.model} point.body.required - the new point * @param {Login.model} point.body.required - the new point
* @produces application/json application/xml * @produces application/json application/xml
* @consumes application/json application/xml * @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200 * @returns {Response.model} 200
* @returns {Array.<Login>} Login * @returns {Array.<Login>} Login
* @headers {integer} 200.X-Rate-Limit * @headers {integer} 200.X-Rate-Limit
@ -79,9 +81,9 @@ const login = async (req: Request, res: Response) => {
/** /**
* @typedef Register * @typedef Register
* @property {string} username.required - * @property {string} username.required - - eg: admin
* @property {string} password.required - * @property {string} password.required - - eg: 123456
* @property {string} verify.required - * @property {integer} verify.required -
*/ */
/** /**
@ -90,6 +92,8 @@ const login = async (req: Request, res: Response) => {
* @param {Register.model} point.body.required - the new point * @param {Register.model} point.body.required - the new point
* @produces application/json application/xml * @produces application/json application/xml
* @consumes application/json application/xml * @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200 * @returns {Response.model} 200
* @returns {Array.<Register>} Register * @returns {Array.<Register>} Register
* @headers {integer} 200.X-Rate-Limit * @headers {integer} 200.X-Rate-Limit
@ -136,7 +140,7 @@ const register = async (req: Request, res: Response) => {
* *
* @route GET /updateList * @route GET /updateList
* @summary * @summary
* @group updateList - * @group
* @returns {object} 200 * @returns {object} 200
* @security JWT * @security JWT
*/ */
@ -149,7 +153,7 @@ const updateList = async (req: Request, res: Response) => {
* *
* @route GET /deleteList * @route GET /deleteList
* @summary * @summary
* @group deleteList - * @group
* @returns {object} 200 * @returns {object} 200
* @security JWT * @security JWT
*/ */
@ -158,23 +162,53 @@ const deleteList = async (req: Request, res: Response) => {
res.json({ code: 1, msg: "成功" }) res.json({ code: 1, msg: "成功" })
} }
/**
* @typedef SearchPage
* @property {integer} page.required - - eg: 1
* @property {integer} size.required - - eg: 5
*/
/** /**
* *
* @route GET /searchPage * @route POST /searchPage
* @param {SearchPage.model} point.body.required - the new point
* @produces application/json application/xml
* @consumes application/json application/xml
* @summary * @summary
* @group searchPage - * @group
* @returns {object} 200 * @returns {Response.model} 200
* @returns {Array.<SearchPage>} SearchPage
* @headers {integer} 200.X-Rate-Limit
* @headers {string} 200.X-Expires-After
* @security JWT * @security JWT
* @returns {Error} default - Unexpected error
*/ */
const searchPage = async (req: Request, res: Response) => { const searchPage = async (req: Request, res: Response) => {
res.json({ code: 1, msg: "成功" }) const { page, size } = req.body
let payload = null
try {
const authorizationHeader = req.get("Authorization")
const accessToken = authorizationHeader.substr("Bearer ".length)
payload = jwt.verify(accessToken, secret.jwtSecret)
} catch (error) {
return res.status(401).end()
}
let sql = 'select * from users limit ' + size + ' offset ' + size * (page - 1)
connection.query(sql, async function (err, data) {
if (err) {
Logger.error(err)
} else {
await res.json({
code: 0,
info: data
})
}
})
} }
/** /**
* @typedef SearchVague * @typedef SearchVague
* @property {string} username.required - * @property {string} username.required - - eg: admin
*/ */
/** /**
@ -183,6 +217,8 @@ const searchPage = async (req: Request, res: Response) => {
* @param {SearchVague.model} point.body.required - the new point * @param {SearchVague.model} point.body.required - the new point
* @produces application/json application/xml * @produces application/json application/xml
* @consumes application/json application/xml * @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200 * @returns {Response.model} 200
* @returns {Array.<SearchVague>} SearchVague * @returns {Array.<SearchVague>} SearchVague
* @headers {integer} 200.X-Rate-Limit * @headers {integer} 200.X-Rate-Limit
@ -235,7 +271,7 @@ const captcha = async (req: Request, res: Response) => {
mathMax: 4, mathMax: 4,
mathOperator: "+" mathOperator: "+"
}) })
generateVerify = create.text generateVerify = Number(create.text)
res.type('svg') // 响应的类型 res.type('svg') // 响应的类型
res.json({ code: 1, msg: create.text, svg: create.data }) res.json({ code: 1, msg: create.text, svg: create.data })
} }

View File

@ -35,8 +35,8 @@ app.get('/deleteList', (req, res) => {
deleteList(req, res) deleteList(req, res)
}) })
app.get('/register', (req, res) => { app.post('/searchPage', (req, res) => {
register(req, res) searchPage(req, res)
}) })
app.post('/searchVague', (req, res) => { app.post('/searchVague', (req, res) => {