1
1
/*
2
2
* @Author : Maslow<[email protected] >
3
3
* @Date : 2021-09-05 02:11:39
4
- * @LastEditTime : 2021-10-08 01:44:47
4
+ * @LastEditTime : 2021-11-01 17:02:59
5
5
* @Description :
6
6
*/
7
7
8
8
9
9
import { Request , Response } from 'express'
10
10
import { ObjectId } from 'mongodb'
11
11
import { ApplicationStruct } from '../../api/application'
12
+ import { getFunctionById } from '../../api/function'
12
13
import { checkPermission } from '../../api/permission'
13
14
import { Constants } from '../../constants'
14
15
import { permissions } from '../../constants/permissions'
@@ -99,11 +100,7 @@ export async function handleUpdateFunctionCode(req: Request, res: Response) {
99
100
const body = req . body
100
101
if ( ! body . code ) return res . status ( 422 ) . send ( 'code cannot be empty' )
101
102
102
- const func = await db . collection ( Constants . cn . functions )
103
- . findOne ( {
104
- _id : new ObjectId ( func_id ) ,
105
- appid : app . appid
106
- } )
103
+ const func = await getFunctionById ( app . appid , new ObjectId ( func_id ) )
107
104
108
105
if ( ! func ) return res . status ( 422 ) . send ( 'function not found' )
109
106
@@ -129,13 +126,15 @@ export async function handleUpdateFunctionCode(req: Request, res: Response) {
129
126
}
130
127
131
128
// update cloud function
132
- const ret = await db . collection ( Constants . cn . functions )
129
+ await db . collection ( Constants . cn . functions )
133
130
. updateOne ( {
134
131
_id : new ObjectId ( func_id ) ,
135
132
appid : app . appid
136
133
} , {
137
134
$set : data
138
135
} )
139
136
140
- return res . send ( { data : ret } )
137
+ const doc = await getFunctionById ( app . appid , new ObjectId ( func_id ) )
138
+
139
+ return res . send ( { data : doc } )
141
140
}
0 commit comments