Skip to content

Commit

Permalink
🎨 Improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toly committed Jun 11, 2024
1 parent 8fe07ff commit c7a5a68
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
[![English-Burning-Backend CI](https://github.com/tolerious/English-Burning-Backend/actions/workflows/English-Burning-Backend.yml/badge.svg?branch=master)](https://github.com/tolerious/English-Burning-Backend/actions/workflows/English-Burning-Backend.yml)

[See Here](https://github.com/tolerious/English-Burning-Frontend)

## Feature List

- 没创建一个用户都需要为其船舰一个默认的单词组,添加单词后都放到这个组里面
4 changes: 2 additions & 2 deletions routes/wordGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ router.get('/child', async function (req, res, next) {
router.post("/", async function (req, res, next) {
let user = req.tUser;
let body = req.body;
Object.assign(body, { userID: user._id, parentGroupID: '' });
Object.assign(body, { creator: user._id, parentGroupID: '' });
let t = await wordGroupModel.create(body);
res.json(generateResponse(t));
});
Expand Down Expand Up @@ -104,7 +104,7 @@ router.post('/sharing/count', async function (req, res, next) {
let c = await wordGroupModel.countDocuments()
res.json(generateResponse({
wordCount: g.wordCount,
videoCount: g.groupMediaUrl.split(',').filter(item => { !item }).length,
videoCount: g.groupVideoUrl.split(',').filter(item => { !item }).length,
audioCount: g.groupAudioUrl.split(',').filter(item => { !item }).length,
articleCount: g.groupArticleUrl.split(',').filter(item => { !item }).length,
groupCount: c
Expand Down
3 changes: 2 additions & 1 deletion schemas/articleSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const articleSchema = new Schema(
author: String,
content: String,
tags: [String],
link: { type: String, default: "" }, //文章链接
/** 文章链接 */
link: { type: String, default: "" },
},

{
Expand Down
2 changes: 2 additions & 0 deletions schemas/userSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const userSchema = new Schema(
{
username: String,
password: String,
/** 注册来源,默认是web */
source: { type: String, default: "web" },
/** 登陆后的token */
token: { type: String, default: "" },
},
{
Expand Down
5 changes: 5 additions & 0 deletions schemas/userSettingsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ const mongoose = require("mongoose");

const { Schema } = mongoose;

/**
* 用户设置
*/
const userSettingSchema = new Schema(
{
userID: ObjectId,
/** 默认单词组,即当前正在背诵的单词所属于的单词组 */
defaultGroupID: ObjectId,
},
{
timestamps: true,
statics: {
// FIXME: 这个函数应该在UserSchema中
async getUserByUserName(username) {
return await mongoose.model("UserSetting", userSettingSchema).find({
username: username,
Expand Down
33 changes: 21 additions & 12 deletions schemas/wordGroupSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@ const { Schema } = mongoose;

const wordGroupSchema = new Schema(
{
userID: ObjectId,
groupMediaUrl: { type: String, default: '' },
groupAudioUrl: { type: String, default: '' },
groupArticleUrl: { type: String, default: '' },
parentGroupID: { type: String, default: '' },
isPublic: { type: Boolean, default: false },
name: { type: String, default: "" },
creator: ObjectId,
groupDescription: { type: String, default: "" },
groupCoverUrl: { type: String, default: "" },
groupVideoUrl: { type: String, default: "" },
groupAudioUrl: { type: String, default: "" },
groupArticleUrl: { type: String, default: "" },
parentGroupID: { type: String, default: "" },
isPublic: { type: Boolean, default: false },
wordCount: { type: Number, default: 0 },
},
{
timestamps: true,
statics: {
getOnlyChildGroup(userID) {
return mongoose.model("WordGroup").find({ userID: userID, parentGroupID: { $ne: '' } })
getOnlyChildGroup(creator) {
return mongoose
.model("WordGroup")
.find({ creator: creator, parentGroupID: { $ne: "" } });
},
getPublicGroup() {
return mongoose.model("WordGroup").find({ isPublic: true, parentGroupID: { $ne: '' } })
return mongoose
.model("WordGroup")
.find({ isPublic: true, parentGroupID: { $ne: "" } });
},
getOnlyParentGroup(userID) {
return mongoose.model("WordGroup").find({ userID })
.where('parentGroupID').equals('');
getOnlyParentGroup(creator) {
return mongoose
.model("WordGroup")
.find({ creator })
.where("parentGroupID")
.equals("");
},
},
}
Expand Down

0 comments on commit c7a5a68

Please sign in to comment.