Skip to content

Commit

Permalink
Merge pull request #26 from DXY-F2E/dev
Browse files Browse the repository at this point in the history
fix: push last api to history when updated api
  • Loading branch information
wuomzfx committed Dec 14, 2017
2 parents 2e97c6c + 5e011fa commit 70ec82f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "client",
"version": "1.2.0",
"version": "1.2.1",
"description": "api-mocker-client",
"author": "zhangfx",
"license": "GPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/edit/apiInfo/ApiHistory.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<ul class="history">
<li class="record" v-for="record in records" :key="record._id" @click="recover(record)">
<span class="time">{{record.createTime | dateFormat}}</span>
<span class="time">{{record.data.modifiedTime | dateFormat}}</span>
<span class="name">{{record.operatorName}}</span>
<span class="recover">加载</span>
</li>
Expand Down
6 changes: 5 additions & 1 deletion client/src/filter/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import moment from 'moment'
const filter = {}
filter.install = (Vue) => {
Vue.filter('dateFormat', (date, format = 'YYYY-MM-DD H:mm:ss') => moment(date).format(format))
Vue.filter('dateFormat', (date, format = 'YYYY-MM-DD H:mm:ss') => {
// 若是时间戳字符串则转换为时间戳
const d = isFinite(date) ? Number(date) : date
return moment(d).format(format)
})
Vue.filter('reverse', (array) => array.reverse())
}
export default filter
3 changes: 2 additions & 1 deletion server/app/controller/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ApiController extends AbstractController {

delete body._id
delete body.manager
const currentApi = await this.service.api.getById(apiId)
// 使用lean()方法会导致无法设定schema的默认值,minimize: false 为了防止清掉空对象
const resources = (await this.service.api.update(apiId, body)).toObject({ minimize: false })
if (!resources) {
Expand All @@ -91,7 +92,7 @@ class ApiController extends AbstractController {
}
const group = await this.service.group.updateTime(groupId)
// 存下历史记录,并将所有记录返回
resources.history = await this.service.apiHistory.push(resources)
resources.history = await this.service.apiHistory.push(currentApi)
this.notifyApiChange(group, resources, lastModifiedTime)
this.ctx.body = { resources }
}
Expand Down

0 comments on commit 70ec82f

Please sign in to comment.