提交 77f742ec 编写于 作者: 0 042003124

完成高校圈模块部分接口

上级 c213c97a
'use strict';
exports.main = async (event, context) => {
const db = uniCloud.database();
const user_table = db.collection("mustgo-user")
const comment_table = db.collection("mustgo-post-comment")
const post_table = db.collection("mustgo-post")
const res = await user_table.where({
_id:event.userId
}).get()
if(res.affectedDocs == 1){
const res2 = await post_table.where({
_id:event.postId
}).get()
if(res2.affectedDocs == 1){
const res3 = await post_table.doc(event.postId).update({
comment_num:res2.data[0]["comment_num"] + 1
})
var time = getSystemTime()
var like = 0
const res4 = await comment_table.add({
owner_id:event.userId,
date:time,
likes:like,
post_id:event.postId,
check_status:false,
content:event.content
})
return{
code:200,
message:"评论帖子成功",
data:{
postId:res2.data[0]["_id"],
newCommentNum:res2.data[0]["comment_num"] + 1,
commenterIcon:res.data[0]["icon"],
commenterName:res.data[0]["name"],
commentDatetime:time,
commentLikes:like
}
}
}
}
return {
code: 400,
message: "评论帖子失败",
data: {}
}
};
function getSystemTime() {
// 实例化日期类
var time = new Date();
// 获取完整的年份(4位)
var year = time.getFullYear();
// 获取月份(0-11,0代表1月)
var month = time.getMonth() + 1;
// 获取日期(1-31)
var date = time.getDate();
// 获取小时
var h = time.getHours();
h = h < 10 ? '0' + h : h;
// 获取分钟
var m = time.getMinutes();
m = m < 10 ? '0' + m : m;
// 获取秒钟
var s = time.getSeconds();
s = s < 10 ? '0' + s : s;
// 合并返回
return(year + "-" + month + "-" + date + " " + h + ":" + m + ":" + s) ;
}
\ No newline at end of file
{
"name": "fe-college-commentPost",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
const db = uniCloud.database();
const post_table = db.collection("mustgo-post")
const like_table = db.collection("mustgo-post-like")
const res = await post_table.where({
_id:event.postId
}).get()
const islike = await like_table.where({
post_id:event.postId,
user_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
})
const res3 = await like_table.add({
post_id:event.postId,
user_id:event.userId
})
return {
code: 200,
message: "点赞帖子成功",
data: {
postId:res.data[0]["_id"],
newlikes:res.data[0]["likes"] + 1
}
}
}
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
}
}
}
return {
code: 500,
message: "服务器错误",
data: {}
}
};
\ No newline at end of file
{
"name": "fe-college-likePost",
"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 res = await post_table.add({
content:event.content,
date:getSystemTime(),
likes:0,
owner_id:event.userId,
check_status:false,
comment_num:0,
url:event.picture
})
if(res.id.length > 0){
return{
code:200,
message:"发布帖子成功",
data:{
postId:res.id
}
}
}
return {
code: 400,
message: "发布帖子失败",
data: {}
}
};
function getSystemTime() {
// 实例化日期类
var time = new Date();
// 获取完整的年份(4位)
var year = time.getFullYear();
// 获取月份(0-11,0代表1月)
var month = time.getMonth() + 1;
// 获取日期(1-31)
var date = time.getDate();
// 获取小时
var h = time.getHours();
h = h < 10 ? '0' + h : h;
// 获取分钟
var m = time.getMinutes();
m = m < 10 ? '0' + m : m;
// 获取秒钟
var s = time.getSeconds();
s = s < 10 ? '0' + s : s;
// 合并返回
return(year + "-" + month + "-" + date + " " + h + ":" + m + ":" + s) ;
}
\ No newline at end of file
{
"name": "fe-college-makePost",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
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()
const res3 = await comment_table.where({
post_id:event.postId
}).get()
var arr = new Array
var list = new Array
arr =res3.data
if(res3.affectedDocs >= 0){
for(var i = 0;i < arr.length;i++){
const res4 = await user_table.where({
_id:arr[i]["owner_id"]
}).get()
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"]
}
list.push(comment)
}
}
}
if (res.affectedDocs == 1) {
const res2 = await user_table.where({
_id:res.data[0]["owner_id"]
}).get()
if(res2.affectedDocs == 1){
return {
code: 200,
message: "成功返回帖子详情",
data: {
ownerName:res2.data[0]["name"],
ownerIcon:res2.data[0]["icon"],
datetime:res.data[0]["date"],
content:res.data[0]["content"],
pictureList:res.data[0]["url"],
likes:res.data[0]["likes"],
comments:res.data[0]["comment_num"],
commentList:list
}
}
}
}
return {
code: 400,
message: "查看帖子详情失败",
data: {}
}
};
\ No newline at end of file
{
"name": "fe-college-postDetail",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
\ No newline at end of file
...@@ -2,25 +2,35 @@ ...@@ -2,25 +2,35 @@
exports.main = async (event, context) => { exports.main = async (event, context) => {
//event为客户端上传的参数 //event为客户端上传的参数
const db = uniCloud.database(); const db = uniCloud.database();
const collection = db.collection("opendb-news-articles") const post_table = db.collection("mustgo-post")
const res = await collection.get(); const user_table = db.collection("mustgo-user")
var postList = new Array const res = await post_table.get();
var list = new Array
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 = 0; i < arr.length; i++) {
var post = { const res2 = await user_table.where({
postId: arr[i]["_id"], _id:arr[i]["owner_id"]
userIcon: arr[i]["title"], }).get()
picture: arr[i]["background_picture"] if(res2.affectedDocs == 1){
var post = {
postId: arr[i]["_id"],
usericon:res2.data[0]["icon"],
username:res2.data[0]["name"],
content: arr[i]["content"],
likes:arr[i]["likes"],
comments:arr[i]["comment_num"],
pictureList:arr[i]["url"]
}
list.push(post);
} }
list.push(activity);
} }
return { return {
code: 200, code: 200,
message: "成功返回活动列表", message: "成功返回帖子列表",
data: { data: {
activityList: list postList: list
} }
} }
} }
...@@ -29,4 +39,4 @@ exports.main = async (event, context) => { ...@@ -29,4 +39,4 @@ exports.main = async (event, context) => {
message: "服务器错误", message: "服务器错误",
data: {} data: {}
} }
}; };
\ No newline at end of file
...@@ -6,7 +6,7 @@ exports.main = async (event, context) => { ...@@ -6,7 +6,7 @@ exports.main = async (event, context) => {
let res = await user_table.where({ let res = await user_table.where({
_id: event.userId _id: event.userId
}).get() }).get()
var team = null var team = ""
if (res.affectedDocs == 1) { if (res.affectedDocs == 1) {
var team_id = res.data[0]["team_id"] var team_id = res.data[0]["team_id"]
if(team_id != null){ if(team_id != null){
...@@ -22,7 +22,7 @@ exports.main = async (event, context) => { ...@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
code: 200, code: 200,
message: "成功返回用户信息", message: "成功返回用户信息",
data: { data: {
"res": res.data[0]["icon"], "icon": res.data[0]["icon"],
"username": res.data[0]["name"], "username": res.data[0]["name"],
"school": res.data[0]["school"], "school": res.data[0]["school"],
"team": team "team": team
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
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 collection.where({ let res = await user_table.where({
_id: event.userId, _id: event.userId,
}).get() }).get()
...@@ -14,13 +14,15 @@ exports.main = async (event, context) => { ...@@ -14,13 +14,15 @@ exports.main = async (event, context) => {
return { return {
"code": 200, "code": 200,
"message": "重置密码成功成功", "message": "重置密码成功成功",
"data": {} "data": {
"userId":res.data[0]["_id"]
}
} }
} }
} }
return { return {
"code": 400, "code": 400,
"message": "重置密码失败", "message": "原密码错误失败",
"data": {} "data": {}
} }
}; };
\ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"id":{"bsonType":"int","title":"活动状态id","description":"活动状态id"},"status":{"bsonType":"string","title":"活动状态","description":"活动状态"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {
\ No newline at end of file "bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
}
}
}
\ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}}
\ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}}
\ No newline at end of file
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
}
}
}
\ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"team_activity_id":{"bsonType":"string","foreignKey":"mustgo-team-activity._id","title":"小队活动id","description":"报名信息所属小队活动id"},"owner_id":{"bsonType":"string","foreignKey":"mustgo-user._id","title":"用户id","description":"报名者id"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"identity":{"bsonType":"string","title":"身份","description":"用户身份"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"start_date":{"bsonType":"string","title":"开始时间","description":"运动开始时间"},"duration":{"bsonType":"int","title":"持续时间","description":"运动持续时间"},"feelings":{"bsonType":"string","title":"感受","description":"运动感受"},"owner_id":{"bsonType":"string","title":"用户id","description":"用户id","foreignKey":"mustgo-user._id"},"distance":{"bsonType":"double","title":"距离","description":"运动距离"},"pace":{"bsonType":"double","title":"配速","description":"运动配速"},"start_point":{"bsonType":"string","title":"起始地点","description":"运动起始地点"},"end_point":{"bsonType":"string","title":"结束地点","description":"运动结束地点"},"path_line":{"bsonType":"array","title":"路线","description":"运动路线"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"title":{"bsonType":"string","title":"标题","description":"校园活动标题"},"content":{"bsonType":"string","title":"内容","description":"校园活动内容"},"start_date":{"bsonType":"string","title":"开始时间","description":"校园活动开始时间"},"end_date":{"bsonType":"string","title":"结束时间","description":"校园活动结束时间"},"owner_id":{"bsonType":"string","foreignKey":"mustgo-user._id","title":"发布者id","description":"校园活动发布者id"},"background_picture":{"bsonType":"string","title":"背景图片","description":"校园活动背景图片"},"place":{"bsonType":"string","title":"地点","description":"校园活动地点"},"status":{"bsonType":"int","foreignKey":"mustgo-activity-status.id","title":"活动状态","description":"校园活动状态"},"contact":{"bsonType":"string","title":"联系方式","description":"校园活动发布者联系方式"},"invitee":{"bsonType":"string","title":"面向对象","description":"校园活动面向对象"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"title":{"bsonType":"string","title":"标题","description":"小队活动标题"},"content":{"bsonType":"string","title":"内容","description":"小队活动内容"},"start_date":{"bsonType":"string","title":"开始时间","description":"小队活动开始时间"},"end_date":{"bsonType":"string","title":"结束时间","description":"小队活动结束时间"},"owner_id":{"bsonType":"string","foreignKey":"mustgo-user._id","title":"发布者id","description":"小队活动发布者id"},"background_picture":{"bsonType":"string","title":"背景图片","description":"小队活动背景图片"},"place":{"bsonType":"string","title":"地点","description":"小队活动地点"},"status":{"bsonType":"int","foreignKey":"mustgo-activity-status.id","title":"活动状态","description":"小队活动状态"},"participants":{"bsonType":"int","title":"参与人数","description":"小队活动参与人数"},"contact":{"bsonType":"string","title":"联系方式","description":"小队活动发布者联系方式"},"team_id":{"bsonType":"string","foreignKey":"mustgo-team._id","title":"小队id","description":"活动所属小队id"}}}
\ No newline at end of file \ No newline at end of file
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}} {"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"icon":{"bsonType":"string","title":"队标","description":"小队队标"},"name":{"bsonType":"string","title":"队名","description":"小队名称"},"owner_id":{"bsonType":"string","foreignKey":"mustgo-user._id","title":"发起人id","description":"小队发起人id"},"description":{"bsonType":"string","title":"描述","description":"小队描述"}}}
\ No newline at end of file \ No newline at end of file
<<<<<<< HEAD {"bsonType":"object","required":[],"permission":{"read":false,"create":true,"update":false,"delete":false},"properties":{"_id":{"title":"id","description":"ID,系统自动生成"},"name":{"bsonType":"string","title":"姓名","description":"用户姓名"},"icon":{"bsonType":"string","title":"头像","description":"用户头像"},"gender":{"bsonType":"string","title":"性别","description":"用户性别"},"password":{"bsonType":"string","title":"密码","description":"用户密码"},"phone_num":{"bsonType":"string","title":"手机号码","description":"用户手机号码"},"team_id":{"bsonType":"string","defaultValue":"","title":"小队id","description":"用户所属小队id"},"school":{"bsonType":"string","title":"学校","description":"用户所属学校"},"type":{"bsonType":"string","foreignKey":"mustgo-role._id","title":"类型","description":"用户类型"},"total_running_distance":{"bsonType":"double","defaultValue":0,"title":"总跑步距离","description":"用户总跑步距离"},"total_walking_distance":{"bsonType":"double","defaultValue":0,"title":"总健走距离","description":"用户总健走距离"}}}
{"bsonType":"object","required":[],"permission":{"read":false,"create":true,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"},"name":{"bsonType":"string"},"icon":{"bsonType":"string"},"gender":{"bsonType":"string"},"password":{"bsonType":"string"},"phone_num":{"bsonType":"string"},"team_id":{"bsonType":"string","defaultValue":""},"school":{"bsonType":"string"},"type":{"bsonType":"string","foreignKey":"mustgo-role._id"},"total_running_distance":{"bsonType":"double","defaultValue":0},"total_walking_distance":{"bsonType":"double","defaultValue":0}}} \ No newline at end of file
=======
{
"bsonType": "object",
"required": [],
"permission": {
"read": false,
"create": true,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"name": {
"bsonType": "string"
},
"icon": {
"bsonType": "string",
"description": "用户头像",
"defaultValue": "https://mp-6f6feaec-a026-4402-8e8d-18f7572890da.cdn.bspapp.com/cloudstorage/0510a534-dd8d-41f0-8341-601aa677e243.jpg"
},
"gender": {
"bsonType": "string"
},
"password": {
"bsonType": "string"
},
"phone_num": {
"bsonType": "string"
},
"team_id": {
"bsonType": "string",
"defaultValue": ""
},
"school": {
"bsonType": "string"
},
"type": {
"bsonType": "string",
"foreignKey": "mustgo-role._id"
},
"total_running_distance": {
"bsonType": "double",
"defaultValue": 0
},
"total_walking_distance": {
"bsonType": "double",
"defaultValue": 0
}
}
}
>>>>>>> 9039ca03ce0a452fbd2b009e72becba2ca46c23b
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册