重构代码, 移除一些warning
This commit is contained in:
parent
9908f376a3
commit
a1fa453cd6
@ -1,5 +1,5 @@
|
|||||||
import BaseController from '../../common/base.controller'
|
import BaseController from '../../common/base.controller'
|
||||||
import { permission, role, router } from '../../decorators/router'
|
import { permission, router } from '../../decorators/router'
|
||||||
import { Shop } from '../../models/shop/Shop'
|
import { Shop } from '../../models/shop/Shop'
|
||||||
import { ZError } from '../../common/ZError'
|
import { ZError } from '../../common/ZError'
|
||||||
import { Game } from '../../models/content/Game'
|
import { Game } from '../../models/content/Game'
|
||||||
@ -8,7 +8,7 @@ class ShopController extends BaseController {
|
|||||||
|
|
||||||
@permission(['shop:read', 'shopman:read'])
|
@permission(['shop:read', 'shopman:read'])
|
||||||
@router('post /shops')
|
@router('post /shops')
|
||||||
async shopList(req, res) {
|
async shopList(req) {
|
||||||
let { start, limit, page } = req.params
|
let { start, limit, page } = req.params
|
||||||
limit = +limit || 10
|
limit = +limit || 10
|
||||||
start = +start || (+page - 1) * limit|| 0
|
start = +start || (+page - 1) * limit|| 0
|
||||||
@ -151,7 +151,7 @@ class ShopController extends BaseController {
|
|||||||
}
|
}
|
||||||
@permission('shop:edit')
|
@permission('shop:edit')
|
||||||
@router('post /shop/save_qtype')
|
@router('post /shop/save_qtype')
|
||||||
async updateQTypes(req, res) {
|
async updateQTypes(req) {
|
||||||
let { shopid, qtypes } = req.params
|
let { shopid, qtypes } = req.params
|
||||||
if (!shopid) {
|
if (!shopid) {
|
||||||
throw new ZError(11, 'params mismatch')
|
throw new ZError(11, 'params mismatch')
|
||||||
|
@ -13,40 +13,37 @@ class ShopController extends BaseController {
|
|||||||
* lng: 经度
|
* lng: 经度
|
||||||
* lat: 纬度
|
* lat: 纬度
|
||||||
* distance: 多少半径范围内, 单位: 米
|
* distance: 多少半径范围内, 单位: 米
|
||||||
* @param res
|
|
||||||
* @return {Promise<any>}
|
|
||||||
*/
|
*/
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /weapp/nearme')
|
@router('post /weapp/nearme')
|
||||||
async shopNearby(req, res) {
|
async shopNearby(req) {
|
||||||
let { lng, lat, distance } = req.params
|
let { lng, lat, distance } = req.params
|
||||||
let queryParam = {
|
let queryParam = {
|
||||||
location: {
|
location: {
|
||||||
$nearSphere: {
|
$nearSphere: {
|
||||||
$geometry: {
|
$geometry: {
|
||||||
type: "Point",
|
type: 'Point',
|
||||||
coordinates: [lng, lat]
|
coordinates: [lng, lat]
|
||||||
},
|
},
|
||||||
$maxDistance: distance
|
$maxDistance: distance
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
deleted: false
|
deleted: false
|
||||||
}
|
}
|
||||||
|
|
||||||
let records = await Shop.find(queryParam)
|
let records = await Shop.find(queryParam)
|
||||||
let result = records.map(o => {
|
return records.map(o => {
|
||||||
return {
|
return {
|
||||||
id: o.id,
|
id: o.id,
|
||||||
name: o.showName,
|
name: o.showName,
|
||||||
address: o.address
|
address: o.address
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /weapp/shopList')
|
@router('post /weapp/shopList')
|
||||||
async shopList(req, res) {
|
async shopList(req) {
|
||||||
let { start, limit } = req.params
|
let { start, limit } = req.params
|
||||||
limit = +limit || 10
|
limit = +limit || 10
|
||||||
start = +start || 0
|
start = +start || 0
|
||||||
@ -75,13 +72,10 @@ class ShopController extends BaseController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO:: 获取某店铺实时的活动信息
|
* TODO:: 获取某店铺实时的活动信息
|
||||||
* @param req
|
|
||||||
* @param res
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
*/
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('get /weapp/act/:sid')
|
@router('get /weapp/act/:sid')
|
||||||
async shopActivity(req, res) {
|
async shopActivity(req) {
|
||||||
let { sid } = req.params
|
let { sid } = req.params
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
@ -89,7 +83,7 @@ class ShopController extends BaseController {
|
|||||||
|
|
||||||
@role('anon')
|
@role('anon')
|
||||||
@router('post /api/:accountid/shop')
|
@router('post /api/:accountid/shop')
|
||||||
async shopInfo(req, res) {
|
async shopInfo(req) {
|
||||||
let { sid } = req.params
|
let { sid } = req.params
|
||||||
if (!sid || !validShopId(sid)) {
|
if (!sid || !validShopId(sid)) {
|
||||||
throw new ZError(10, '没有店铺id或者店铺id格式不正确, 测试使用: 607ff59d4a4e16687a3b7079')
|
throw new ZError(10, '没有店铺id或者店铺id格式不正确, 测试使用: 607ff59d4a4e16687a3b7079')
|
||||||
@ -104,7 +98,13 @@ class ShopController extends BaseController {
|
|||||||
rspData.area = shop.areaStr
|
rspData.area = shop.areaStr
|
||||||
rspData.logo = shop.logo
|
rspData.logo = shop.logo
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
let exams = await ShopExam.find({shop: shop.id, beginTime: {$lte: now}, endTime: {$gte: now}, active: true, deleted: false})
|
let exams = await ShopExam.find({
|
||||||
|
shop: shop.id,
|
||||||
|
beginTime: { $lte: now },
|
||||||
|
endTime: { $gte: now },
|
||||||
|
active: true,
|
||||||
|
deleted: false
|
||||||
|
})
|
||||||
if (exams && exams.length > 0) {
|
if (exams && exams.length > 0) {
|
||||||
let datas: any = []
|
let datas: any = []
|
||||||
for (let exam of exams) {
|
for (let exam of exams) {
|
||||||
@ -112,8 +112,7 @@ class ShopController extends BaseController {
|
|||||||
}
|
}
|
||||||
rspData.exams = datas
|
rspData.exams = datas
|
||||||
}
|
}
|
||||||
let activity = await ShopActivity.getActivityOne(shop.id)
|
rspData.activity = await ShopActivity.getActivityOne(shop.id)
|
||||||
rspData.activity = activity
|
|
||||||
return rspData
|
return rspData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import 'reflect-metadata'
|
import 'reflect-metadata'
|
||||||
import { singleton } from './singleton'
|
import { singleton } from './singleton'
|
||||||
|
|
||||||
const noJsonMetadataKey = ('noJsonSet')
|
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
export class NoJsonClass {
|
export class NoJsonClass {
|
||||||
private noJsonPropSet: Set<string> = new Set()
|
private noJsonPropSet: Set<string> = new Set()
|
||||||
|
@ -15,8 +15,6 @@ const saveExcludeKeys = ['createdAt', 'updatedAt', '__v', '_id']
|
|||||||
@plugin(findOrCreate)
|
@plugin(findOrCreate)
|
||||||
export abstract class BaseModule extends FindOrCreate {
|
export abstract class BaseModule extends FindOrCreate {
|
||||||
static db: Connection
|
static db: Connection
|
||||||
static noJsonSet: Set<string> = new Set()
|
|
||||||
|
|
||||||
|
|
||||||
public updateFromReq(data: any) {
|
public updateFromReq(data: any) {
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
import {
|
import { getModelForClass, modelOptions, prop } from '@typegoose/typegoose'
|
||||||
getModelForClass,
|
|
||||||
index,
|
|
||||||
modelOptions,
|
|
||||||
prop
|
|
||||||
} from '@typegoose/typegoose'
|
|
||||||
import { dbconn } from 'decorators/dbconn'
|
import { dbconn } from 'decorators/dbconn'
|
||||||
import { BaseModule } from '../Base'
|
import { BaseModule } from '../Base'
|
||||||
|
|
||||||
@ -22,7 +17,7 @@ export class AdminPermissionClass extends BaseModule {
|
|||||||
@prop()
|
@prop()
|
||||||
public name: string
|
public name: string
|
||||||
|
|
||||||
@prop()
|
@prop({ type: () => [String] })
|
||||||
public actions: string[]
|
public actions: string[]
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,18 +143,12 @@ class ShopClass extends BaseModule {
|
|||||||
|
|
||||||
|
|
||||||
public static parseQueryParam(params) {
|
public static parseQueryParam(params) {
|
||||||
let {key, timeBegin, timeEnd, publish} = params
|
let options: any = {
|
||||||
let opt: any = {deleted: false, show: true, publish: true}
|
opt: {deleted: false, show: true, publish: true},
|
||||||
if (key) {
|
matchKey: 'name'
|
||||||
opt.name = {$regex: key, $options: 'i'}
|
|
||||||
}
|
|
||||||
if (timeBegin && !timeEnd) {
|
|
||||||
opt.createdAt = {$gte: timeBegin};
|
|
||||||
} else if (timeBegin && timeEnd) {
|
|
||||||
opt['$and'] = [{createdAt: {$gte: timeBegin}}, {createdAt: {$lte: timeEnd}}];
|
|
||||||
} else if (!timeBegin && timeEnd) {
|
|
||||||
opt.createdAt = {$lte: timeEnd};
|
|
||||||
}
|
}
|
||||||
|
let { opt, sort } = super.parseQueryParam(params, options)
|
||||||
|
let { publish } = params
|
||||||
if (publish !== undefined) {
|
if (publish !== undefined) {
|
||||||
if (typeof publish === 'boolean') {
|
if (typeof publish === 'boolean') {
|
||||||
opt.publish = publish
|
opt.publish = publish
|
||||||
@ -169,7 +163,6 @@ class ShopClass extends BaseModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let sort = {_id: -1}
|
|
||||||
return { opt, sort }
|
return { opt, sort }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user