Skip to content

Commit 70ec82f

Browse files
authored
Merge pull request #26 from DXY-F2E/dev
fix: push last api to history when updated api
2 parents 2e97c6c + 5e011fa commit 70ec82f

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "client",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "api-mocker-client",
55
"author": "zhangfx",
66
"license": "GPL-3.0",

client/src/components/edit/apiInfo/ApiHistory.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<ul class="history">
33
<li class="record" v-for="record in records" :key="record._id" @click="recover(record)">
4-
<span class="time">{{record.createTime | dateFormat}}</span>
4+
<span class="time">{{record.data.modifiedTime | dateFormat}}</span>
55
<span class="name">{{record.operatorName}}</span>
66
<span class="recover">加载</span>
77
</li>

client/src/filter/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import moment from 'moment'
22
const filter = {}
33
filter.install = (Vue) => {
4-
Vue.filter('dateFormat', (date, format = 'YYYY-MM-DD H:mm:ss') => moment(date).format(format))
4+
Vue.filter('dateFormat', (date, format = 'YYYY-MM-DD H:mm:ss') => {
5+
// 若是时间戳字符串则转换为时间戳
6+
const d = isFinite(date) ? Number(date) : date
7+
return moment(d).format(format)
8+
})
59
Vue.filter('reverse', (array) => array.reverse())
610
}
711
export default filter

server/app/controller/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ApiController extends AbstractController {
8181

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

0 commit comments

Comments
 (0)