fix: 修复评论/资料/导航胶囊/宠物档案/定位等多处问题,补全相关云函数
- 新增 addComment/getComments/getFollowList/followUser/getUser/updateProfile/updatePet/deletePet 云函数并完成部署 - 统一通过 app.globalData.navBarInfo 避让系统胶囊按钮(编辑资料/编辑宠物等页面保存按钮被遮挡问题) - 编辑资料页所在城市改为省份 picker 选择 - 修复"我的"页动态为空(getUserPosts 应传 openid 而非数据库 _id) - 重构编辑宠物页:品种改用 picker 滚轮(替代有数量上限的 actionSheet),标签改用 selectedTagSet 映射 + 自定义标签输入(5字以内、仅中英文/数字、最多8个) - 接通宠物保存/删除真实云函数调用并同步本地缓存 - 移除 feed 页对不存在的 getStories 云函数调用,修复模拟器卡死 - 移除 post 页对不存在的 wx.reverseGeocoder API 的调用 - 统一扩展 AppGlobalData 类型并修正所有 getApp 调用的泛型,解决 TS 报错
This commit is contained in:
40
cloudfunctions/followUser/index.js
Normal file
40
cloudfunctions/followUser/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const cloud = require('wx-server-sdk')
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
|
||||
const db = cloud.database()
|
||||
const _ = db.command
|
||||
|
||||
exports.main = async (event, context) => {
|
||||
const { OPENID } = cloud.getWXContext()
|
||||
const { targetId } = event
|
||||
if (!targetId || targetId === OPENID) return { code: -1, message: '参数错误' }
|
||||
|
||||
try {
|
||||
const existRes = await db.collection('follows')
|
||||
.where({ followerId: OPENID, followeeId: targetId })
|
||||
.count()
|
||||
|
||||
if (existRes.total > 0) {
|
||||
// unfollow
|
||||
await db.collection('follows')
|
||||
.where({ followerId: OPENID, followeeId: targetId })
|
||||
.remove()
|
||||
await Promise.all([
|
||||
db.collection('users').where({ openid: OPENID }).update({ data: { 'stats.friends': _.inc(-1) } }),
|
||||
db.collection('users').where({ openid: targetId }).update({ data: { 'stats.friends': _.inc(-1) } }),
|
||||
])
|
||||
return { code: 0, data: { following: false } }
|
||||
} else {
|
||||
// follow
|
||||
await db.collection('follows').add({
|
||||
data: { followerId: OPENID, followeeId: targetId, createdAt: db.serverDate() },
|
||||
})
|
||||
await Promise.all([
|
||||
db.collection('users').where({ openid: OPENID }).update({ data: { 'stats.friends': _.inc(1) } }),
|
||||
db.collection('users').where({ openid: targetId }).update({ data: { 'stats.friends': _.inc(1) } }),
|
||||
])
|
||||
return { code: 0, data: { following: true } }
|
||||
}
|
||||
} catch (e) {
|
||||
return { code: -1, message: e.message }
|
||||
}
|
||||
}
|
||||
1
cloudfunctions/followUser/package.json
Normal file
1
cloudfunctions/followUser/package.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "name": "followUser", "version": "1.0.0", "main": "index.js", "dependencies": { "wx-server-sdk": "~2.1.2" } }
|
||||
Reference in New Issue
Block a user