Skip to content

Commit

Permalink
Merge pull request #7 from tolerious/feat/refactor-create-group-logic
Browse files Browse the repository at this point in the history
🚧 Update usersetting api.
  • Loading branch information
tolerious authored Sep 7, 2024
2 parents 9e57598 + 2988b8c commit de168f0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions routes/userSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const express = require("express");
const { generateResponse, grabWordFromCambridge } = require("../utils/utils");
const { userSettingModel } = require("../schemas/userSettingsSchema");
const router = express.Router();
/* GET home page. */

// 获取用户settings
router.get("/", async function (req, res, next) {
const u = req.tUser;
let r = await userSettingModel.findOne({ userID: u._id });
res.json(generateResponse(r));
});

// 创建或者更新用户settings
router.post("/", async function (req, res, next) {
let d = req.body;
let u = req.tUser;
Expand All @@ -18,10 +20,7 @@ router.post("/", async function (req, res, next) {
Object.assign(d, { userID: u._id });
t = await userSettingModel.create(d);
} else {
t = await userSettingModel.findOneAndUpdate(
{ userID: u._id },
{ defaultGroupID: d.defaultGroupID }
);
t = await userSettingModel.findOneAndUpdate({ userID: u._id }, d);
}
res.json(generateResponse(t));
});
Expand Down

0 comments on commit de168f0

Please sign in to comment.