分页查询添加

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",
"lockfileVersion": 1,
"requires": true,
@ -3749,4 +3749,4 @@
}
}
}
}
}

View File

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

View File

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

View File

@ -12,14 +12,7 @@ export interface dataModel {
}
// 保存验证码
let generateVerify: number | string
/**
* @typedef Login
* @property {string} username.required -
* @property {string} password.required -
* @property {string} verify.required -
*/
let generateVerify: number
/**
* @typedef Error
@ -31,12 +24,21 @@ let generateVerify: number | string
* @property {[integer]} code
*/
/**
* @typedef Login
* @property {string} username.required - - eg: admin
* @property {string} password.required - - eg: 123456
* @property {integer} verify.required -
*/
/**
*
* @route POST /login
* @param {Login.model} point.body.required - the new point
* @produces application/json application/xml
* @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200
* @returns {Array.<Login>} Login
* @headers {integer} 200.X-Rate-Limit
@ -79,9 +81,9 @@ const login = async (req: Request, res: Response) => {
/**
* @typedef Register
* @property {string} username.required -
* @property {string} password.required -
* @property {string} verify.required -
* @property {string} username.required - - eg: admin
* @property {string} password.required - - eg: 123456
* @property {integer} verify.required -
*/
/**
@ -90,6 +92,8 @@ const login = async (req: Request, res: Response) => {
* @param {Register.model} point.body.required - the new point
* @produces application/json application/xml
* @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200
* @returns {Array.<Register>} Register
* @headers {integer} 200.X-Rate-Limit
@ -136,7 +140,7 @@ const register = async (req: Request, res: Response) => {
*
* @route GET /updateList
* @summary
* @group updateList -
* @group
* @returns {object} 200
* @security JWT
*/
@ -149,7 +153,7 @@ const updateList = async (req: Request, res: Response) => {
*
* @route GET /deleteList
* @summary
* @group deleteList -
* @group
* @returns {object} 200
* @security JWT
*/
@ -158,23 +162,53 @@ const deleteList = async (req: Request, res: Response) => {
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
* @group searchPage -
* @returns {object} 200
* @group
* @returns {Response.model} 200
* @returns {Array.<SearchPage>} SearchPage
* @headers {integer} 200.X-Rate-Limit
* @headers {string} 200.X-Expires-After
* @security JWT
* @returns {Error} default - Unexpected error
*/
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
* @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
* @produces application/json application/xml
* @consumes application/json application/xml
* @summary
* @group
* @returns {Response.model} 200
* @returns {Array.<SearchVague>} SearchVague
* @headers {integer} 200.X-Rate-Limit
@ -235,7 +271,7 @@ const captcha = async (req: Request, res: Response) => {
mathMax: 4,
mathOperator: "+"
})
generateVerify = create.text
generateVerify = Number(create.text)
res.type('svg') // 响应的类型
res.json({ code: 1, msg: create.text, svg: create.data })
}

View File

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