-
-
Notifications
You must be signed in to change notification settings - Fork 663
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-service): refactor trigger getter, publish;
- Loading branch information
Showing
9 changed files
with
62 additions
and
76 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DB=laf-app | ||
DB_URI=mongodb://root:password123@localhost:27017/?authSource=admin&replicaSet=laf&writeConcern=majority | ||
DB_POOL_LIMIT=10 | ||
SERVER_SALT=abcdefg1234567!@#$%^&sadfqwef&*^*#!@^ | ||
LOG_LEVEL=debug | ||
ENABLE_CLOUD_FUNCTION_LOG = always | ||
# FILE_SYSTEM_HTTP_CACHE_CONTROL=max-age=60 | ||
# FILE_SYSTEM_ENABLE_UNAUTHORIZED_UPLOAD = off |
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
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
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,37 +1,36 @@ | ||
/* | ||
* @Author: Maslow<wangfugen@126.com> | ||
* @Date: 2021-07-30 10:30:29 | ||
* @LastEditTime: 2021-08-18 16:53:53 | ||
* @LastEditTime: 2021-09-09 23:36:39 | ||
* @Description: | ||
*/ | ||
|
||
import { Trigger } from "cloud-function-engine" | ||
import { Constants } from "../constants" | ||
import { DatabaseAgent } from "../lib/database" | ||
|
||
const db = DatabaseAgent.db | ||
|
||
/** | ||
* Get triggers | ||
* @param status The default value is 1, means will select all enabled triggers | ||
* @returns | ||
*/ | ||
export async function getTriggers(status = 1) { | ||
const r = await db.collection(Constants.trigger_collection) | ||
.where({ status: status }) | ||
.get() | ||
const db = DatabaseAgent.accessor.db | ||
|
||
return r.data | ||
} | ||
const docs = await db.collection(Constants.function_collection) | ||
.find({ | ||
triggers: { $exists: true }, | ||
'triggers.status': status | ||
}, { | ||
projection: { triggers: 1 } | ||
}) | ||
.toArray() | ||
|
||
/** | ||
* Get trigger by id | ||
* @param id | ||
* @returns | ||
*/ | ||
export async function getTriggerById(id: string) { | ||
const r = await db.collection(Constants.trigger_collection) | ||
.where({ _id: id }) | ||
.getOne() | ||
const triggers = [] | ||
for (const func of docs) { | ||
func.triggers.forEach((tri: any) => tri['func_id'] = func._id) | ||
triggers.push(...func.triggers) | ||
} | ||
|
||
return r.data | ||
return triggers.map(data => Trigger.fromJson(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
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
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