提交 c057a78e 编写于 作者: 0 042003124

完善部分接口

上级 057908c4
......@@ -64,7 +64,7 @@ function getSystemTime() {
// 获取日期(1-31)
var date = time.getDate();
// 获取小时
var h = time.getHours();
var h = time.getHours() + 8;
h = h < 10 ? '0' + h : h;
// 获取分钟
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) => {
const islike = await like_table.where({
post_id:event.postId,
user_id:event.userId
owner_id:event.userId
}).get()
if(islike.affectedDocs == 0 && res.affectedDocs == 1){
const res2 = await post_table.doc(event.postId).update({
likes:res.data[0]["likes"] + 1
......@@ -19,7 +20,7 @@ exports.main = async (event, context) => {
const res3 = await like_table.add({
post_id:event.postId,
user_id:event.userId
owner_id:event.userId
})
return {
......@@ -31,22 +32,22 @@ exports.main = async (event, context) => {
}
}
}
else if(islike.affectedDocs == 1 && res.affectedDocs == 1){
const res4 = await post_table.doc(event.postId).update({
likes:res.data[0]["likes"] - 1,
})
like_table.doc(islike.data[0]["_id"]).remove().then((res5) => {
console.log("删除成功");
})
return {
code: 200,
message: "取消点赞帖子成功",
data: {
postId:res.data[0]["_id"],
newlikes:res.data[0]["likes"] - 1
}
const deleteLike = await like_table.doc(islike.data[0]["_id"]).remove()
if(deleteLike.deleted === 1){
return {
code: 200,
message: "取消点赞帖子成功",
data: {
postId:res.data[0]["_id"],
newlikes:res.data[0]["likes"] - 1
}
}
}
}
......
......@@ -39,7 +39,7 @@ function getSystemTime() {
// 获取日期(1-31)
var date = time.getDate();
// 获取小时
var h = time.getHours();
var h = time.getHours() + 8;
h = h < 10 ? '0' + h : h;
// 获取分钟
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) => {
const post_table = db.collection("mustgo-post")
const comment_table = db.collection("mustgo-post-comment")
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({
_id:event.postId
}).get()
const res3 = await comment_table.where({
post_id:event.postId
}).get()
var arr = new Array
var list = new Array
arr =res3.data
......@@ -19,13 +24,22 @@ exports.main = async (event, context) => {
const res4 = await user_table.where({
_id:arr[i]["owner_id"]
}).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){
var comment ={
commenterIcon:res4.data[0]["icon"],
commenterName:res4.data[0]["name"],
commentContent:arr[i]["content"],
commentDatetime:arr[i]["date"],
commentLikes:arr[i]["likes"]
commentLikes:arr[i]["likes"],
islike:like
}
list.push(comment)
}
......@@ -36,11 +50,18 @@ exports.main = async (event, context) => {
const res2 = await user_table.where({
_id:res.data[0]["owner_id"]
}).get()
var likepost = 0
const postLike = await post_like.where({
owner_id:event.userId,
post_id:event.postId
}).get()
if(postLike == 1) likepost = 1
if(res2.affectedDocs == 1){
return {
code: 200,
message: "成功返回帖子详情",
data: {
ownerId:res2.data[0]["_id"],
ownerName:res2.data[0]["name"],
ownerIcon:res2.data[0]["icon"],
datetime:res.data[0]["date"],
......@@ -48,6 +69,7 @@ exports.main = async (event, context) => {
pictureList:res.data[0]["url"],
likes:res.data[0]["likes"],
comments:res.data[0]["comment_num"],
islike:likepost,
commentList:list
}
}
......
......@@ -4,7 +4,8 @@ exports.main = async (event, context) => {
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
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 arr = new Array;
arr = res.data;
......@@ -13,6 +14,14 @@ exports.main = async (event, context) => {
const res2 = await user_table.where({
_id:arr[i]["owner_id"]
}).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){
var post = {
postId: arr[i]["_id"],
......@@ -21,7 +30,9 @@ exports.main = async (event, context) => {
content: arr[i]["content"],
likes:arr[i]["likes"],
comments:arr[i]["comment_num"],
pictureList:arr[i]["url"]
pictureList:arr[i]["url"],
date:arr[i]["date"],
islike:like
}
list.push(post);
}
......
......@@ -2,18 +2,18 @@
exports.main = async (event, context) => {
const db = uniCloud.database()
const user_table = db.collection('mustgo-user')
let res = await user_table.where({
const res = await user_table.where({
_id: event.userId,
}).get()
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
})
if (res.updated === 1) {
if (res2.updated == 1) {
return {
"code": 200,
"message": "重置密码成功成功",
"message": "重置密码成功",
"data": {
"userId":res.data[0]["_id"]
}
......@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
}
return {
"code": 400,
"message": "原密码错误失败",
"message": "原密码错误,重置密码失败",
"data": {}
}
};
\ No newline at end of file
......@@ -11,10 +11,10 @@ exports.main = async (event, context) => {
if(res.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){
var record = {
runningId: arr[i]["_id"]
distance: arr[i]["distance"]
duration: arr[i]["duration"]
pace: arr[i]["pace"]
runningId: arr[i]["_id"],
distance: arr[i]["distance"],
duration: arr[i]["duration"],
pace: arr[i]["pace"],
startDatetime: arr[i]["start_date"]
}
list.push(record)
......
......@@ -2,18 +2,20 @@
exports.main = async (event, context) => {
const db = uniCloud.database();
const walking_table = db.collection('mustgo-walking-record')
let res = await walking_table.where({
_id: event.userId
var res = await walking_table.where({
owner_id: event.userId
}).get()
var arr = new Array
var list = new Array
arr = res.data
console.log(res.affectedDocs)
if(res.affectedDocs >= 0){
for(var i = 0;i < arr.length;i ++){
var record = {
walkingId: arr[i]["_id"]
distance: arr[i]["distance"]
steps: arr[i]["steps"]
walkingId: arr[i]["_id"],
distance: arr[i]["distance"],
steps: arr[i]["steps"],
startDatetime: arr[i]["start_date"]
}
list.push(record)
......
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册