Skip to content

Commit

Permalink
feat: 喜欢的卡片可以查看详情了
Browse files Browse the repository at this point in the history
  • Loading branch information
Honye committed May 15, 2022
1 parent b20690c commit b9ee97d
Show file tree
Hide file tree
Showing 6 changed files with 952 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cloudfunctions/getCard/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"permissions": {
"openapi": [
]
}
}
36 changes: 36 additions & 0 deletions cloudfunctions/getCard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const cloud = require('wx-server-sdk');

cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV,
});

const db = cloud.database();
const _ = db.command;
const $ = _.aggregate;

exports.main = async (event, context) => {
const wxContext = cloud.getWXContext();
const openid = wxContext.OPENID;
const _id = event._id;

const promiseCard = db.collection('cards').doc(_id).get().then(({ data }) => data);
const promiseLiked =
db.collection('card_like')
.where({ card_id: _id, state: 1 })
.count()
.then(({ total }) => total);
const promiseState =
db.collection('card_like')
.where({ card_id: _id, openid })
.limit(1)
.get()
.then(({ data }) => data[0] && data[0].state);

const [card, liked, state] = await Promise.all([promiseCard, promiseLiked, promiseState]);

return {
...card,
like_count: liked,
like_state: state,
};
}
14 changes: 14 additions & 0 deletions cloudfunctions/getCard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "getCard",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.6.1"
}
}
Loading

0 comments on commit b9ee97d

Please sign in to comment.