You need to sign in or sign up before continuing.
提交 98c8a9a7 编写于 作者: M MicroMilo

Merge branch 'backend' of https://gitcode.net/qq_50679803/great-teamwork into backend

...@@ -64,7 +64,7 @@ function getSystemTime() { ...@@ -64,7 +64,7 @@ function getSystemTime() {
// 获取日期(1-31) // 获取日期(1-31)
var date = time.getDate(); var date = time.getDate();
// 获取小时 // 获取小时
var h = time.getHours(); var h = time.getHours() + 8;
h = h < 10 ? '0' + h : h; h = h < 10 ? '0' + h : h;
// 获取分钟 // 获取分钟
var m = time.getMinutes(); var m = time.getMinutes();
......
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
const comment_table = db.collection("mustgo-post-comment")
const like_table = db.collection("mustgo-post-like")
const res = await post_table.doc(event.postId) .remove()
const res2 = await comment_table.where({post_id:event.postId}).remove()
const res3 = await like_table.where({post_id:event.postId}).remove()
if(res.affectedDocs == 1){
return{
code:200,
message:"删除帖子成功",
data:{}
}
}
return{
code:400,
message:"删除帖子失败",
data:{}
}
};
{
"name": "fe-college-deletePost",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const like_table = db.collection("mustgo-comment-like")
const comment_table = db.collection("mustgo-post-comment")
const islike = await like_table.where({
comment_id:event.commentId,
owner_id:event.userId
}).get()
if(islike.affectedDocs == 0){
const res = await like_table.add({
comment_id:event.commentId,
owner_id:event.userId
})
const comment = await comment_table.where({
_id:event.commentId
}).get()
var like
if(comment.affectedDocs == 1){
like = comment.data[0]["likes"] + 1
const res2 = await comment_table.doc(event.commentId).update({
likes:like
})
return{
code:200,
message:"点赞评论成功",
data:{
commentId:comment.data[0]["_id"],
newlikes:like
}
}
}
}
else{
const res3 = await like_table.where({
comment_id:event.commentId,
owner_id:event.userId
}).remove()
const comment2 = await comment_table.where({
_id:event.commentId
}).get()
var like2
if(comment2.affectedDocs == 1){
like2 = comment2.data[0]["likes"] - 1
const res4 = await comment_table.doc(event.commentId).update({
likes:like2
})
return{
code:200,
message:"取消点赞评论成功",
data:{
commentId:comment2.data[0]["_id"],
newlikes:like2
}
}
}
}
return{
code:400,
message:"点赞评论成功",
data:{}
}
};
{
"name": "fe-college-likeComment",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
...@@ -10,8 +10,9 @@ exports.main = async (event, context) => { ...@@ -10,8 +10,9 @@ exports.main = async (event, context) => {
const islike = await like_table.where({ const islike = await like_table.where({
post_id:event.postId, post_id:event.postId,
user_id:event.userId owner_id:event.userId
}).get() }).get()
if(islike.affectedDocs == 0 && res.affectedDocs == 1){ if(islike.affectedDocs == 0 && res.affectedDocs == 1){
const res2 = await post_table.doc(event.postId).update({ const res2 = await post_table.doc(event.postId).update({
likes:res.data[0]["likes"] + 1 likes:res.data[0]["likes"] + 1
...@@ -19,7 +20,7 @@ exports.main = async (event, context) => { ...@@ -19,7 +20,7 @@ exports.main = async (event, context) => {
const res3 = await like_table.add({ const res3 = await like_table.add({
post_id:event.postId, post_id:event.postId,
user_id:event.userId owner_id:event.userId
}) })
return { return {
...@@ -31,22 +32,22 @@ exports.main = async (event, context) => { ...@@ -31,22 +32,22 @@ exports.main = async (event, context) => {
} }
} }
} }
else if(islike.affectedDocs == 1 && res.affectedDocs == 1){ else if(islike.affectedDocs == 1 && res.affectedDocs == 1){
const res4 = await post_table.doc(event.postId).update({ const res4 = await post_table.doc(event.postId).update({
likes:res.data[0]["likes"] - 1, likes:res.data[0]["likes"] - 1,
}) })
like_table.doc(islike.data[0]["_id"]).remove().then((res5) => { const deleteLike = await like_table.doc(islike.data[0]["_id"]).remove()
console.log("删除成功"); if(deleteLike.deleted === 1){
}) return {
code: 200,
return { message: "取消点赞帖子成功",
code: 200, data: {
message: "取消点赞帖子成功", postId:res.data[0]["_id"],
data: { newlikes:res.data[0]["likes"] - 1
postId:res.data[0]["_id"], }
newlikes:res.data[0]["likes"] - 1 }
}
} }
} }
......
...@@ -39,7 +39,7 @@ function getSystemTime() { ...@@ -39,7 +39,7 @@ function getSystemTime() {
// 获取日期(1-31) // 获取日期(1-31)
var date = time.getDate(); var date = time.getDate();
// 获取小时 // 获取小时
var h = time.getHours(); var h = time.getHours() + 8;
h = h < 10 ? '0' + h : h; h = h < 10 ? '0' + h : h;
// 获取分钟 // 获取分钟
var m = time.getMinutes(); var m = time.getMinutes();
......
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
const comment_table = db.collection("mustgo-post-comment")
const user_table = db.collection("mustgo-user")
const res = await post_table.where({
_id:event.postId
}).get()
if(res.affectedDocs == 1){
const res2 = await comment_table.where({
post_id:event.postId
}).get()
var arr = new Array
var list = new Array
arr = res2.data
if(res2.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){
const res3 = await user_table.where({
_id:arr[i]["owner_id"]
}).get()
if(res3.affectedDocs == 1){
var comment ={
commenterIcon:res3.data[0]["icon"],
commenterName:res3.data[0]["name"],
commentContent:arr[i]["content"],
commentDatetime:arr[i]["date"],
commentLikes:arr[i]["likes"]
}
list.push(comment)
}
}
}
const res4 = await user_table.where({
_id:res.data[0]["owner_id"]
}).get()
if(res4.affectedDocs == 1){
return{
code:200,
message:"成功返回我的帖子详情",
data:{
ownername:res4.data[0]["name"],
ownerIcon:res4.data[0]["icon"],
datetime:res.data[0]["date"],
content:res.data[0]["content"],
pictureList:res.data[0]["url"],
likes:res.data[0]["likes"],
commentNum:res.data[0]["comment_num"],
commentList:list
}
}
}
}
return{
code:400,
message:"查看我的帖子详情失败",
data:{}
}
};
{
"name": "fe-college-myPostDetail",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
const user_table = db.collection("mustgo-user")
const like_table = db.collection("mustgo-post-like")
const res = await post_table.orderBy("date","desc").where({
owner_id:event.userId
}).get()
var arr = new Array
var list = new Array
arr = res.data
if(res.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){
const res2 = await user_table.where({
_id:event.userId
}).get()
var like = 0
const res3 = await like_table.where({
owner_id:event.userId,
post_id:arr[i]["_id"]
}).get()
if(res3.affectedDocs == 1) like = 1
if(res2.affectedDocs == 1){
var post = {
postId:arr[i]["_id"],
usericon:res2.data[0]["icon"],
username:res2.data[0]["name"],
content:arr[i]["content"],
date:arr[i]["date"],
pictureList:arr[i]["url"],
likes:arr[i]["likes"],
comments:arr[i]["comment_num"],
islike:like
}
list.push(post)
}
}
return{
code:200,
message:"成功返回我的帖子列表",
data:{
postList:list
}
}
}
return{
code:400,
message:"返回我的帖子列表失败",
data:{}
}
};
{
"name": "fe-college-myPosiList",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
...@@ -5,12 +5,17 @@ exports.main = async (event, context) => { ...@@ -5,12 +5,17 @@ exports.main = async (event, context) => {
const post_table = db.collection("mustgo-post") const post_table = db.collection("mustgo-post")
const comment_table = db.collection("mustgo-post-comment") const comment_table = db.collection("mustgo-post-comment")
const user_table = db.collection("mustgo-user") const user_table = db.collection("mustgo-user")
const comment_like = db.collection("mustgo-comment-like")
const post_like = db.collection("mustgo-post-like")
const res = await post_table.where({ const res = await post_table.where({
_id:event.postId _id:event.postId
}).get() }).get()
const res3 = await comment_table.where({
const res3 = await comment_table.orderBy("date","desc").where({
post_id:event.postId post_id:event.postId
}).get() }).get()
var arr = new Array var arr = new Array
var list = new Array var list = new Array
arr =res3.data arr =res3.data
...@@ -19,13 +24,23 @@ exports.main = async (event, context) => { ...@@ -19,13 +24,23 @@ exports.main = async (event, context) => {
const res4 = await user_table.where({ const res4 = await user_table.where({
_id:arr[i]["owner_id"] _id:arr[i]["owner_id"]
}).get() }).get()
var like = 0
const res5 = await comment_like.where({
owner_id:event.userId,
comment_id:arr[i]["_id"]
}).get()
if(res5.affectedDocs == 1) like = 1
if(res4.affectedDocs == 1){ if(res4.affectedDocs == 1){
var comment ={ var comment ={
commenterIcon:res4.data[0]["icon"], commenterIcon:res4.data[0]["icon"],
commenterName:res4.data[0]["name"], commenterName:res4.data[0]["name"],
commentId:arr[i]["_id"],
commentContent:arr[i]["content"], commentContent:arr[i]["content"],
commentDatetime:arr[i]["date"], commentDatetime:arr[i]["date"],
commentLikes:arr[i]["likes"] commentLikes:arr[i]["likes"],
islike:like
} }
list.push(comment) list.push(comment)
} }
...@@ -36,11 +51,20 @@ exports.main = async (event, context) => { ...@@ -36,11 +51,20 @@ exports.main = async (event, context) => {
const res2 = await user_table.where({ const res2 = await user_table.where({
_id:res.data[0]["owner_id"] _id:res.data[0]["owner_id"]
}).get() }).get()
var likepost = 0
const postLike = await post_like.where({
owner_id:event.userId,
post_id:event.postId
}).get()
if(postLike.affectedDocs == 1) likepost = 1
if(res2.affectedDocs == 1){ if(res2.affectedDocs == 1){
return { return {
code: 200, code: 200,
message: "成功返回帖子详情", message: "成功返回帖子详情",
data: { data: {
ownerId:res2.data[0]["_id"],
ownerName:res2.data[0]["name"], ownerName:res2.data[0]["name"],
ownerIcon:res2.data[0]["icon"], ownerIcon:res2.data[0]["icon"],
datetime:res.data[0]["date"], datetime:res.data[0]["date"],
...@@ -48,6 +72,7 @@ exports.main = async (event, context) => { ...@@ -48,6 +72,7 @@ exports.main = async (event, context) => {
pictureList:res.data[0]["url"], pictureList:res.data[0]["url"],
likes:res.data[0]["likes"], likes:res.data[0]["likes"],
comments:res.data[0]["comment_num"], comments:res.data[0]["comment_num"],
islike:likepost,
commentList:list commentList:list
} }
} }
......
...@@ -4,7 +4,8 @@ exports.main = async (event, context) => { ...@@ -4,7 +4,8 @@ exports.main = async (event, context) => {
const db = uniCloud.database(); const db = uniCloud.database();
const post_table = db.collection("mustgo-post") const post_table = db.collection("mustgo-post")
const user_table = db.collection("mustgo-user") const user_table = db.collection("mustgo-user")
const res = await post_table.get(); const like_table = db.collection("mustgo-post-like")
const res = await post_table.orderBy("date","desc").get();
var list = new Array var list = new Array
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
...@@ -13,6 +14,14 @@ exports.main = async (event, context) => { ...@@ -13,6 +14,14 @@ exports.main = async (event, context) => {
const res2 = await user_table.where({ const res2 = await user_table.where({
_id:arr[i]["owner_id"] _id:arr[i]["owner_id"]
}).get() }).get()
const res3 = await like_table.where({
owner_id:event.uid,
post_id:arr[i]["_id"]
}).get()
var like = 0
if(res3.affectedDocs == 1) like = 1
if(res2.affectedDocs == 1){ if(res2.affectedDocs == 1){
var post = { var post = {
postId: arr[i]["_id"], postId: arr[i]["_id"],
...@@ -21,7 +30,9 @@ exports.main = async (event, context) => { ...@@ -21,7 +30,9 @@ exports.main = async (event, context) => {
content: arr[i]["content"], content: arr[i]["content"],
likes:arr[i]["likes"], likes:arr[i]["likes"],
comments:arr[i]["comment_num"], comments:arr[i]["comment_num"],
pictureList:arr[i]["url"] pictureList:arr[i]["url"],
date:arr[i]["date"],
islike:like
} }
list.push(post); list.push(post);
} }
......
...@@ -8,7 +8,7 @@ exports.main = async (event, context) => { ...@@ -8,7 +8,7 @@ exports.main = async (event, context) => {
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
if (res.affectedDocs >= 0) { if (res.affectedDocs >= 0) {
for (var i = 0; i < arr.length; i++) { for (var i = arr.length-1; i >= 0; i--) {
var activity = { var activity = {
activityId: arr[i]["_id"], activityId: arr[i]["_id"],
title: arr[i]["title"], title: arr[i]["title"],
......
...@@ -10,7 +10,7 @@ exports.main = async (event, context) => { ...@@ -10,7 +10,7 @@ exports.main = async (event, context) => {
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
if (res.affectedDocs >= 0) { if (res.affectedDocs >= 0) {
for (var i = 0; i < arr.length; i++) { for (var i = arr.length-1; i >=0 ; i--) {
var activity = { var activity = {
activityId: arr[i]["_id"], activityId: arr[i]["_id"],
title: arr[i]["title"], title: arr[i]["title"],
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
exports.main = async (event, context) => { exports.main = async (event, context) => {
const db = uniCloud.database() const db = uniCloud.database()
const user_table = db.collection('mustgo-user') const user_table = db.collection('mustgo-user')
let res = await user_table.where({ const res = await user_table.where({
_id: event.userId, _id: event.userId,
}).get() }).get()
if (res.affectedDocs == 1 && res.data[0]["password"] == event.password) { if (res.affectedDocs == 1 && res.data[0]["password"] == event.password) {
const res = await collection.doc(event.userId).update({ const res2 = await user_table.doc(event.userId).update({
password: event.newPassword password: event.newPassword
}) })
if (res.updated === 1) { if (res2.updated == 1) {
return { return {
"code": 200, "code": 200,
"message": "重置密码成功成功", "message": "重置密码成功",
"data": { "data": {
"userId":res.data[0]["_id"] "userId":res.data[0]["_id"]
} }
...@@ -22,7 +22,7 @@ exports.main = async (event, context) => { ...@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
} }
return { return {
"code": 400, "code": 400,
"message": "原密码错误失败", "message": "原密码错误,重置密码失败",
"data": {} "data": {}
} }
}; };
\ No newline at end of file
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
exports.main = async (event, context) => { exports.main = async (event, context) => {
const db = uniCloud.database(); const db = uniCloud.database();
const running_table = db.collection('mustgo-running-record') const running_table = db.collection('mustgo-running-record')
let res = await running_table.where({ let res = await running_table.orderBy("start_date","desc").where({
_id: event.userId owner_id: event.userId
}).get() }).get()
var arr = new Array var arr = new Array
var list = new Array var list = new Array
...@@ -11,10 +11,10 @@ exports.main = async (event, context) => { ...@@ -11,10 +11,10 @@ exports.main = async (event, context) => {
if(res.affectedDocs >= 0){ if(res.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){ for(var i = 0;i < arr.length;i ++){
var record = { var record = {
runningId: arr[i]["_id"] runningId: arr[i]["_id"],
distance: arr[i]["distance"] distance: arr[i]["distance"],
duration: arr[i]["duration"] duration: arr[i]["duration"],
pace: arr[i]["pace"] pace: arr[i]["pace"],
startDatetime: arr[i]["start_date"] startDatetime: arr[i]["start_date"]
} }
list.push(record) list.push(record)
......
...@@ -2,19 +2,22 @@ ...@@ -2,19 +2,22 @@
exports.main = async (event, context) => { exports.main = async (event, context) => {
const db = uniCloud.database(); const db = uniCloud.database();
const walking_table = db.collection('mustgo-walking-record') const walking_table = db.collection('mustgo-walking-record')
let res = await walking_table.where({ var res = await walking_table.orderBy("start_date","desc").where({
_id: event.userId owner_id: event.userId
}).get() }).get()
var arr = new Array var arr = new Array
var list = new Array var list = new Array
arr = res.data arr = res.data
console.log(res.affectedDocs)
if(res.affectedDocs >= 0){ if(res.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){ for(var i = 0;i < arr.length;i ++){
var record = { var record = {
walkingId: arr[i]["_id"] walkingId: arr[i]["_id"],
distance: arr[i]["distance"] distance: arr[i]["distance"],
steps: arr[i]["steps"] pace: arr[i]["pace"],
startDatetime: arr[i]["start_date"] startDatetime: arr[i]["start_date"]
duration:arr[i]["duration"]
} }
list.push(record) list.push(record)
} }
...@@ -22,7 +25,7 @@ exports.main = async (event, context) => { ...@@ -22,7 +25,7 @@ exports.main = async (event, context) => {
code: 200, code: 200,
message: "成功返回健走记录列表", message: "成功返回健走记录列表",
data: { data: {
runningList: list walkingList: list
} }
} }
} }
......
...@@ -20,8 +20,6 @@ exports.main = async (event, context) => { ...@@ -20,8 +20,6 @@ exports.main = async (event, context) => {
message: "成功返回小队活动列表", message: "成功返回小队活动列表",
join: false, join: false,
data: { data: {
username: userres.data[0]["name"],
icon: userres.data[0]["icon"],
activityList: [] activityList: []
} }
} }
...@@ -37,10 +35,14 @@ exports.main = async (event, context) => { ...@@ -37,10 +35,14 @@ exports.main = async (event, context) => {
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
if (res.affectedDocs >= 0) { if (res.affectedDocs >= 0) {
for (var i = 0; i < arr.length; i++) { const teamcollection = db.collection('mustgo-team')
let teamres = await teamcollection.where({
_id: teamid
}).get()
for (var i = arr.length-1; i >=0 ; i--) {
var activity = { var activity = {
activityId: arr[i]["_id"], activityId: arr[i]["_id"],
title: arr[i]["title"] title: arr[i]["title"],
} }
list.push(activity); list.push(activity);
} }
...@@ -48,8 +50,8 @@ exports.main = async (event, context) => { ...@@ -48,8 +50,8 @@ exports.main = async (event, context) => {
code: 200, code: 200,
message: "成功返回小队活动列表", message: "成功返回小队活动列表",
data: { data: {
username: userres.data[0]["name"], teamname:teamres.data[0]["name"],
icon: userres.data[0]["icon"], teamicon:teamres.data[0]["icon"],
activityList: list activityList: list
} }
} }
......
...@@ -34,7 +34,7 @@ exports.main = async (event, context) => { ...@@ -34,7 +34,7 @@ exports.main = async (event, context) => {
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
if (res.affectedDocs >= 0) { if (res.affectedDocs >= 0) {
for (var i = 0; i < arr.length; i++) { for (var i = arr.length-1; i >=0 ; i--) {
var user = { var user = {
"memberId": arr[i]["_id"], "memberId": arr[i]["_id"],
"memberIcon": arr[i]["icon"], "memberIcon": arr[i]["icon"],
......
...@@ -8,7 +8,7 @@ exports.main = async (event, context) => { ...@@ -8,7 +8,7 @@ exports.main = async (event, context) => {
var arr = new Array; var arr = new Array;
arr = res.data; arr = res.data;
if (res.affectedDocs >= 0) { if (res.affectedDocs >= 0) {
for (var i = 0; i < arr.length; i++) { for (var i = arr.length-1; i >=0 ; i--) {
var team = { var team = {
teamId: arr[i]["_id"], teamId: arr[i]["_id"],
teamName: arr[i]["name"], teamName: arr[i]["name"],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册