From 0fd798c64b63981964b6911bb0e22b1a6019b32e Mon Sep 17 00:00:00 2001 From: "huoyong.msb" Date: Fri, 19 Feb 2021 17:41:59 +0800 Subject: [PATCH] feat: fix new version ts errors --- src/routes/account.ts | 2 +- src/routes/export.ts | 4 ++-- src/routes/organization.ts | 4 ++-- src/routes/repository.ts | 34 +++++++++++++++++----------------- src/routes/router.ts | 3 ++- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/routes/account.ts b/src/routes/account.ts index abcffe5..08c796c 100644 --- a/src/routes/account.ts +++ b/src/routes/account.ts @@ -58,7 +58,7 @@ router.get('/account/list', isLoggedIn, async (ctx) => { } let options = { where } let total = await User.count(options) - let limit = Math.min(ctx.query.limit ?? 10, 100) + let limit = Math.min(+ctx.query.limit ?? 10, 100) let pagination = new Pagination(total, ctx.query.cursor || 1, limit) ctx.body = { data: await User.findAll({ diff --git a/src/routes/export.ts b/src/routes/export.ts index 2b4d2f6..67ffd68 100644 --- a/src/routes/export.ts +++ b/src/routes/export.ts @@ -52,7 +52,7 @@ router.get('/export/markdown', async ctx => { if (!(repoId > 0)) { ctx.data = COMMON_ERROR_RES.ERROR_PARAMS } - ctx.body = await MarkdownService.export(repoId, ctx.query.origin) + ctx.body = await MarkdownService.export(repoId, ctx.query.origin as string) }) router.get('/export/docx', async ctx => { @@ -71,7 +71,7 @@ router.get('/export/docx', async ctx => { ctx.data = COMMON_ERROR_RES.ERROR_PARAMS } const repository = await Repository.findByPk(repoId) - ctx.body = await DocxService.export(repoId, ctx.query.origin) + ctx.body = await DocxService.export(repoId, ctx.query.origin as string) ctx.set( 'Content-Disposition', `attachment; filename="RAP-${encodeURI( diff --git a/src/routes/organization.ts b/src/routes/organization.ts index 172b0bc..48e8f6c 100644 --- a/src/routes/organization.ts +++ b/src/routes/organization.ts @@ -39,7 +39,7 @@ router.get('/organization/list', async (ctx) => { const { name } = ctx.query const total = await OrganizationService.getAllOrganizationIdListNum(curUserId) const pagination = new Pagination(total, ctx.query.cursor || 1, ctx.query.limit || 100) - const organizationIds = await OrganizationService.getAllOrganizationIdList(curUserId, pagination, name) + const organizationIds = await OrganizationService.getAllOrganizationIdList(curUserId, pagination, name as string) const options: FindOptions = { where: { id: { @@ -117,7 +117,7 @@ router.get('/organization/get', async (ctx) => { ctx.body = COMMON_ERROR_RES.ACCESS_DENY return } - const organization = await Organization.findByPk(ctx.query.id, { + const organization = await Organization.findByPk(+ctx.query.id, { attributes: { exclude: [] }, include: [QueryInclude.Creator, QueryInclude.Owner, QueryInclude.Members], } as any) diff --git a/src/routes/repository.ts b/src/routes/repository.ts index 6871c6d..def0a29 100644 --- a/src/routes/repository.ts +++ b/src/routes/repository.ts @@ -52,7 +52,7 @@ router.get('/repository/list', async (ctx) => { let { name, user, organization } = ctx.query if (+organization > 0) { - const access = await AccessUtils.canUserAccess(ACCESS_TYPE.ORGANIZATION_GET, ctx.session.id, organization) + const access = await AccessUtils.canUserAccess(ACCESS_TYPE.ORGANIZATION_GET, ctx.session.id, +organization) if (access === false) { ctx.body = { @@ -82,7 +82,7 @@ router.get('/repository/list', async (ctx) => { QueryInclude.Locker ] }) - let limit = Math.min(ctx.query.limit ?? 10, 100) + let limit = Math.min(+ctx.query.limit ?? 10, 100) let pagination = new Pagination(total, ctx.query.cursor || 1, limit) let repositories = await Repository.findAll({ where, @@ -197,8 +197,8 @@ router.get('/repository/get', async (ctx) => { const access = await AccessUtils.canUserAccess( ACCESS_TYPE.REPOSITORY_GET, ctx.session.id, - ctx.query.id, - ctx.query.token + +ctx.query.id, + ctx.query.token as string ) if (access === false) { ctx.body = { @@ -211,15 +211,15 @@ router.get('/repository/get', async (ctx) => { const canUserEdit = await AccessUtils.canUserAccess( ACCESS_TYPE.REPOSITORY_SET, ctx.session.id, - ctx.query.id, - ctx.query.token, + +ctx.query.id, + ctx.query.token as string, ) let repository: Partial & { canUserEdit: boolean } // 分开查询减少查询时间 let [repositoryOmitModules, repositoryModules] = await Promise.all([ - Repository.findByPk(ctx.query.id, { + Repository.findByPk(+ctx.query.id, { attributes: { exclude: [] }, include: [ QueryInclude.Creator, @@ -230,7 +230,7 @@ router.get('/repository/get', async (ctx) => { QueryInclude.Collaborators, ], }), - Repository.findByPk(ctx.query.id, { + Repository.findByPk(+ctx.query.id, { attributes: { exclude: [] }, include: [ excludeProperty @@ -476,7 +476,7 @@ router.get('/module/list', async (ctx) => { router.get('/module/get', async (ctx) => { ctx.body = { - data: await Module.findByPk(ctx.query.id, { + data: await Module.findByPk(+ctx.query.id, { attributes: { exclude: [] } }) } @@ -563,7 +563,7 @@ router.get('/module/remove', isLoggedIn, async (ctx, next) => { return next() }, async (ctx) => { if (ctx.body.data === 0) return - let { id } = ctx.query + const id = +ctx.query.id let mod = await Module.findByPk(id, { paranoid: false }) await Logger.create({ userId: ctx.session.id, @@ -648,9 +648,9 @@ router.post('/repository/defaultVal/update/:id', async (ctx) => { }) router.get('/interface/get', async (ctx) => { - let { id } = ctx.query + const id = +ctx.query.id - if (id === undefined || id === '') { + if (id === undefined || !id) { ctx.body = { isOk: false, errMsg: '请输入参数id' @@ -784,7 +784,7 @@ router.post('/interface/move', isLoggedIn, async ctx => { }) router.get('/interface/remove', async (ctx, next) => { - let { id } = ctx.query + let id = +ctx.query.id if (!await AccessUtils.canUserAccess(ACCESS_TYPE.INTERFACE_SET, ctx.session.id, +id)) { ctx.body = Consts.COMMON_ERROR_RES.ACCESS_DENY return @@ -806,7 +806,7 @@ router.get('/interface/remove', async (ctx, next) => { return next() }, async (ctx) => { if (ctx.body.data === 0) return - let { id } = ctx.query + const id = +ctx.query.id let itf = await Interface.findByPk(id, { paranoid: false }) await Logger.create({ userId: ctx.session.id, @@ -928,7 +928,7 @@ router.get('/property/list', async (ctx) => { }) router.get('/property/get', async (ctx) => { - let { id } = ctx.query + const id = +ctx.query.id ctx.body = { data: await Property.findByPk(id, { attributes: { exclude: [] } @@ -1098,7 +1098,7 @@ router.post('/properties/update', isLoggedIn, async (ctx, next) => { return next() }, async (ctx) => { if (ctx.body.data === 0) return - let itf = await Interface.findByPk(ctx.query.itf, { + let itf = await Interface.findByPk(ctx.query.itf as string, { attributes: { exclude: [] } }) await Logger.create({ @@ -1112,7 +1112,7 @@ router.post('/properties/update', isLoggedIn, async (ctx, next) => { router.get('/property/remove', isLoggedIn, async (ctx) => { let { id } = ctx.query - if (!await AccessUtils.canUserAccess(ACCESS_TYPE.PROPERTY_SET, ctx.session.id, id)) { + if (!await AccessUtils.canUserAccess(ACCESS_TYPE.PROPERTY_SET, ctx.session.id, +id)) { ctx.body = Consts.COMMON_ERROR_RES.ACCESS_DENY return } diff --git a/src/routes/router.ts b/src/routes/router.ts index f2e61e9..0f2c364 100644 --- a/src/routes/router.ts +++ b/src/routes/router.ts @@ -28,7 +28,8 @@ router.get('/test/test.status', (ctx) => { // proxy router.get('/proxy', async(ctx) => { let { target } = ctx.query - let json = await fetch(target).then(res => res.json()) + console.log(` <=> ${target}`) + let json = await fetch(target as string).then(res => res.json()) ctx.type = 'json' ctx.body = json })