-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(system-server): fix get function error;
- Loading branch information
Showing
3 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
/* | ||
* @Author: Maslow<[email protected]> | ||
* @Date: 2021-08-30 16:51:19 | ||
* @LastEditTime: 2021-09-02 16:34:40 | ||
* @LastEditTime: 2021-09-03 20:30:19 | ||
* @Description: | ||
*/ | ||
|
||
import { CloudFunctionStruct } from 'cloud-function-engine' | ||
import { Request, Response } from 'express' | ||
import { ApplicationStruct } from '../../api/application' | ||
import { checkPermission } from '../../api/permission' | ||
|
@@ -72,4 +73,31 @@ export async function handleGetFunctions(req: Request, res: Response) { | |
limit: limit, | ||
page | ||
}) | ||
} | ||
|
||
|
||
/** | ||
* Get a function by id | ||
*/ | ||
export async function handleGetFunctionById(req: Request, res: Response) { | ||
const db = DatabaseAgent.sys_db | ||
const app: ApplicationStruct = req['parsed-app'] | ||
const func_id = req.params.func_id | ||
|
||
// check permission | ||
const code = await checkPermission(req['auth']?.uid, FUNCTION_READ.name, app) | ||
if (code) { | ||
return res.status(code).send() | ||
} | ||
|
||
const coll = db.collection(Constants.cn.functions) | ||
|
||
// do db query | ||
const ret = await coll | ||
.where({ _id: func_id }) | ||
.getOne<CloudFunctionStruct>() | ||
|
||
return res.send({ | ||
data: ret.data | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
/* | ||
* @Author: Maslow<[email protected]> | ||
* @Date: 2021-08-29 11:35:05 | ||
* @LastEditTime: 2021-09-01 13:07:39 | ||
* @LastEditTime: 2021-09-03 20:25:43 | ||
* @Description: | ||
*/ | ||
|
||
import { Router } from "express" | ||
import { handleCreateFunction } from "./create" | ||
import { handleGetFunctions } from "./get" | ||
import { handleGetFunctionById, handleGetFunctions } from "./get" | ||
import { handlePublishFunctions } from "./publish" | ||
import { handlePublishTriggers } from "./trigger" | ||
|
||
|
@@ -19,6 +19,11 @@ export const FunctionRouter = Router() | |
*/ | ||
FunctionRouter.get('/', handleGetFunctions) | ||
|
||
/** | ||
* Get a function by id of an application | ||
*/ | ||
FunctionRouter.get('/:func_id', handleGetFunctionById) | ||
|
||
/** | ||
* Create a function | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* | ||
* @Author: Maslow<[email protected]> | ||
* @Date: 2021-08-30 16:51:19 | ||
* @LastEditTime: 2021-09-01 11:18:22 | ||
* @LastEditTime: 2021-09-03 20:02:25 | ||
* @Description: | ||
*/ | ||
|
||
import { Request, Response } from 'express' | ||
import { getApplicationByAppid } from '../../api/application' | ||
import { ApplicationStruct } from '../../api/application' | ||
import { publishFunctions } from '../../api/function' | ||
import { checkPermission } from '../../api/permission' | ||
import Config from '../../config' | ||
|
@@ -20,20 +20,16 @@ const { PUBLISH_FUNCTION } = permissions | |
* Publish functions | ||
*/ | ||
export async function handlePublishFunctions(req: Request, res: Response) { | ||
const appid = req.params.appid | ||
const app = await getApplicationByAppid(appid) | ||
if (!app) { | ||
return res.status(422).send('app not found') | ||
} | ||
const uid = req['auth']?.uid | ||
const app: ApplicationStruct = req['parsed-app'] | ||
|
||
// check permission | ||
const code = await checkPermission(req['auth']?.uid, PUBLISH_FUNCTION.name, app) | ||
const code = await checkPermission(uid, PUBLISH_FUNCTION.name, app) | ||
if (code) { | ||
return res.status(code).send() | ||
} | ||
|
||
try { | ||
|
||
await publishFunctions(app) | ||
|
||
return res.send({ | ||
|