Skip to content

Commit

Permalink
delete & rename
Browse files Browse the repository at this point in the history
  • Loading branch information
demozlx committed Mar 5, 2019
1 parent fa1cd22 commit e6cd752
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/actions/api/groups/delete.js
@@ -0,0 +1,18 @@
import mongoose from 'mongoose';
import { code } from '../../config';
import { argsFilter } from '../../lib/util';
import {roleAuthPromise} from "../../lib/auth";
const Groups = mongoose.model('Groups');

export default async req => {
await roleAuthPromise(req, 'read', 'post');
const args = await argsFilter(req.body, {
_id: ["required", "string"]
});
const update = await Groups.remove({_id: args._id});
if (update) {
return { code: code.success, data: {msg: '删除成功!'} };
} else {
return { code: code.fail };
}
};
2 changes: 2 additions & 0 deletions api/actions/api/groups/index.js
Expand Up @@ -3,4 +3,6 @@ import "../../models/Signup";
export create from "./create";
export list from "./list";
export detail from "./detail";
export remove from "./delete";
export rename from "./rename";

22 changes: 22 additions & 0 deletions api/actions/api/groups/rename.js
@@ -0,0 +1,22 @@
import mongoose from 'mongoose';
import { code } from '../../config';
import { argsFilter } from '../../lib/util';

const Groups = mongoose.model('Groups');

export default async req => {
const args = await argsFilter(req.body, {
_id: ['required', 'string'],
name: ['required', 'string']
});

const update = await Groups.findOneAndUpdate(
{ _id: args._id },
{ $set: { group_name: args.name } }
);
if (update) {
return { code: code.success, data: {msg: '重命名成功!'} };
} else {
return { code: code.fail };
}
};

0 comments on commit e6cd752

Please sign in to comment.